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. Secret-controlled indexes and
scalars use clear-on-drop ct::SecretIndex and ct::SecretScalar
owners, while ct::SecretCtOption and ct::SecretCtResult manage
secret-bearing dummy and unselected state. 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.
Under
std,sanitize_then_abortclears one explicitly supplied root before a deliberate abort; it does not intercept arbitrary abort paths. - 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. The crate’s own Miri unit tests use a test-only aligned-allocation model for lifecycle and clear-before-release checks; modeled report states do not prove that an OS protection was applied. Downstream Miri execution of native mapped constructors is unsupported. - 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. - The dependency-free default enables
asm-compare, selecting the reviewed x86_64/AArch64 assembly equality backend where available. Builds usingdefault-features = falseretain the weaker portable fallback unless they explicitly enableasm-compare. - Fail-closed assembly-backed equal-length byte comparison is available
through
strict-compare. This feature does not strengthen ordering, selection, lookup, or caller code. Other fail-closed profiles includestrict-canary-checkandrequire-fork-exclusion. - Named native profiles bundle reviewed capabilities without claiming that
runtime protections succeeded. Use
ProtectionRequestto inspect the policy andProtectionReportto inspect achieved controls. - Checked x86_64 cache-line eviction is available through the explicit
cache-flushfeature. Other architectures and Miri return a structured unsupported result after sanitizing helpers have still cleared memory. - 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.- UTF-8 validation, serde size-limit rejection, and public-length mismatch handling are not data-oblivious operations. Callers must treat validity and length as public metadata when using text or variable-length APIs.
- 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.
§Migrating From 1.x
Version 2 makes storage stability, CT declassification, derive safety,
mapped integrity, and runtime protection outcomes explicit. The complete
source-change inventory and replacement examples are maintained in
docs/MIGRATION_2.0.md.
Generic Secret<T> exposure is governed by the conditional contracts in
docs/STORAGE_CONTRACTS.md,
and native hardening policy/report semantics are defined in
docs/PROTECTION_REPORT.md.
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.
- wipe
- Safe direct wiping helpers for ordinary buffers. Safe direct wiping helpers for ordinary owned buffers.
Macros§
- define_
secret_ storage_ policy - Define an application-owned concrete-type allow-list for
AllowlistedSecret. - secure_
drop_ struct - Declare a struct and generate
SecureSanitizeplusDrop. - secure_
sanitize_ struct - Declare a struct and generate
SecureSanitizefor all fields.
Structs§
- Allowlisted
Secret - Clear-on-drop secret gated by an application-controlled storage allow-list.
- Already
Consumed Error - Error returned after a
ConsumeOnceSecrethas already been claimed. - Bounded
Guarded Secret String - Guarded UTF-8 text with a permanent type-level byte maximum.
- Bounded
Guarded Secret Vec - Runtime-length guarded bytes with a permanent type-level maximum.
- Bounded
Locked Secret String - Locked UTF-8 text with a permanent type-level byte maximum.
- Bounded
Locked Secret Vec - Runtime-length locked bytes with a permanent type-level maximum.
- Bounded
Secret String - Heap-allocated secret UTF-8 text constrained to a public byte limit.
- Bounded
Secret Vec - Heap-allocated secret bytes constrained to a public maximum length.
- Canary
Corrupted Error - Error returned when a mapped secret’s integrity canaries are corrupted.
- Cleanup
Error - Error returned when explicit page-sealed cleanup is incomplete.
- Cleanup
Report - Observable result of explicit page-sealed mapping cleanup.
- Consume
Once Secret - Clear-on-drop wrapper that permits one scoped secret exposure.
- Expiring
Secret Bytes - Fixed-size secret bytes with
stdlifetime enforcement. - Fork
Protection Report - Actual outcome of the requested process-fork behavior.
- Fork
Protection Request - Fork behavior requested for a mapped secret allocation.
- Guard
Page Error - Error returned by guarded secret allocation operations.
- Guarded
Secret String - UTF-8 text stored between inaccessible platform guard pages.
- 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 String - UTF-8 text stored in a private platform mapping locked against paging.
- 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.
- Protection
Error - Error returned when a required runtime protection cannot be established.
- Protection
Failure - Non-secret description of a failed protection operation.
- Protection
Report - Runtime report retained by a mapped secret container.
- Protection
Request - Runtime protections requested for a mapped secret allocation.
- Rollback
Report - Cleanup results after a required protection could not be established.
- Sealed
Secret Bytes - Fixed-size secret bytes kept on an inaccessible page between accesses.
- Secret
- Clear-on-drop wrapper for non-byte secret types.
- Secret
BoxBytes - Fixed-allocation secret bytes with a runtime length.
- 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 Report - Point-in-time capacity and lock-efficiency report for a fixed-size pool.
- Secret
Pool Slot - A live fixed-size secret slot allocated from a
SecretPool. - Secret
Pool Slot Id - Stable identity of one live allocation from a fixed-size secret pool.
- Secret
String - Heap-allocated secret UTF-8 text with clear-on-drop behavior.
- Secret
String Limit Error - Error returned when secret UTF-8 text exceeds its declared public limit.
- Secret
Vec - Heap-allocated secret bytes with clear-on-drop behavior.
- Secret
VecLimit Error - Error returned when a dynamic secret exceeds its declared public limit.
- Split
Secret Bytes - Fixed-size N-of-N XOR split secret storage.
Enums§
- Bounded
Mapped Secret Error - Error returned by a permanently bounded mapped-secret mutation.
- Bounded
Secret String Error - Error returned while converting bounded secret bytes into UTF-8 text.
- Cleanup
State - Outcome of one explicit page-sealed cleanup operation.
- Expiring
Secret Error - Error returned by expiring secret operations.
- Fork
Policy - Desired treatment of secret mappings across process fork.
- Guard
Page Operation - Platform guard-page operation that failed.
- Guarded
Secret VecGenerate Error - Error returned when fallible guarded byte generation fails.
- Locked
Secret Bytes Error - Error returned when constructing
LockedSecretBytesfrom a slice. - Locked
Secret Bytes Fill Error - Error returned while fallibly filling a new locked fixed-size mapping.
- Locked
Secret Bytes Generate Error - Error returned when fallible locked secret byte generation fails.
- Locked
Secret Init Error - Error returned while initializing locked fixed-size secret storage.
- Locked
Secret Initialize Error - Error returned while initializing an existing locked fixed-size mapping.
- 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.
- Pool
Init Error - Error returned while initializing a locked pool slot from bytes.
- Protected
Secret Fill Error - Error returned when protected dynamic storage cannot be established and filled in place.
- Protected
Secret Text Fill Error - Error returned when protected UTF-8 storage cannot be established, filled, or validated.
- Protection
Control - Runtime control that failed during protected allocation.
- Protection
State - Actual outcome of one requested runtime protection.
- Requirement
- Whether a runtime memory-protection control is mandatory.
- Rollback
State - Result of one cleanup operation after failed construction.
- Sealed
Secret Access Error - Error returned by scoped page-sealed secret access.
- Secret
Allocation Error - Error returned when fallible dynamic secret allocation fails.
- Secret
Generate Error - Error returned by fallible dynamic secret generation.
- Secret
Integrity Error - Error returned by an operation that checks mapped-secret integrity.
- Secret
Pool Generate Error - Error returned when initializing a pool slot with a fallible generator.
- Secret
Text Integrity Error - Error returned when checked secret-text exposure detects corruption or invalid UTF-8.
- Split
Secret Error - Error returned by split-secret construction.
Constants§
- DEFAULT_
SECRET_ STRING_ SERDE_ MAX_ LEN - Default maximum accepted by serde deserialization into
SecretString. - DEFAULT_
SECRET_ VEC_ SERDE_ MAX_ LEN - Default maximum accepted by serde deserialization into
SecretVec.
Traits§
- Drop
Safe Sanitize - Security contract for calling
SecureSanitizefrom the value’s destructor. - Monotonic
Clock - Caller-provided monotonic tick source for no-
stdexpiring secrets. - Secret
Integrity Result Ext - Flattens a fallible mapped-secret exposure closure without losing the distinction between integrity corruption and the closure’s own error.
- Secret
Storage Policy - Application-controlled allow-list for concrete secret storage types.
- Secure
Sanitize - Clear the currently reachable sensitive contents owned by a value.
- Stable
Mutable Secret Storage - Security contract for secret storage exposed through mutable references.
- Stable
Shared Secret Storage - Security contract for secret storage exposed through shared references.
Functions§
- sanitize_
then_ abort - Sanitize one application-owned root value and then deliberately abort.
- secure_
replace - Sanitize a value before replacing it.
Type Aliases§
- Integrity
Result - Result alias for mapped operations that can fail only because integrity canaries were corrupted.
- Locked
Secret Bytes Checked Copy Error - Compatibility name for fixed-size copy operations that check integrity.
- Mapped
Result - Result alias for mapped operations that distinguish integrity corruption from an operation-specific failure.
- Secret
BoxBytes Build Error - Compatibility name for fixed-allocation build failures.
- Secret
BoxBytes Generate Error - Compatibility name for fixed-allocation generation failures.
- Secret
Integrity Result - Descriptive compatibility alias for
MappedResult.
Derive Macros§
- Conditionally
Selectable - Derive
sanitization::ct::ConditionallySelectablefor structs. - Constant
Time Eq - Derive
sanitization::ct::ConstantTimeEqfor structs. - Secure
Sanitize - Derive
sanitization::SecureSanitizefor structs. - Secure
Sanitize OnDrop - Derive
Dropby invoking the completeSecureSanitizeimplementation.