aboutsummaryrefslogtreecommitdiffstats
path: root/serve/crypto.c
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-28 17:37:41 +0100
committereunhhu <[email protected]>2026-09-28 17:37:41 +0100
commit745efcd4f19b59bcfb131df2d127a3387a544e84 (patch)
tree3e001fdd0a695f9a9aaf567e07ad00415f3cf330 /serve/crypto.c
parent502f70dbd66debcf1cb0328427831ec14926504b (diff)
downloadpure-745efcd4f19b59bcfb131df2d127a3387a544e84.tar.gz
pure-745efcd4f19b59bcfb131df2d127a3387a544e84.zip
Link two nodes without a connection over UDP (093, design 011's first stage)
pure-serve --send OUTPUT=pure://host:port/INPUT sends an output's saved sends to another node's --link-port with no handshake: the first packet carries records. Keys come from the two nodes' keys (X25519, HKDF-SHA256, AES-128-GCM), with a random run in each packet's header so no nonce repeats across restarts; nothing is stored for them. What lasts is the apps' own: the sender's outbox and the receiver's heard numbers (pure_app_heard, new). The sender detects losses as RFC 9002 says, with NewReno, and trims a send once the receiver says it stored it; the receiver hands the owner whole records in order, which it applies from the one after the source's last heard number, stopping at a gap, and answers how far it stored with every acknowledgment. Stored bytes are the bytes on the wire: an output and an input of one shape need no JSON. server_links_udp kills the receiver, the sender, then both (-9) while four clients buy: every saved order is applied once, with no handshake (five runs, 10k-11k orders each). server_links_udp_lossy does it again in a namespace of its own with the link's packets delayed, lost (3 %) and reordered (10 %) by netem (three runs, 11k-12k orders).
Diffstat (limited to 'serve/crypto.c')
-rw-r--r--serve/crypto.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/serve/crypto.c b/serve/crypto.c
index 8eae6d1..d43de93 100644
--- a/serve/crypto.c
+++ b/serve/crypto.c
@@ -133,3 +133,33 @@ bool pure_unseal(PureOpener *o, uint64_t n, const char *aad, const unsigned char
}
void pure_opener_free(PureOpener *o) { if (o) crypto->opener_free(o); }
+
+/* ---- Links */
+
+bool pure_link_secret(const PureSealKey *own, const unsigned char peer[PURE_SEAL_KEY], unsigned char out[32]) {
+ const PureCrypto *c = loaded(NULL, 0);
+ return c && own && c->link_secret(own, peer, out);
+}
+
+bool pure_link_derive(const unsigned char secret[32], const unsigned char *info, size_t info_size, unsigned char *out,
+ size_t out_size) {
+ const PureCrypto *c = loaded(NULL, 0);
+ return c && c->link_derive(secret, info, info_size, out, out_size);
+}
+
+PureAead *pure_aead(const unsigned char key[PURE_AEAD_KEY]) {
+ const PureCrypto *c = loaded(NULL, 0);
+ return c ? c->aead(key) : NULL;
+}
+
+bool pure_aead_seal(PureAead *a, 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) {
+ return crypto->aead_seal(a, nonce, aad, aad_size, plain, size, out);
+}
+
+bool pure_aead_open(PureAead *a, 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) {
+ return crypto->aead_open(a, nonce, aad, aad_size, sealed, size, plain);
+}
+
+void pure_aead_free(PureAead *a) { if (a) crypto->aead_free(a); }