Skip to main content

Module util

Module util 

Source
Expand description

Small helpers: constant-time comparison and selection, hex for tests and diagnostics.

Functions§

ct_eq
Constant-time equality of two slices. The lengths are not secret.
ct_eq_mask
All-ones if a == b, else zero, as an opaque mask.
ct_mask
An all-ones (flag = 1) or all-zero (flag = 0) mask, hidden from the optimizer so that it cannot turn masked selection back into a branch (LLVM’s cmov-to-branch conversion would otherwise make table lookups and swaps leak through the branch predictor).
hex
Lower-case hex.
unhex
Decodes hex, ignoring whitespace and :. Panics on bad input (constants and tests only).
zeroize
Best-effort zeroing of secret material (not elided: the writes go through black_box).