totp_sha1.nx
buildroot/runtime/totp_sha1.nx
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
imports: syscalls.nxhmac_sha1.nx
imported by: totp_verify.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 29 | const TOTP_SHA1_STEP_SECONDS: i64 = 30 |
| 30 | const TOTP_SHA1_DIGITS: i64 = 6 |
functions
| 34 | func hotp_sha1_value(key: *u8, key_len: i64, |
| 65 | func totp_sha1_value(key: *u8, key_len: i64, |
| 72 | func totp_sha1_default(key: *u8, key_len: i64, now_unix: i64) -> i64 { |
| 80 | func totp_sha1_render(value: i64, digits: i64, out: *u8) -> i64 {
called by 1: main |
| 94 | func main() -> i64 { |