code wiki / (root) / totp_verify.nx

totp_verify.nx

buildroot/runtime/totp_verify.nx

3919 B99 linesdepth 5pulls 7 transitivereach 0 importersview sourcekind tooltopic totp
docsdependenciesstructsconstsfunctions

about

totp_verify.nx -- TOTP code verification with clock-skew window. Companion to totp_sha1.nx. A bare "is the code equal to totp(secret, now)?" check fails whenever the user's device clock drifts by a few seconds past the step boundary. RFC 6238 ยง5.2 recommends accepting the code from step N-1 and N+1 as well, for a 3-window tolerance. We generalise to caller-chosen window size. Uses constant-time comparison (ct.nx) across all candidate windows so timing doesn't leak which window matched (hardening against code-enumeration attacks from a malicious client). Invariants: TV1 Provided code compared against every window in [now_step - window, now_step + window], inclusive. TV2 Match check uses ct_eq on the integer value -- no timing side-channel per window. TV3 Returns matched window offset (negative meaning older step, 0 = current, positive = newer) on success, or TV_ERR_NO_MATCH if nothing in range matches.

dependencies 3 imports · 0 importers

syscalls.nx totp_sha1.nx ct.nx totp_verify.nx

imports: syscalls.nxtotp_sha1.nxct.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main totp_sha1_value hotp_sha1_value hmac_sha1 sha1 sys_mmap sha1_process_block if_ge totp_sha1_verify hotp_sha1_value ↻ ct_eq

structs

none

consts

27const TV_ERR_NO_MATCH: i64 = -1000 // way outside any reasonable window

functions

33func totp_sha1_verify(secret: *u8, secret_len: i64,
61func totp_sha1_verify_default(secret: *u8, secret_len: i64,
71func main() -> i64 {