pub fn set_record_stack_erasure(enabled: bool)Expand description
Turns on or off, for the whole process, the stack overwrite after each record operation of
the paths that leave key copies in dead stack frames of code the crate cannot change: the
AWS-LC provider’s AEAD (its AES-GCM leaves a GHASH table entry) and HMAC (each MAC is
computed on a copy of the keyed context, HMAC-SHA1 for SRTP and the DTLS AES-CBC suites);
the ring provider’s ChaCha20-Poly1305 (the key is copied to the stack per record); and
AES-CCM (RustCrypto’s aes under ccm, which left round keys with compilers older than
rustc 1.99.1 in an optimised build). Each such call then runs in a frame of its own and the
stack below it is overwritten afterwards, as deep as that path was measured to use
(record_depth: a few KiB optimised; 128 KiB unoptimised), so no key is left in a dead stack frame
(RFC 7714 section 13.1: “All keys MUST be properly erased when no longer needed”;
rtci-srtp/tests/key_residue.rs, rtci-dtls/tests/key_residue.rs). On by default.
Off, those copies stay until later calls on the same thread overwrite them, and an
application that cares calls scrub_stack from that thread when a session ends. The
cost is one overwrite per record on those paths only (docs/performance.md); ring’s AES-GCM,
RustCrypto’s AES-CTR and AES-CBC and the ring provider’s HMAC were measured to leave nothing
and are not affected.