code wiki / (root) / nx_totp_verify.nx

nx_totp_verify.nx

buildroot/runtime/nx_totp_verify.nx

4206 B107 linesdepth 5pulls 6 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

nx_syscalls.nx nx_totp_sha1.nx nx_ct.nx nx_totp_verify.nx

imports: nx_syscalls.nxnx_totp_sha1.nxnx_ct.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 sys_mmap hmac_sha1 sys_mmap ↻ sha1 sys_mmap ↻ sha1_process_block if_ge totp_sha1_verify hotp_sha1_value ↻ ct_eq

structs

none

consts

32const TV_MAGIC_287082: i64 = 287082
33const TV_MAGIC_999999: i64 = 999999
35const TV_ERR_NO_MATCH: i64 = -1000 // way outside any reasonable window

functions

41func totp_sha1_verify(secret: *u8, secret_len: i64,
69func totp_sha1_verify_default(secret: *u8, secret_len: i64,
79func main() -> i64