roka-totp
Zero-dependency TOTP / HOTP implementation for Rust.
Implements RFC 6238 (TOTP) and RFC 4226 (HOTP). Brings its own SHA-1, HMAC-SHA1, and Base32 — no crypto crate is pulled in, no unsafe is used.
Highlights
- Zero external crate dependencies.
stdonly. - No
unsafe. - RFC test vectors verified — SHA-1 (RFC 3174), HMAC (RFC 2202), HOTP (RFC 4226 Appendix D), TOTP (RFC 6238 Appendix B).
- Type-safe API —
Secretnewtype,Algorithmenum, builder pattern. - otpauth URI build ready for QR pairing.
Quick start
use ;
let secret = from_base32?;
let totp = builder
.issuer
.account
.build;
let code = totp.code_now; // current OTP, e.g. "847529"
let uri = totp.uri; // otpauth://totp/Acme:alice... for QR pairing
// Verify a user-entered code against the current window ± 1 step
match totp.verify
#
# let user_input = Stringnew;
# Ok::
When to use this crate
- You want minimal supply-chain risk for your authentication path.
roka-totphas zero transitive dependencies — anyone can audit the whole code path from base32 secret to 6-digit code in an afternoon. - You're targeting embedded / WASM / no-std-ish environments where pulling in RustCrypto + serde is excessive.
- You want QR generation built in — pair with
roka-qrand ship a complete 2FA stack with no other deps.
Performance
Indicative numbers on M2 (release); see BUDGETS.md:
| Operation | Time |
|---|---|
Secret::from_base32 (16 bytes) |
~84 ns |
Totp::code_at |
~900 ns |
Totp::verify (match, ±1 window) |
~1.8 µs |
Totp::uri |
~815 ns |
Regression gates live in tests/perf_gate.rs.
Roadmap
- 0.1.0 — current API surface (SHA-1 only).
- 0.2.0 —
Algorithm::Sha256/Algorithm::Sha512(otpauth URI standard). - 0.2.x —
Totp::from_uriparsing. - Later —
no_std + allocsupport.
License
Dual-licensed under Apache 2.0 or MIT, at your option.
Part of the roka project by GOLIA Inc.