Expand description
PNP — the information-theoretic true one-time pad tier, the last resort should
computational cryptography fall (the P = NP scenario the name marks).
Every other suite in super::channel — Classic, Hybrid, PQ, PQ-Max — rests on a
hardness assumption (a lattice, a factoring, a discrete-log problem). If those assumptions
collapse, so does the secrecy. This tier does not: a Vernam one-time pad is perfectly secret
by Shannon’s theorem, unconditionally, against a computationally unbounded adversary. The price
Shannon exacts is exact and unavoidable — one truly random pad byte per plaintext byte, used
once and never again — so this is a break-glass tier for crown-jewel traffic, not the bulk path.
Two constraints define the design:
- A true pad, never a stream. The pad is not grown from a seed by a PRG — that would be a
stream cipher (computationally secure, and so it would fall with
P = NP, defeating the entire purpose). The pad is pre-provisioned, externally-sourced true randomness, shared out of band. “Rotation” is a synchronized cursor advancing through that pool, consuming a fresh, never-reused segment per message. - No randomness at runtime.
PnpSuite::seal/PnpSuite::opendraw zero entropy — they are pure deterministic functions of(pad, ledger, plaintext). All randomness is the pad.
The pad is quality-gated at provisioning: a real pad is incompressible (K(pad) ≈ |pad|), so
PadPool::shared rejects any pool the logicaffeine_proof::ait classifier can compress — a
structured “pad” is a weak pad. (The connection is exact: a PRG-grown pad is by definition
low-Kolmogorov-complexity, which is precisely what the classifier detects.)
Confidentiality alone is not enough: XOR is malleable — flip a ciphertext bit and the plaintext
bit flips, undetected. So each cover carries a one-time Wegman–Carter MAC (Poly1305 keyed by
fresh pad bytes, logicaffeine_system::aead::poly1305); because the key is one-time pad
material, the authentication is also information-theoretic, not computational.
Two regions per half. A MAC key is only a secret while no ciphertext has exposed it, and a cover’s keystream is exposed to anyone who knows its plaintext. So keystream and MAC keys never share pad: each directional half hands out keystream from its bottom, upward, and 32-byte MAC keys from its top, downward, one key slot per cover; the half is spent when the two meet. A cover names its key slot and its keystream offset, both under its tag, and a receiver keys the MAC only from the key region — were it to key the MAC from wherever a frame said, a cover placed over a known stretch of keystream would carry a MAC key its forger knows.
A durable ledger. Reissuing a byte of pad is a two-time pad, and a cursor that lived only in
the process would start at the bottom on every run. Every reservation is made through a
PadLedgerStore, which reads, advances and durably records the half’s position under one
exclusive hold before the frame exists, so a crash can only waste pad, and two holders of one ledger
(two threads, two processes) never draw the same byte. The ledger also keeps the receive half’s
high-water key slot, so a cover opened before a restart is refused after it. A ledger that cannot
be read closes the pad: it is never taken for a fresh one.
Speed. seal writes the plaintext straight into the frame buffer and XORs the pad in place
(one pass, LLVM-vectorized), then MACs a single contiguous region — no intermediate ciphertext
copy, one allocation. Throughput is therefore bounded by Poly1305 (which has an AVX2 path) plus a
memcpy-speed XOR: a one-time pad is cheap when the codec never copies the payload twice.
The next pad. Net-new pad entropy cannot be produced inside the channel (Shannon), so the next pad is always fresh out-of-band randomness. What the codec provides is a seamless, authenticated handoff: each frame is tagged with its pad epoch; when a pool nears exhaustion a peer emits an authenticated roll cover (a kind-tagged cover, MAC’d by the current pad) committing to the next epoch’s id and a hash of the next pad, so both sides confirm they hold identical bytes before switching.
Frames ride the super::channel envelope:
[ CHAN_MAGIC | CHAN_VER | SUITE_PNP | kind:u8 | epoch:u32 | offset:u64 | len:u32 | slot:u64 | ct(len) | tag:16 ]Structs§
- File
Ledger - The file ledger: the position lives in a file, every update holds an exclusive lock on a sibling lock file across its read and its record, and a record is written to a temporary file, synced, renamed over the ledger and the directory synced, so a crash leaves the old position or the new one and a restart resumes past every byte ever handed out. A missing ledger is a fresh pad; a ledger of any other shape, or one that cannot be read, is an error.
- Ledger
Error - Why a ledger could not be read or recorded. Either way the pad is closed: a position that cannot be read could be a position that has already handed out every byte below it.
- MemLedger
- The in-memory ledger: correct for one process’s sessions over a pad no other run will use.
- PadLedger
- Where one pad’s two halves stand: what the send half has handed out, and how far the receive half has opened.
- PadPool
- A shared, pre-provisioned pool of true random bytes for one pad epoch, split into two directional halves. Both peers build an identical pool from the same out-of-band material and split it the same way, so each direction is a private, agreed pad both sides index into.
- PnpSession
- A live bidirectional PNP session for the interpreter’s send/receive seam: it seals outbound covers
with this peer’s send half and opens inbound covers with its receive half. Install it on the
channel via
super::channel::with_session/super::channel::install_sessionand everySend/ receive on that thread is one-time-pad protected — fail-closed on exhaustion. - PnpSuite
- A keyed one-time-pad channel over one directional half of a
PadPoolat one pad epoch. A peer seals with the suite for its send direction and opens with the suite for its receive direction; because the two directions are different pad halves, a peer never seals and opens over the same bytes.
Enums§
- PadError
- Why a pad pool was refused at provisioning.
- Role
- Which end of the shared pool this peer is. The pool is split identically on both peers into two
directional halves so the two directions never draw overlapping pad — the same reasoning behind
super::channel::derive_aead_key’si2r/r2isplit, made physical.
Constants§
- MAC_
KEY_ LEN - The one-time Poly1305 MAC key length: each cover takes one key slot of this many pad bytes from
the top of its half, on top of the
lenkeystream bytes it takes from the bottom. - RECV_
WINDOW_ COVERS - The default receiver reorder/replay window, in covers: a cover whose key slot is this many or more behind the newest one opened can no longer be told from a replay, and is refused. Forward jumps (a dropped cover skipped) are always fine.
- TAG_LEN
- The authenticator tag length (Poly1305).
Traits§
- PadLedger
Store - The durable record of a pad’s position — the state whose loss would be catastrophic, because reissuing a byte the send half has handed out is a two-time pad.
Functions§
- frame_
key_ slot - The key slot a
PNPframe’s MAC key is drawn from, orNoneif it is not a well-formedPNPframe. - frame_
kind - The cover kind of a
PNPframe (KIND_DATA/KIND_ROLL), orNoneif it is not a well-formedPNPframe — lets a receive loop dispatch data vs. handoff without opening. - frame_
offset - The half-local keystream offset a
PNPframe draws from, orNoneif it is not a well-formedPNPframe. Useful for monitoring the pad high-water mark without opening the cover.