1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//! 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_abort`] clears 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-lock` feature on supported Linux, Android, macOS, iOS, Windows,
//! and BSD targets. On WASM, `memory-lock` must be paired with `wasm-compat`
//! to expose volatile-only compatibility types without host memory locking.
//! The same feature also enables pooled slots with [`SecretPool`] on
//! 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-check` feature on supported targets.
//! - OS-CSPRNG canary generation is available only through the explicit
//! `random-canary` feature.
//! - The dependency-free default enables `asm-compare`, selecting the reviewed
//! x86_64/AArch64 assembly equality backend where available. Builds using
//! `default-features = false` retain the weaker portable fallback unless they
//! explicitly enable `asm-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 include
//! `strict-canary-check` and `require-fork-exclusion`.
//! - Named native profiles bundle reviewed capabilities without claiming that
//! runtime protections succeeded. Use [`ProtectionRequest`] to inspect the
//! policy and [`ProtectionReport`] to inspect achieved controls.
//! - Checked x86_64 cache-line eviction is available through the explicit
//! `cache-flush` feature. 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 `derive`
//! feature. The default build remains dependency-free.
//! - `zeroize`, `subtle`, and `serde` integration are available only through
//! explicit `zeroize-interop`, `subtle-interop`, and `serde` features. 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 `std`
//! feature and [`ExpiringSecretBytes`].
//! - Guard-page allocation is available only through the explicit
//! `guard-pages` feature 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-lock` exposes
//! volatile-only compatibility types on WASM only when `wasm-compat` is also
//! enabled, so callers explicitly acknowledge the reduced guarantees.
//! `guard-pages` is 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`](https://github.com/valkyoth/sanitization/blob/main/docs/MIGRATION_2.0.md).
//! Generic `Secret<T>` exposure is governed by the conditional contracts in
//! [`docs/STORAGE_CONTRACTS.md`](https://github.com/valkyoth/sanitization/blob/main/docs/STORAGE_CONTRACTS.md),
//! and native hardening policy/report semantics are defined in
//! [`docs/PROTECTION_REPORT.md`](https://github.com/valkyoth/sanitization/blob/main/docs/PROTECTION_REPORT.md).
compile_error!;
compile_error!;
compile_error!;
compile_error!;
compile_error!;
compile_error!;
compile_error!;
compile_error!;
compile_error!;
extern crate alloc;
extern crate std;
pub use ;
pub use compare_asm;
pub use *;
/// Safe direct wiping helpers for ordinary buffers.
/// Data-oblivious primitives for secret-handling code.
///
/// This module intentionally uses the familiar `ct` name, but its documented
/// claim is narrower than "identical wall-clock time": APIs here are designed
/// to avoid secret-dependent control flow and secret-dependent memory access
/// under documented compiler, target, feature, and release-profile conditions.
///
/// Lengths, allocation behavior, panics, page faults, scheduling, and the final
/// decision to branch on a secret-derived result are public effects. Use
/// [`ct::Choice::declassify`] at that boundary so reviewers can search for it.
pub use *;
pub use ;
pub use *;