Module hmac

Available on crate feature dep_orion only.
Expand description

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

§Parameters:

  • secret_key: The authentication key.
  • data: Data to be authenticated.
  • expected: The expected authentication tag.

§Errors:

An error will be returned if:

§Security:

  • The secret key should always be generated using a CSPRNG. SecretKey::generate() can be used for this.
  • The minimum recommended size for a secret key is 64 bytes.

§Recommendation:

  • If you are unsure of whether to use HMAC or Poly1305, it is most often easier to just use HMAC. See also Cryptographic Right Answers.

§Example:

use orion::hazardous::mac::hmac::sha512::{HmacSha512, SecretKey};

let key = SecretKey::generate();

let mut state = HmacSha512::new(&key);
state.update(b"Some message.")?;
let tag = state.finalize()?;

assert!(HmacSha512::verify(&tag, &key, b"Some message.").is_ok());

Modules§

sha256
HMAC-SHA256 (Hash-based Message Authentication Code) as specified in the RFC 2104.
sha384
HMAC-SHA384 (Hash-based Message Authentication Code) as specified in the RFC 2104.
sha512
HMAC-SHA512 (Hash-based Message Authentication Code) as specified in the RFC 2104.