Skip to main content

hmac_sha256

Function hmac_sha256 

Source
pub fn hmac_sha256(key: &[u8], data: &[u8]) -> Result<[u8; 32]>
Available on (crate features mac-hmac or mac-blake3) and crate feature mac-hmac only.
Expand description

Compute an HMAC-SHA256 tag over data under key.

§Errors

Returns Error::Mac if the upstream hmac crate refuses the key. In practice this never happens — HMAC accepts any key length — but the upstream API is fallible by signature, so the wrapper preserves it.

§Example

use crypt_io::mac;
let tag = mac::hmac_sha256(b"shared key", b"message")?;
assert_eq!(tag.len(), 32);