sealed

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: GPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sealed is the room record's bytes: one message locked under a fresh key, that key sealed to every recipient, a signed header that commits to the key, and the writer's counter in the header.

The wire form is header ‖ stanzas ‖ body ‖ signature, the first three length-prefixed (uint32 big-endian):

  • header: JSON {"v":1,"room":"<32 hex>","idx":k,"ctr":n,"kh":"<base64, 32 bytes>","at":"<RFC 3339 UTC ms>"}
  • stanzas: count (uint16) ‖ [idx (uint16) ‖ len (uint16) ‖ enc‖ct]*, in idx order; enc‖ct is HPKE single-shot (DHKEM X25519, HKDF-SHA256, AES-256-GCM) of the 32-byte body key K to the recipient's seal key, info = "peer room seal v1" ‖ room ‖ idx ‖ SHA-256(header)
  • body: AES-256-GCM under K, nonce twelve zero bytes, AAD = the header bytes
  • signature: Ed25519 over the length-prefixed header ‖ stanzas ‖ body by the writer's room signing key

kh = SHA-256("peer room key commit v1" ‖ K): the signature commits to the body key, so one signed record cannot open to two messages for two members. ctr is the writer's own count of records in the room, +1 each.

A receiver runs Parse, Verify under the roster's signing key for the header's idx, CheckCtr against the writer's last counter, then Open with its own idx and seal keys (the current one first, then each retired one).

Index

Constants

View Source
const AtLayout = "2006-01-02T15:04:05.000Z"

AtLayout is the header's at: RFC 3339, UTC, milliseconds.

View Source
const MaxRecord = 1 << 20

MaxRecord is the relay's cap on a record's decoded bytes (1 MiB).

View Source
const StanzaSize = 32 + 32 + 16

StanzaSize is enc ‖ ct for a 32-byte key under DHKEM(X25519) + AES-256-GCM.

View Source
const Version = 1

Version is the header's v.

Variables

View Source
var (
	ErrMalformed  = errors.New("sealed: malformed")
	ErrTooLarge   = errors.New("sealed: record over 1 MiB")
	ErrSignature  = errors.New("sealed: bad signature")
	ErrUnverified = errors.New("sealed: record not verified")
	ErrNoStanza   = errors.New("sealed: no stanza for this idx")
	ErrStanza     = errors.New("sealed: stanza opens under no key")
	ErrKeyCommit  = errors.New("sealed: key commitment mismatch")
	ErrBody       = errors.New("sealed: body does not open")
	ErrCtrGap     = errors.New("sealed: counter gap")
	ErrCtrBack    = errors.New("sealed: counter step back")
)

Functions

func CheckCtr

func CheckCtr(last, got uint64) error

CheckCtr compares a verified record's ctr with the writer's last one. A gap or a step back is reported for the receiver to log and read on.

func KeyCommit

func KeyCommit(k []byte) [32]byte

KeyCommit is kh: SHA-256("peer room key commit v1" ‖ k).

func Seal

func Seal(h Header, msg []byte, to []Recipient, signer ed25519.PrivateKey) ([]byte, error)

Seal locks msg under a fresh key sealed to each recipient and signs the record with the writer's room signing key. Recipients may come in any order; two at one idx refuse.

Types

type Header struct {
	Room string // 32 lowercase hex
	Idx  uint16 // the writer's index
	Ctr  uint64 // the writer's count of records in this room
	KH   [32]byte
	At   time.Time
}

Header is the signed header. Seal fills KH; At is written as UTC milliseconds.

type Recipient

type Recipient struct {
	Idx uint16
	Key *ecdh.PublicKey
}

Recipient is one member's X25519 seal key at its index.

type Record

type Record struct {
	Header Header
	// contains filtered or unexported fields
}

Record is a parsed sealed record.

func Parse

func Parse(b []byte) (*Record, error)

Parse splits and checks a record's framing and header. It verifies nothing: a parsed record is bytes of the right shape.

func (*Record) Open

func (r *Record) Open(idx uint16, keys ...*ecdh.PrivateKey) ([]byte, error)

Open finds idx's stanza, unwraps the body key with each seal key in turn (the current one first, then each retired one), checks it against the header's kh — a mismatch names the writer — and opens the body. It refuses a record Verify has not passed.

func (*Record) Recipients

func (r *Record) Recipients() []uint16

Recipients lists the stanza indexes in wire order.

func (*Record) Verify

func (r *Record) Verify(pub ed25519.PublicKey) error

Verify checks the signature under the writer's room signing key — the folded roster's key for Header.Idx.

Jump to

Keyboard shortcuts

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