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 hmac;
extern crate sha2;
use Sha256;
use ;
// Create alias for HMAC-SHA256
type HmacSha256 = ;
#
To verify the message:
# extern crate hmac;
# extern crate sha2;
# use Sha256;
# use ;
#
Block and input sizes
Usually it is assumed that block size is larger than output size, due to the generic nature of the implementation this edge case must be handled as well to remove potential panic scenario. This is done by truncating hash output to the hash block size if needed.