Skip to main content

Module noise

Module noise 

Source
Expand description

Sendspin’s Noise layer: Noise_KKpsk2_25519_<cipher>_SHA256.

Every Sendspin connection is wrapped in Noise. The handshake follows the cleartext init exchange and precedes all application traffic:

client -> server  client/init      cleartext JSON, carries the client_id and the suite
server -> client  server/init      cleartext JSON, carries the server_id
server -> client  noise/handshake  Noise message 1, payload {"psk_id": .., "psk_category": ..}
client -> server  noise/handshake  Noise message 2, payload {}

The server is always the Noise initiator and the client the responder, whichever side opened the WebSocket. Both static public keys are known before the handshake (KK), and the pre-shared key is mixed in at the end of the second message (psk2). The Noise prologue is the exact concatenation of the client/init and server/init bytes as sent on the wire, so tampering with the cleartext exchange fails the handshake.

This module carries both halves of the handshake - Responder for the client, Initiator for the server - plus the transport that follows it. It does not interpret handshake payloads; the session layer validates the psk_id/psk_category metadata. A handshake starts with the published Sentinel PSK, which is what an unpaired client uses and which provides no authentication on its own; the session layer reads the PSK metadata from message 1 and selects the matching key through Responder::set_psk or Initiator::set_psk before it answers.

§Cipher suites

The specification defines two suites and requires a server to support both. Suite is the set this build has; a name outside it is refused. The client picks the suite and announces it in client/init, so there is no negotiation to fall back from: a responder built for another suite than the one announced is an error, not a downgrade.

Structs§

Identity
A long-lived X25519 keypair that identifies one side of a connection.
Initiator
Noise initiator state for one connection: the server half.
Responder
Noise responder state for one connection.
TransportState
A Noise transport session: one ciphertext per message.

Enums§

PskOutcome
Which key sealed the handshake message 2 the initiator just read.
Suite
A Sendspin cipher suite: the <DH>_<cipher>_<hash> tail of a Noise protocol name.

Constants§

MAX_MESSAGE_LEN
Maximum size of one Noise message, handshake or transport, including the authentication tag.
MAX_PLAINTEXT_LEN
Largest plaintext that fits into one Noise transport message, including the leading binary message id byte.
NOISE_PARAMS
Noise protocol parameters of the default suite, Suite::ChaChaPoly.
SENTINEL_PSK
The published Sentinel PSK, used whenever no paired PSK applies.
SENTINEL_PSK_ID
The Sentinel PSK’s published id, psk_id_for(SENTINEL_PSK).
TAG_LEN
Length of the authentication tag appended to every Noise transport ciphertext.

Functions§

psk_id_for
Derives a PSK id: base64url(SHA-256("sendspin-psk-id-v1" || psk)), without padding.