| Crates.io | totpyx |
| lib.rs | totpyx |
| version | 1.0.0 |
| created_at | 2025-12-24 16:50:02.126194+00 |
| updated_at | 2025-12-24 16:50:02.126194+00 |
| description | Minimal, dependency-free RFC 6238 TOTP implementation |
| homepage | https://github.com/rccyx/totpyx |
| repository | https://github.com/rccyx/totpyx |
| max_upload_size | |
| id | 2003587 |
| size | 45,004 |
A tiny, dependency-free TOTP generator (RFC 6238) with a strict RFC 4648 Base32 decoder.
This project exists for a single purpose: to provide a fully auditable TOTP implementation with no third-party crypto dependencies, no hidden behavior, and a deliberately minimal attack and trust surface.
A–Z2–7), case-insensitive, optional = paddingThis crate computes TOTP codes. Secret storage, lifecycle, and protection are intentionally left to the caller.
As a CLI:
cargo install totpyx
As a library:
cargo add totpyx
totpyx <base32-secret> \
[--algo sha1|sha256|sha512] \
[--digits 6|7|8] \
[--period <seconds>] \
[--t0 <unix>] \
[--time <unix>]
Generate a standard 6-digit TOTP (SHA-1, 30s period, T0=0):
totpyx JBSWY3DPEHPK3PXP
Generate SHA-256 with 8 digits:
totpyx JBSWY3DPEHPK3PXP --algo sha256 --digits 8
Generate with a custom period:
totpyx JBSWY3DPEHPK3PXP --period 60
Reproduce a code for a specific Unix timestamp (debugging drift, server-side validation):
totpyx JBSWY3DPEHPK3PXP --time 1710000000
= at the end is allowed but not required.Minimal example:
use totpyx::crypto::HashAlgo;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let secret = totpyx::base32::decode("JBSWY3DPEHPK3PXP")?;
let unix_time = 1_710_000_000u64;
let code = totpyx::totp::generate_totp(
&secret,
unix_time,
30, // period (X)
0, // T0
6, // digits
HashAlgo::Sha1,
)?;
println!("{code}");
Ok(())
}
T = (unix_time - T0) / X (RFC 6238 §4).This create implements the relevant standards directly, without abstraction or reinterpretation. The primary references are:
RFC 6238 — Time-Based One-Time Password Algorithm (TOTP) https://www.rfc-editor.org/rfc/rfc6238
RFC 4226 — HMAC-Based One-Time Password Algorithm (HOTP) https://www.rfc-editor.org/rfc/rfc4226
RFC 2104 — HMAC: Keyed-Hashing for Message Authentication https://www.rfc-editor.org/rfc/rfc2104
FIPS 180-4 — Secure Hash Standard (SHS) https://csrc.nist.gov/publications/detail/fips/180/4/final
RFC 4648 — The Base16, Base32, and Base64 Data Encodings https://www.rfc-editor.org/rfc/rfc4648
All test vectors included in this repository are taken directly from the referenced specifications.
Apache-2.0 © @rccyx