Expand description
§HMAC-SHA-512-256 authentication
Implements libsodium’s crypto_auth_hmacsha512256_* functions.
HMAC-SHA-512-256 is HMAC-SHA-512 with a 32-byte truncated output. This is
libsodium’s default crypto_auth construction. It authenticates a public
message with a shared secret key; it does not hide the message contents.
use dryoc::classic::crypto_auth_hmacsha512256::*;
let key = crypto_auth_hmacsha512256_keygen();
let message = b"No legacy is so rich as honesty.";
let mut mac = Mac::default();
crypto_auth_hmacsha512256(&mut mac, message, &key);
crypto_auth_hmacsha512256_verify(&mac, message, &key).expect("verify failed");
crypto_auth_hmacsha512256_verify(&mac, b"invalid", &key).expect_err("verify should fail");The incremental interface produces the same truncated HMAC-SHA-512 MAC as the one-shot interface:
use dryoc::classic::crypto_auth_hmacsha512256::*;
let key = crypto_auth_hmacsha512256_keygen();
let mut one_shot = Mac::default();
crypto_auth_hmacsha512256(
&mut one_shot,
b"Small cheer and great welcome makes a merry feast.",
&key,
);
let mut state = crypto_auth_hmacsha512256_init(&key);
crypto_auth_hmacsha512256_update(&mut state, b"Small cheer and great welcome ");
crypto_auth_hmacsha512256_update(&mut state, b"makes a merry feast.");
let mut streaming = Mac::default();
crypto_auth_hmacsha512256_final(state, &mut streaming);
assert_eq!(one_shot, streaming);Functions§
- crypto_
auth_ hmacsha512256 - Authenticates
messageusingkey, and places the result intomac. - crypto_
auth_ hmacsha512256_ final - Finalizes HMAC-SHA-512-256 and places the truncated result into
output. - crypto_
auth_ hmacsha512256_ init - Initializes the incremental interface for HMAC-SHA-512-256.
- crypto_
auth_ hmacsha512256_ keygen - Generates a random key for HMAC-SHA-512-256.
- crypto_
auth_ hmacsha512256_ update - Updates
statefor HMAC-SHA-512-256 withinput. - crypto_
auth_ hmacsha512256_ verify - Verifies that
macis the correct authenticator formessageusingkey.
Type Aliases§
- Hmac
Sha512256 State - Internal state for HMAC-SHA-512-256.
- Key
- Key for HMAC-SHA-512-256 message authentication.
- Mac
- Message authentication code type for HMAC-SHA-512-256.