Expand description
Dependency-free secret memory sanitization for no_std Rust.
The primary type is SecretBytes, a fixed-size clear-on-drop container
designed for secrets that are controlled from creation through destruction.
Clearing routes through a small internal volatile-write backend. That backend uses one isolated unsafe boundary so the optimizer cannot remove secret clearing as a dead store.
The ct module provides dependency-free data-oblivious primitives such as
ct::Choice, ct::ConstantTimeEq, and explicit
ct::Choice::declassify boundaries. Its claim is no secret-dependent
control flow or memory access under documented conditions, not identical
wall-clock timing on every target.
Important limits:
- Safe Rust cannot soundly scrub old stack frames created by prior moves.
- Process abort prevents destructors and post-closure cleanup from running.
- SIMD stores, broad memory policy, and target-specific hardening need target-specific unsafe code and platform policy.
- Platform memory locking is available only through the explicit
memory-lockfeature on supported Linux, Android, macOS, iOS, Windows, and BSD targets. On WASM,memory-lockmust be paired withwasm-compatto expose volatile-only compatibility types without host memory locking. The same feature also enables pooled slots withSecretPoolon supported targets. - Locked, pooled, and guarded canary integrity checks are available only
through the explicit
canary-checkfeature on supported targets. - OS-CSPRNG canary generation is available only through the explicit
random-canaryfeature. - x86_64/AArch64 assembly-backed comparison is available only through the explicit
asm-comparefeature. - High-assurance fail-closed profiles are available through
strict-ct,strict-canary-check, andrequire-fork-exclusion. - x86_64 cache-line eviction is available only through the explicit
cache-flushfeature. - Proc-macro derives are available only through the explicit
derivefeature. The default build remains dependency-free. zeroize,subtle, andserdeintegration are available only through explicitzeroize-interop,subtle-interop, andserdefeatures. They are off by default.- Fixed-size lifetime enforcement is available only through the
stdfeature andExpiringSecretBytes. - Guard-page allocation is available only through the explicit
guard-pagesfeature on supported Linux, Android, macOS, iOS, Windows, and BSD targets. - WASM has no kernel page table,
mlock,mprotect, or native volatile semantics. Base secret containers compile on WASM.memory-lockexposes volatile-only compatibility types on WASM only whenwasm-compatis also enabled, so callers explicitly acknowledge the reduced guarantees.guard-pagesis rejected at compile time on WASM.
Modules§
- cache_
flush - ct
- Data-oblivious primitives for secret-handling code.
- hardware
- Traits for integrating external hardware-backed secret providers.
- register_
scrub - Architecture-specific register scrubbing helpers.
- unsafe_
wipe - Explicit volatile-write backend for ordinary mutable buffers.
Macros§
- secure_
drop_ struct - Declare a struct and generate
SecureSanitizeplusDrop. - secure_
sanitize_ struct - Declare a struct and generate
SecureSanitizefor all fields.
Structs§
- Already
Consumed Error - Error returned after a
ReadOnceSecrethas already been consumed. - Canary
Corrupted Error - Error returned when a checked locked secret detects canary corruption.
- Expiring
Secret Bytes - Fixed-size secret bytes with
stdlifetime enforcement. - Guard
Page Error - Error returned by guarded secret allocation operations.
- Guarded
Secret Vec - Dynamic secret bytes stored between inaccessible platform guard pages.
- Length
Error - Error returned when a caller provides a buffer with the wrong length.
- Locked
Secret Bytes - Fixed-size secret bytes stored in a private locked platform mapping.
- Locked
Secret Vec LockedSecretVecfills the gap betweencrate::SecretVecandcrate::GuardedSecretVec. It supports runtime-length secret bytes in platform-locked memory without adding guard pages, which keeps memory overhead lower for large PEM/DER material, tokens, or generated secrets where page-fence protection is not required.- Memory
Lock Error - Error returned by platform memory-locking operations.
- Monotonic
Expiring Secret Bytes - Fixed-size secret bytes with caller-provided monotonic lifetime enforcement.
- Read
Once Secret - Clear-on-drop wrapper that can be consumed exactly once.
- Secret
- Clear-on-drop wrapper for non-byte secret types.
- Secret
Bytes - Fixed-size secret byte storage with automatic sanitization on drop.
- Secret
Expired Error - Error returned when an expiring secret has exceeded its configured lifetime.
- Secret
Pool - Fixed-slot arena for many same-size secrets inside one locked mapping.
- Secret
Pool Slot - A live fixed-size secret slot allocated from a
SecretPool. - Secret
String - Heap-allocated secret UTF-8 text with clear-on-drop behavior.
- Secret
Vec - Heap-allocated secret bytes with clear-on-drop behavior.
- Split
Secret Bytes - Fixed-size N-of-N XOR split secret storage.
Enums§
- Expiring
Secret Error - Error returned by expiring secret operations.
- Guard
Page Operation - Platform guard-page operation that failed.
- Guarded
Secret VecGenerate Error - Error returned when fallible guarded byte generation fails.
- Locked
Secret Bytes Checked Copy Error - Error returned by checked locked-secret copy operations.
- Locked
Secret Bytes Error - Error returned when constructing
LockedSecretBytesfrom a slice. - Locked
Secret Bytes Generate Error - Error returned when fallible locked secret byte generation fails.
- Locked
Secret VecFill Error - Error returned when in-place locked dynamic byte filling fails.
- Locked
Secret VecGenerate Error - Dynamic secret bytes stored in a private locked platform mapping.
- Memory
Lock Operation - Platform memory-locking operation that failed.
- Split
Secret Error - Error returned by split-secret construction.
Traits§
- Monotonic
Clock - Caller-provided monotonic tick source for no-
stdexpiring secrets. - Secure
Sanitize - Shared trait for values that can clear their own sensitive contents.
Functions§
- sanitize_
bytes - Clear ordinary mutable bytes with volatile writes.
- sanitize_
bytes_ best_ effort - Compatibility alias for
sanitize_bytes. - sanitize_
bytes_ multi_ pass - Clear ordinary mutable bytes with an explicit three-pass volatile pattern.
- secure_
replace - Sanitize a value before replacing it.
Derive Macros§
- Conditionally
Selectable - Derive
sanitization::ct::ConditionallySelectablefor structs. - Constant
Time Eq - Derive
sanitization::ct::ConstantTimeEqfor structs. - Secure
Sanitize - Derive
sanitization::SecureSanitizefor structs and enums. - Secure
Sanitize OnDrop - Derive
Dropby callingsanitization::SecureSanitize::secure_sanitize.