Skip to main content

Module ct

Module ct 

Source
Available on crate feature 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§

CtCheckedAdd
Constant-time checked addition (the masked counterpart of CheckedAdd).
CtCheckedMul
Constant-time checked multiplication (the masked counterpart of CheckedMul).
CtCheckedNeg
Constant-time checked negation (the masked counterpart of CheckedNeg).
CtCheckedSignedDiff
Constant-time signed difference of unsigned values (the masked counterpart of CheckedSignedDiff).
CtCheckedSub
Constant-time checked subtraction (the masked counterpart of CheckedSub).
CtIsPowerOfTwo
Constant-time power-of-two check (the masked counterpart of IsPowerOfTwo).
CtIsZero
Constant-time zero check.
CtParity
Constant-time parity check (the masked counterpart of Parity).