nx_totp_verify.nx
buildroot/runtime/nx_totp_verify.nx
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
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
structs
| none |
consts
| 32 | const TV_MAGIC_287082: i64 = 287082 |
| 33 | const TV_MAGIC_999999: i64 = 999999 |
| 35 | const TV_ERR_NO_MATCH: i64 = -1000 // way outside any reasonable window |
functions
| 41 | func totp_sha1_verify(secret: *u8, secret_len: i64, |
| 69 | func totp_sha1_verify_default(secret: *u8, secret_len: i64, calls 1: totp_sha1_verify |
| 79 | func main() -> i64 |