feat: seal peer sync with X25519 + XChaCha20-Poly1305 (0.9.17)

Encrypt parliament context sync after Realm mutual auth without pulling in OpenSSL.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
WHC
2026-10-29 11:16:26 +08:00
co-authored by Cursor
parent a3e115539e
commit 5900b53642
5 changed files with 241 additions and 56 deletions
+10 -5
View File
@@ -8,17 +8,22 @@
extern "C" {
#endif
/* Mutual Realm certificate challenge over TCP (cleartext for now; TLS wrap
* is the next slice). Same Realm public key required on both sides. */
/* Mutual Realm certificate challenge over TCP, then ephemeral X25519 +
* XChaCha20-Poly1305 (Monocypher) for the session. Same Realm public key
* required on both sides. */
typedef struct {
cst_realm_cert_t remote;
char host[64];
int port;
intptr_t sock; /* open until cst_peer_close */
uint8_t aead_key[32];
uint64_t send_ctr;
uint64_t recv_ctr;
int sealed; /* 1 after key exchange */
} cst_peer_session_t;
/* Dial host:port, prove our cert, verify theirs. 0 on success.
/* Dial host:port, prove our cert, verify theirs, establish AEAD session.
* Leaves sock open for post-handshake sync; call cst_peer_close. */
int cst_peer_dial(const char *host, int port, const cst_realm_cert_t *self,
const uint8_t self_sk[64], const uint8_t realm_pk[32],
@@ -33,8 +38,8 @@ int cst_peer_accept(intptr_t listen_sock, const cst_realm_cert_t *self,
void cst_peer_close(cst_peer_session_t *s);
/* After handshake: exchange parliament revision/context. Higher revision wins
* and is written locally via the callbacks. Returns 0 on success. */
/* After handshake: exchange parliament revision/context over the sealed
* channel. Higher revision wins. Returns 0 on success. */
typedef struct {
unsigned long revision;
char parliament_id[64];
+1 -1
View File
@@ -3,7 +3,7 @@
#define CST_VERSION_MAJOR 0
#define CST_VERSION_MINOR 9
#define CST_VERSION_PATCH 16
#define CST_VERSION_PATCH 17
#define CST_VERSION_STR_(x) #x
#define CST_VERSION_STR(x) CST_VERSION_STR_(x)