Crate rs_hmac

source ·
Expand description

HMAC rs_hmac - Hash-based Message Authentication Code

This HMAC implementation is a specific type of message authentication code (MAC) involving a cryptographic hash function in combination with a secret cryptographic key. It was developed by the National Institute of Standards and Technology (NIST).

The HMAC function implemented in this crate is compatible with any hash function present in the encompassing project.

HMAC is suitable for a range of cryptographic purposes, including verifying the data integrity and the authenticity of a message. It is typically used in data communications and is crucial for many protocols to ensure data hasn’t been tampered with during transmission.

Usage

The crate provides a straightforward API. Users can create a new HMAC instance, update it with input data, and finalize to get the resultant MAC.

Example

Here is an example of how to use the HMAC function with SHA3-256 in Rust:

let mut hmac = Hmac::<Sha3_256State, 32>::new(b"my secret and secure key");
hmac.write(b"hello world");
let result = hmac.finish();
assert_eq!(result, 0xE50FF3D282C9C0F9);

Use Cases

HMAC is recommended for a variety of tasks, including:

  • Ensuring data integrity and authenticity in data communications.
  • Authenticating API requests.
  • Secure password storage.

NIST recommends HMAC for ensuring data integrity and authenticity, particularly when it is crucial to verify that data has not been tampered with during communication.

Structs

  • Hmac<H: Default + HashAlgorithm, const OUTPUT_SIZE: usize> is a generic struct that provides the HMAC (Hash-based Message Authentication Code) in Rust.

Traits

  • Overloads the finish Hasher method for a version that mutates itself