Skip to content

Commit

Permalink
Expose hmac_sha1 function
Browse files Browse the repository at this point in the history
  • Loading branch information
inikulin committed Jun 28, 2024
1 parent b7baacc commit d8e821b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions boring/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ pub fn hmac_sha512(key: &[u8], data: &[u8]) -> Result<[u8; 64], ErrorStack> {
hmac(MessageDigest::sha512(), key, data)
}

/// Computes HMAC with SHA-1 digest.
pub fn hmac_sha1(key: &[u8], data: &[u8]) -> Result<[u8; 20], ErrorStack> {
hmac(MessageDigest::sha1(), key, data)
}

fn hmac<const N: usize>(
digest: MessageDigest,
key: &[u8],
Expand Down Expand Up @@ -437,6 +442,19 @@ mod tests {
);
}

#[test]
fn test_hmac_sha1() {
let hmac = hmac_sha1(b"That's a secret".as_slice(), b"Hello world!".as_slice()).unwrap();

assert_eq!(
hmac,
[
0xe1, 0x06, 0x76, 0x46, 0x3b, 0x82, 0x67, 0xa1, 0xae, 0xe5, 0x1c, 0xfa, 0xee, 0x36,
0x1d, 0x4b, 0xd4, 0x41, 0x6e, 0x37
]
);
}

#[test]
fn test_md5() {
for test in MD5_TESTS.iter() {
Expand Down

0 comments on commit d8e821b

Please sign in to comment.