code wiki / (root) / totp_sha1.nx

totp_sha1.nx

buildroot/runtime/totp_sha1.nx

3668 B109 linesdepth 4pulls 5 transitivereach 1 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 · 1 importers

syscalls.nx hmac_sha1.nx totp_sha1.nx totp_verify.nx

imports: syscalls.nxhmac_sha1.nx

imported by: 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 hmac_sha1 sha1 sys_mmap sha1_process_block if_ge totp_sha1_render

structs

none

consts

29const TOTP_SHA1_STEP_SECONDS: i64 = 30
30const TOTP_SHA1_DIGITS: i64 = 6

functions

34func hotp_sha1_value(key: *u8, key_len: i64,
65func totp_sha1_value(key: *u8, key_len: i64,
72func totp_sha1_default(key: *u8, key_len: i64, now_unix: i64) -> i64 {
called by 1: main calls 1: totp_sha1_value
80func totp_sha1_render(value: i64, digits: i64, out: *u8) -> i64 {
called by 1: main
94func main() -> i64 {