rs_hmac

The rs_hmac crate provides an implementation of the Keyed-Hash Message Authentication Code (HMAC) that is compatible with all hash function algorithms present in the RustySSL library. HMAC is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key, used to confirm both the data integrity and the authenticity of a message.

This implementation of HMAC is compliant with the Federal Information Processing Standards (FIPS) Publication 198[^1]. The National Institute of Standards and Technology (NIST) provides the following recommendation on HMAC usage:

"HMAC is a mechanism for message authentication using cryptographic hash functions. HMAC can be used with any iterative cryptographic hash function, e.g., SHA-256, in combination with a secret shared key. The cryptographic strength of HMAC depends on the properties of the underlying hash function."

Given this recommendation, HMAC is implicated in use cases such as:

Beyond these specific use cases, HMAC could also find more broad applications in:

These points should be considered carefully, given the security requirements of your particular application.

How To Use

Below are steps to use the rs_hmac crate in your Rust projects:

  1. Add the following line to your Cargo.toml under the [dependencies] section:

    toml rs_hmac = "0.1.*"

  2. Add any hash function available on rs_ssl. In this case we will use the SHAKE128 algorithm as example:

    toml rs_shake128 = "0.1.*"

  3. Use the functions provided by the rs_hmac module in your code. Here's an example of how to create an HMAC from a string and a key:

    ```rust use rshmac::Hmac; use rsshake128::Shake128State;

    const BYTEOUTPUTLENGTH: usize = 20; let key = b"your key here"; let data = b"your string here"; let byteresult = Hmac::, BYTEOUTPUT_LENGTH>::digest(key, data);

    asserteq!(format!("{byteresult:X}"), "C17043C47B31C5897E35E658AD9521734E5CBF") ```

More Information

For a more detailed exploration of rs_hmac, an overview of other available cryptographic functions, and an introduction to the broader rs_ssl project, please consult the RustySSL project page on crates.io.

Contributions

Potential contributors are encouraged to consult the contribution guidelines on our GitHub page.

License

This project is licensed under GPL-2.0-only.

References


Note: The references have been provided as per the best knowledge as of May 17, 2023.