code wiki / (root) / otp.nx

otp.nx

buildroot/runtime/otp.nx

4191 B113 linesdepth 6pulls 6 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

otp.nx -- HOTP (RFC 4226) + TOTP (RFC 6238) one-time passwords. Powers the 6-digit codes in Google Authenticator / Authy / Yubico Authenticator / Microsoft Authenticator / 1Password. HOTP = HMAC(key, counter) -> 6-digit code (event-counter based) TOTP = HOTP(key, floor(time / period)) -- time-based variant Standard RFC profiles use HMAC-SHA-1 for compatibility. We ship HMAC-SHA-256 variants here because: - SHA-1 is deprecated for new systems (rule: don't encourage) - RFC 6238 ยง5 explicitly permits SHA-256 / SHA-512 - All major authenticator apps support SHA-256 profiles Callers interoperating with legacy SHA-1 providers need a separate hotp_sha1.nx we're not shipping. Algorithm (RFC 4226): 1. HMAC = HMAC-SHA-256(key, counter as u64 big-endian) 2. offset = HMAC[31] & 0x0F (dynamic truncation) 3. truncated = read 4 bytes BE at HMAC[offset..offset+4] 4. truncated &= 0x7FFFFFFF (clear top bit) 5. code = truncated mod 10^digits Invariants: OTP1 digits in [6, 10]; most deployments use 6. We don't enforce; caller picks. OTP2 Counter is u64 big-endian; identical on every platform. OTP3 Code is zero-padded to `digits` length on render.

dependencies 2 imports · 0 importers

syscalls.nx nx_hmac.nx otp.nx

imports: syscalls.nxnx_hmac.nx

imported by: nobody (leaf or entry point)

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

main hotp_sha256 hotp_value hmac_sha256 sys_mmap sha256_digest sys_mmap ↻ sha256_init sys_mmap ↻ sha256_k sha256_update sha256_compress_ni_blocks blk_set_byte sha256_compress sha256_final blk_set_byte ↻ sha256_compress ↻ sha256_init ↻ sha256_update ↻ sha256_final ↻ otp_render

structs

none

consts

none

functions

36func hotp_value(key: *u8, key_len: i64, counter: i64, digits: i64) -> i64
called by 1: hotp_sha256 calls 1: hmac_sha256
68func otp_render(value: i64, digits: i64, out: *u8) -> i64
called by 1: hotp_sha256
80func hotp_sha256(key: *u8, key_len: i64, counter: i64, digits: i64,
89func totp_sha256(key: *u8, key_len: i64,
calls 1: hotp_sha256
100func main() -> i64
calls 1: hotp_sha256