Module orion::hazardous::hmac [−][src]
HMAC-SHA512 (Hash-based Message Authentication Code) as specified in the RFC 2104.
Parameters:
secret_key
: The authentication keydata
: Data to be authenticated
See RFC for more information.
Exceptions:
An exception will be thrown if:
- Either
finalize()
orfinalize_with_dst()
is called twice without areset()
in between update()
is called afterfinalize()
without areset()
in between
Security:
The secret key should always be generated using a CSPRNG. The gen_rand_key
function
in util
can be used for this. The recommended length for a secret key is 64.
Example:
Generating HMAC:
use orion::hazardous::hmac; use orion::utilities::util; let mut key = [0u8; 64]; util::gen_rand_key(&mut key).unwrap(); let msg = "Some message."; let mut mac = hmac::init(&key); mac.update(msg.as_bytes()).unwrap(); mac.finalize().unwrap();
Verifying HMAC:
use orion::hazardous::hmac; use orion::utilities::util; let mut key = [0u8; 64]; util::gen_rand_key(&mut key).unwrap(); let msg = "Some message."; let mut mac = hmac::init(&key); mac.update(msg.as_bytes()).unwrap(); assert!(hmac::verify(&mac.finalize().unwrap(), &key, msg.as_bytes()).unwrap());
Structs
Hmac |
HMAC-SHA512 (Hash-based Message Authentication Code) as specified in the RFC 2104. |
Functions
init |
Initialize |
verify |
Verify a HMAC-SHA512 MAC in constant time. |