Systematic memory zeroization with compile-time and runtime guarantees.
Overview
redoubt-zero provides RAII guards and derive macros for automatic, verifiable zeroization. Zeroization happens automatically on drop with runtime verification that it actually occurred.
This is a convenience re-export crate combining [redoubt-zero-core] and [redoubt-zero-derive].
Quick Start
use ;
let mut buffer = TempBuffer ;
// Use buffer...
// Automatically zeroized on drop
drop;
How It Works
1. The Sentinel Pattern
Every struct includes a ZeroizeOnDropSentinel field. This sentinel:
- Flips a flag on drop
- Can be cloned to verify the original was zeroized
- Provides runtime proof of zeroization
2. Automatic Trait Implementation
The #[derive(RedoubtZero)] macro generates:
FastZeroizable: Implementsfast_zeroize(&mut self)to zero all fieldsZeroizationProbe: Implementsis_zeroized(&self)to check if data is zeroedAssertZeroizeOnDrop: Test helper to verify drop behavior- Optional Drop impl: With
#[fast_zeroize(drop)], generatesDropthat callsfast_zeroize()
3. Field Skipping
Fields can be excluded from zeroization with #[fast_zeroize(skip)]:
# use ;
Core Types
ZeroizeOnDropSentinel: Drop sentinel for verifiable zeroizationZeroizingGuard<T>: RAII wrapper that zeroizes on drop (owned)ZeroizingMutGuard<'a, T>: RAII wrapper that zeroizes on drop (borrowed)
Traits
FastZeroizable: Providesfast_zeroize(&mut self)for efficient zeroizationZeroizationProbe: Providesis_zeroized(&self)to check if data is zeroedAssertZeroizeOnDrop: Test helper to verify drop zeroizationZeroizeMetadata: Field count metadata for verification
Testing Zeroization
Use AssertZeroizeOnDrop::assert_zeroize_on_drop() in tests to verify behavior:
# use ;
Design Rationale
The Sentinel Pattern
The sentinel enables runtime verification without unsafe code:
- Clone the sentinel before drop
- Drop the original
- Check the sentinel's flag flipped
This proves Drop ran and zeroization occurred.
FastZeroizable Implementation
FastZeroizable uses compiler fences for zeroization:
- Matches LLVM's optimization model
- Allows vectorization and unrolling
- Prevents dead store elimination
See redoubt-zero-core for implementation details.
Use Cases
Useful for any data that needs guaranteed cleanup:
- Cryptographic material: Keys, nonces, IVs
- Temporary buffers: Workspace memory, intermediate results
- Session data: Tokens, cookies, auth state
- Parser state: Untrusted input, partial parses
- Any heap allocation you want cleaned up reliably
Crate Structure
This crate re-exports:
redoubt-zero-core: Core types and traitsredoubt-zero-derive:#[derive(RedoubtZero)]macro
License
GPL-3.0-only