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 RustyShield 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.
Below are steps to use the rs_hmac
crate in your Rust projects:
Add the following line to your Cargo.toml
under the [dependencies]
section:
toml
rs_hmac = "0.1.*"
Add any hash function available on rs_shield
. In this case we will use the SHAKE128
algorithm as example:
toml
rs_shake128 = "0.1.*"
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::
asserteq!(format!("{byteresult:X}"), "C17043C47B31C5897E35E658AD9521734E5CBF") ```
For a more detailed exploration of rs_hmac
, an overview of other available cryptographic functions, and an introduction to the broader rs_shield
project, please consult the RustyShield project page on crates.io.
Potential contributors are encouraged to consult the contribution guidelines on our GitHub page.
This project is licensed under GPL-2.0-only.
Note: The references have been provided as per the best knowledge as of May 17, 2023.