e2e

package
v0.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package e2e — shared end-to-end envelope primitives. ML-KEM-768 encapsulation, HKDF-SHA256 key derivation, ChaCha20-Poly1305 AEAD, and gzip, in the wire layout used by chutes. Each provider package owns its own discovery, attestation, transport, and stream handling; this package only translates plaintext <-> wire envelopes.

Index

Constants

View Source
const (
	MLKEMCTSize = 1088 // ML-KEM-768 ciphertext
	SaltSize    = 16   // HKDF salt = mlkem_ct[:16]
	KeySize     = 32   // ChaCha20-Poly1305 key / ML-KEM shared secret
	NonceSize   = chacha20poly1305.NonceSize
	TagSize     = chacha20poly1305.Overhead
)

Pinned wire sizes (chutes WIRE.md sections 1-2).

Variables

View Source
var ErrShortBlob = errors.New("blob shorter than nonce+tag")

ErrShortBlob is returned when an encrypted wire blob is too short to hold the required nonce and authentication tag. Exported for callers that branch on it via errors.Is.

Functions

func DeriveKey

func DeriveKey(shared, mlkemCT, info []byte) ([]byte, error)

DeriveKey computes the per-message AEAD key: HKDF-SHA256(ikm=shared, salt=mlkemCT[:16], info), 32 bytes. The salt is the first 16 bytes of THIS message's ML-KEM ciphertext, not a constant (chutes WIRE.md section 1).

func Open

func Open(shared, mlkemCT, blob, info []byte, gunzip bool) ([]byte, error)

Open reverses Seal given the already-decapsulated shared secret, the mlkemCT used for the HKDF salt, and blob = nonce || ct || tag. It derives the direction key from info, AEAD-opens, and optionally gunzips.

func OpenFrame

func OpenFrame(key, blob []byte) ([]byte, error)

OpenFrame opens a single AEAD frame (blob = nonce || ct || tag) with an already-derived key. This is the stream path: the stream key is derived once from the e2e_init ciphertext and reused, and stream frames are never gzipped.

func Seal

func Seal(plaintext, recipientPub, info []byte, gzipFirst bool) (mlkemCT, blob []byte, err error)

Seal encapsulates a fresh shared secret to the recipient's ML-KEM-768 encapsulation key, derives the direction key via info, optionally gzips the plaintext, then AEAD-seals it under a random nonce. It returns the ML-KEM ciphertext (1088 bytes) and blob = nonce(12) || ciphertext || tag(16). Callers prepend mlkemCT to blob for the request/response wire layout; stream frames omit it.

func SealFrame

func SealFrame(key, plaintext []byte) ([]byte, error)

SealFrame is the inverse of OpenFrame: it AEAD-seals plaintext under an already-derived key and a fresh random nonce, returning nonce || ct || tag. No ML-KEM, no gzip — this is exactly the stream-chunk wire layout (chutes WIRE.md section 2). It exists so test/fixture code can produce real e2e frames; the production client never seals stream frames (the server does).

Types

type Error

type Error struct {
	Op  string
	Err error
}

Error wraps any envelope failure: HKDF derivation, ML-KEM encapsulation/decapsulation, ChaCha20-Poly1305 seal/open, gzip, or a malformed wire blob. Op names the failing operation; Err is the cause and is inspectable via errors.As / errors.Is.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL