This library aims to provide implementations of HOTP, TOTP, and OCRA as specified by the RFCs.
Implemented:
Planned:
NOTE: SHA2 doesn't work. Only SHA1 works. Why? I haven't been able to
figure that out. It might be an issue in the rust-crypto
library, but I
haven't been able to spot it. Digests are used interchangeably in my code, same
as in the rust-crypto
HMAC code, so I don't know what's going on.
// htop(key, counter, digits)
// hotp_raw takes bytes as the key
assert_eq!(hotp_raw(b"\xff", 23, 6), 330795);
// hotp takes a hex string as the key
assert_eq!(hotp("ff", 23, 6), 330795);
hotp_custom(b"\xff", 23, 6, Sha1::new());
All the times below are in seconds.
// totp(key, digits, epoch, time_step)
totp("ff", 6, 0, 30); // defaults for most TOTP implementations
totp_raw(b"\xff", 6, 0, 30);
// totp_custom(key, digits, epoch, time_step, current_time, hash)
totp_custom(b"\xff", 6, 0, 30, 255, Sha1::new());
If you don't want to use rustc-serialize
directly, this library provides a
wrapper around from_hex()
. This helps with the functions that expect byte
arrays.
let seed = oath::from_hex("ff").unwrap();
totp_raw(seed.as_slice(), 6, 0, 30);