aboutsummaryrefslogtreecommitdiffstats
path: root/serve/crypto.h
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-28 19:30:44 +0100
committereunhhu <[email protected]>2026-09-28 19:30:44 +0100
commita83d663404e030a8734fddc8827fb4afe309a1b9 (patch)
treed94c2eb3c63cddd5418e8ffeb1896747abc4ac96 /serve/crypto.h
parent09b754f2490dec5582ba79c9cde55b32bac12bcf (diff)
downloadpure-a83d663404e030a8734fddc8827fb4afe309a1b9.tar.gz
pure-a83d663404e030a8734fddc8827fb4afe309a1b9.zip
Keep a run's keys as bytes: one AES-GCM context serves the listener
Each run a listener knew held two OpenSSL contexts. With 16 KiB pages, what those allocations left behind when idle senders went kept 42 MB of free heap resident after 10,000 senders had come and gone (in use: 0.6 MB). A run now keeps its keys (16 bytes each way and the nonce bases), and the listener seals and opens with one context, giving it each packet's key: about 130 ns a packet on this Pi. Two runs a sender, not four; a sender's address as an IPv6 one (an IPv4 one fits). What idle senders held goes back to the system once 1,024 have gone, or 10 s after any went (malloc_trim). HKDF is fetched once, not at every derivation.
Diffstat (limited to 'serve/crypto.h')
-rw-r--r--serve/crypto.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/serve/crypto.h b/serve/crypto.h
index b8a48fd..53e9c2c 100644
--- a/serve/crypto.h
+++ b/serve/crypto.h
@@ -8,7 +8,7 @@
* first time a server seals, opens a seal or connects to an https receiver
* (serve/crypto.c): one that does none of these maps no OpenSSL, 2.3 MiB
* less resident and 0.6 MiB less of its own. */
-enum { PURE_CRYPTO_VERSION = 3 };
+enum { PURE_CRYPTO_VERSION = 4 };
typedef struct {
unsigned version;
@@ -38,10 +38,12 @@ typedef struct {
bool (*link_derive)(const unsigned char secret[32], const unsigned char *info, size_t info_size, unsigned char *out,
size_t out_size);
PureAead *(*aead)(const unsigned char key[PURE_AEAD_KEY]);
- bool (*aead_seal)(PureAead *, const unsigned char nonce[PURE_AEAD_NONCE], const unsigned char *aad, size_t aad_size,
- const unsigned char *plain, size_t size, unsigned char *out);
- bool (*aead_open)(PureAead *, const unsigned char nonce[PURE_AEAD_NONCE], const unsigned char *aad,
- size_t aad_size, const unsigned char *sealed, size_t size, unsigned char *plain);
+ bool (*aead_seal)(PureAead *, const unsigned char *key, const unsigned char nonce[PURE_AEAD_NONCE],
+ const unsigned char *aad, size_t aad_size, const unsigned char *plain, size_t size,
+ unsigned char *out);
+ bool (*aead_open)(PureAead *, const unsigned char *key, const unsigned char nonce[PURE_AEAD_NONCE],
+ const unsigned char *aad, size_t aad_size, const unsigned char *sealed, size_t size,
+ unsigned char *plain);
void (*aead_free)(PureAead *);
} PureCrypto;
#endif