Module orion::hazardous::hmac[][src]

HMAC-SHA512 (Hash-based Message Authentication Code) as specified in the RFC 2104.

Parameters:

  • secret_key: The authentication key
  • data: Data to be authenticated

See RFC for more information.

Exceptions:

An exception will be thrown if:

  • Either finalize() or finalize_with_dst() is called twice in a row without calling reset() 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 the SHA functions digest size in bytes.

Example:

Generating HMAC:

use orion::hazardous::hmac;

let key = "Very insecure key, should NOT be used".as_bytes();
let msg = "Some message.";

let mut mac = hmac::init(key);
mac.update(msg.as_bytes());
mac.finalize();

Verifying HMAC:

use orion::hazardous::hmac;

let key = "Very insecure key, should NOT be used".as_bytes();
let msg = "Some message.";

let mut mac = hmac::init(key);
mac.update(msg.as_bytes());

assert!(hmac::verify(&mac.finalize(), &key, msg.as_bytes()).unwrap());

Structs

Hmac

HMAC-SHA512 (Hash-based Message Authentication Code) as specified in the RFC 2104.

Functions

init

Initialize Hmac struct with a given key.

verify

Verify a HMAC-SHA512 MAC in constant time.