code wiki / (root) / nx_totp_sha1.nx

nx_totp_sha1.nx

buildroot/runtime/nx_totp_sha1.nx

3867 B116 linesdepth 4pulls 4 transitivereach 6 importersview sourcekind tooltopic totp
docsdependenciesstructsconstsfunctions

about

totp_sha1.nx -- RFC 6238 TOTP with SHA-1 (Google Authenticator default, Authy, Microsoft Authenticator, Duo, etc.). Companion to otp.nx which shipped SHA-256 variants. The real world runs on HMAC-SHA-1 TOTP because RFC 6238 specified it as the default and every authenticator app followed suit. Protocol: HOTP(K, C) = truncate(HMAC-SHA-1(K, C_be64)) mod 10^digits TOTP(K) = HOTP(K, floor(now_unix / step)) Standard params: digits = 6 step = 30 seconds T0 = 0 (unix epoch) Composes hmac_sha1.nx. Invariants: TS1 Dynamic truncation per RFC 4226 ยง5.3: last 4 bits of hash = offset; take 4 bytes @ offset with high bit of first masked off (31-bit unsigned). TS2 Leading zeros are preserved by otp_render (6-digit codes starting with 0 are common and still valid).

dependencies 2 imports · 2 importers

nx_syscalls.nx nx_hmac_sha1.nx nx_totp_sha1.nx nx_mfa.nx nx_totp_verify.nx

imports: nx_syscalls.nxnx_hmac_sha1.nx

imported by: nx_mfa.nxnx_totp_verify.nx

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

main totp_sha1_default totp_sha1_value hotp_sha1_value sys_mmap hmac_sha1 sys_mmap ↻ sha1 sys_mmap ↻ sha1_process_block if_ge sys_mmap ↻ totp_sha1_render

structs

none

consts

34const TOTP_MAGIC_1000000: i64 = 1000000
36const TOTP_SHA1_STEP_SECONDS: i64 = 30
37const TOTP_SHA1_DIGITS: i64 = 6

functions

41func hotp_sha1_value(key: *u8, key_len: i64,
72func totp_sha1_value(key: *u8, key_len: i64,
79func totp_sha1_default(key: *u8, key_len: i64, now_unix: i64) -> i64
called by 1: main calls 1: totp_sha1_value
87func totp_sha1_render(value: i64, digits: i64, out: *u8) -> i64
called by 3: mfa_verifymainmain
101func main() -> i64