Expand description
§HMAC-SHA-512 authentication
Implements libsodium’s crypto_auth_hmacsha512_* functions.
HMAC-SHA-512 authenticates a message with a shared secret key and writes a 64-byte tag. Use it when a protocol specifically requires HMAC-SHA-512. Verification fails if either the message or the tag has been changed.
use dryoc::classic::crypto_auth_hmacsha512::*;
let key = crypto_auth_hmacsha512_keygen();
let message = b"One touch of nature makes the whole world kin.";
let mut mac: Mac = [0u8; 64];
crypto_auth_hmacsha512(&mut mac, message, &key);
crypto_auth_hmacsha512_verify(&mac, message, &key).expect("verify failed");
crypto_auth_hmacsha512_verify(&mac, b"invalid", &key).expect_err("verify should fail");The incremental interface produces the same MAC as the one-shot interface:
use dryoc::classic::crypto_auth_hmacsha512::*;
let key = crypto_auth_hmacsha512_keygen();
let mut one_shot: Mac = [0u8; 64];
crypto_auth_hmacsha512(
&mut one_shot,
b"How far that little candle throws his beams!",
&key,
);
let mut state = crypto_auth_hmacsha512_init(&key);
crypto_auth_hmacsha512_update(&mut state, b"How far that little candle ");
crypto_auth_hmacsha512_update(&mut state, b"throws his beams!");
let mut streaming: Mac = [0u8; 64];
crypto_auth_hmacsha512_final(state, &mut streaming);
assert_eq!(one_shot, streaming);Structs§
- Hmac
Sha512 State - Internal state for HMAC-SHA-512.
Functions§
- crypto_
auth_ hmacsha512 - Authenticates
messageusingkey, and places the result intomac. - crypto_
auth_ hmacsha512_ final - Finalizes HMAC-SHA-512 and places the result into
output. - crypto_
auth_ hmacsha512_ init - Initializes the incremental interface for HMAC-SHA-512.
- crypto_
auth_ hmacsha512_ keygen - Generates a random key for HMAC-SHA-512.
- crypto_
auth_ hmacsha512_ update - Updates
statefor HMAC-SHA-512 withinput. - crypto_
auth_ hmacsha512_ verify - Verifies that
macis the correct authenticator formessageusingkey.