Function rusthotp::hotp
[−]
[src]
pub fn hotp(
desired_code_length: usize,
key: &[u8],
counter: &[u8]
) -> HotpOutput
This implementation of HMAC-Based One Time Passwords proceeds in three stages, as per RFC 4226:
- Generate an HMAC-SHA-1 value given a shared secret
key
and a moving factorcounter
that should change on every use - Extraction of a 4-byte value from the SHA-1 digest
- Deriving a final HOTP value between 0 and
10{
desired_code_length
}-1 from the 4-byte value extracted in the last step.
Note that it is the responsibility of the caller to:
- Fulfill the precondition that
counter
is an 8-byte value - Increment the counter accordingly per invocation
Examples
To generate an HOTP value between 0 and 108 - 1, given the shared
secret ASCII key "Hello world!"
and current counter 0
:
rusthotp::hotp(8, "Hello world!".as_bytes(), &[0; 8]);