Skip to main content

Module e2e

Module e2e 

Source
Expand description

End-to-end ElGamal encryption for byte payloads.

This module models E2E encryption as two separate protocol facts:

  • peers discover encryption public keys with signed handshake messages;
  • message bodies are encrypted directly with secp256k1 ElGamal stream frames, each carried by its own signed MessagePayload.

Rings intentionally uses the DID/account secp256k1 public key as the ElGamal key. The public key carried by a handshake or encrypted message must resolve to the signed DID; this is the protocol’s key-ownership proof. The module does not derive a separate encryption subkey.

The direct ElGamal body is deliberately not KEM/DEM or AEAD. Keeping the ciphertext in group-element form preserves the algebraic structure needed by future homomorphic operations. That also means ciphertext frames are malleable if detached from the signed message envelope. Integrity, sender authentication, public-key ownership, and per-frame integrity are provided by the surrounding MessagePayload signature. The stream id, sequence, and final marker make truncation observable and let the decryptor release reordered frames as a gapless plaintext stream.

Structs§

E2eHandshakeRequest
An invitation to start E2E encryption with the requester’s public key.
E2eHandshakeResponse
An acceptance of an E2E handshake with the responder’s public key.
E2eStreamDecryptor
Stateful streaming decryptor for direct ElGamal body frames.
E2eStreamEncryptor
Stateful streaming encryptor for direct ElGamal body frames.
E2eStreamFrame
One ordered ElGamal-encrypted stream frame.
E2eStreamFrames
Lazy iterator that encrypts one E2E stream frame per iteration.

Constants§

DEFAULT_E2E_PLAINTEXT_FRAME_LEN
Default plaintext bytes per encrypted E2E stream frame.
DEFAULT_E2E_REORDER_WINDOW_FRAMES
Default maximum number of out-of-order future frames buffered per stream.
E2E_PLAINTEXT_BLOCK_LEN
Plaintext bytes carried by one ElGamal body block.

Functions§

decrypt_stream
Decrypt a complete direct-ElGamal E2E frame sequence into bytes.
encrypt_stream_frames
Encrypt a byte slice lazily with the default thread-local RNG.
encrypt_stream_frames_with_rng
Encrypt a byte slice lazily into direct-ElGamal E2E stream frames.
encrypt_stream_with_rng
Encrypt a byte slice into direct-ElGamal E2E stream frames.
ensure_public_key_matches_did
Verify that a public key hashes to the expected DID.

Type Aliases§

E2eStreamId
Identifier shared by all frames of one encrypted E2E stream.