A Rust library for performing the HMAC-based One-Time Password (HOTP) and Time-based One-Time Password (TOTP) algorithms.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
.travis.yml
Cargo.toml
LICENSE.md
README.md

README.md

rust-otp

Build Status

rust-otp is a Rust library for performing the HMAC-based One-time Passsword Algorithm as per RFC 4226 and the Time-based One-time Password Algorithm as per RFC 6238. These are also the algorithms many mobile-based 2FA apps, such as Google Authenticator and Authy, use to generate 2FA codes.

Installation

Just add the library as a dependency by adding the following section to your Cargo.toml file.

[dependencies.otp]

git = "https://github.com/TimDumol/rust-otp"

Usage

// first argument is the secret, second argument is the counter
assert_eq!(make_hotp("base32secret3232".to_ascii(), 0), Some(260182));

// first argument is the secret, followed by the time step in seconds (Google
// Authenticator uses a time step of 30), and then the skew in seconds
// (often used when calculating HOTPs for a sequence of consecutive
// time intervals, to deal with potential latency and desynchronization).
assert_eq!(make_totp("base32secret3232".to_ascii(), 30, 0), Some(260182)); // true on Unix epoch

License

rust-otp is licensed under the MIT license. The full license is included in this repository in LICENSE.md.