ct only.Expand description
Constant-time (masked-return) counterparts of the Tier-B atoms, built on
subtle’s Choice and CtOption. Only available with the ct
cargo feature.
The plain Tier-B traits (CheckedAdd, Parity, IsPowerOfTwo, …)
return bool/Option, which invite branching on secret-derived data at
the call site. The traits here return Choice/CtOption instead, so
the secret-derived condition stays masked until the caller explicitly
unwraps it.
Selection and equality are deliberately not duplicated here — use
subtle::ConditionallySelectable and subtle::ConstantTimeEq directly.
These are plain (never-const) traits: subtle’s constructors are not
const fn, so a const port has to wait for subtle. This does not affect
the c0nst story of the rest of the crate.
Note on the primitive impls: “constant time” here means the usual
best-effort guarantee for Rust code — branchless source operating on
values the compiler has no reason to branch on (the same contract subtle
itself provides). Types with stronger needs (e.g. a Ct-personality
bigint) implement these traits with their own hardened bodies.
Traits§
- CtChecked
Add - Constant-time checked addition (the masked counterpart of
CheckedAdd). - CtChecked
Mul - Constant-time checked multiplication (the masked counterpart of
CheckedMul). - CtChecked
Neg - Constant-time checked negation (the masked counterpart of
CheckedNeg). - CtChecked
Signed Diff - Constant-time signed difference of unsigned values (the masked
counterpart of
CheckedSignedDiff). - CtChecked
Sub - Constant-time checked subtraction (the masked counterpart of
CheckedSub). - CtIs
Power OfTwo - Constant-time power-of-two check (the masked counterpart of
IsPowerOfTwo). - CtIs
Zero - Constant-time zero check.
- CtParity
- Constant-time parity check (the masked counterpart of
Parity).