hmac-0.1.1 has been yanked.
Generic implementation of Hash-based Message Authentication Code (HMAC).
To use it you'll need a cryptographic hash function implementation from
RustCrypto project. You can either import specific crate (e.g. sha2
), or
meta-crate crypto-hashes
which reexport all related crates.
Usage
Let us demonstrate how to use HMAC using SHA256 as an example.
To get the authentication code:
extern crate sha2;
extern crate hmac;
use ;
use Sha256;
// Create `Mac` trait implementation, namely HMAC-SHA256
let mac = new;
mac.input;
// `result` has type `MacResult` which is a thin wrapper around array of
// bytes for providing constant time equality check
let result = mac.result;
// To get &[u8] use `code` method, but be carefull, since incorrect use
// of the code value may permit timing attacks which defeat the security
// provided by the `MacResult`.
let code_bytes = resul.code;
To verify the message:
let mac = new;
mac.input;
let is_code_correct = mac.verify;