Expand description
§HMAC-SHA-256 authentication
Implements libsodium’s crypto_auth_hmacsha256_* functions.
HMAC-SHA-256 authenticates a message with a shared secret key and writes a 32-byte tag. Verification recomputes the tag and compares it in constant time. The message is not encrypted, and the same key must be available to both the sender and verifier.
use dryoc::classic::crypto_auth_hmacsha256::*;
let key = crypto_auth_hmacsha256_keygen();
let message = b"What's past is prologue.";
let mut mac = Mac::default();
crypto_auth_hmacsha256(&mut mac, message, &key);
crypto_auth_hmacsha256_verify(&mac, message, &key).expect("verify failed");
crypto_auth_hmacsha256_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_hmacsha256::*;
let key = crypto_auth_hmacsha256_keygen();
let mut one_shot = Mac::default();
crypto_auth_hmacsha256(&mut one_shot, b"Parting is such sweet sorrow.", &key);
let mut state = crypto_auth_hmacsha256_init(&key);
crypto_auth_hmacsha256_update(&mut state, b"Parting is such ");
crypto_auth_hmacsha256_update(&mut state, b"sweet sorrow.");
let mut streaming = Mac::default();
crypto_auth_hmacsha256_final(state, &mut streaming);
assert_eq!(one_shot, streaming);Structs§
- Hmac
Sha256 State - Internal state for HMAC-SHA-256.
Functions§
- crypto_
auth_ hmacsha256 - Authenticates
messageusingkey, and places the result intomac. - crypto_
auth_ hmacsha256_ final - Finalizes HMAC-SHA-256 and places the result into
output. - crypto_
auth_ hmacsha256_ init - Initializes the incremental interface for HMAC-SHA-256.
- crypto_
auth_ hmacsha256_ keygen - Generates a random key for HMAC-SHA-256.
- crypto_
auth_ hmacsha256_ update - Updates
statefor HMAC-SHA-256 withinput. - crypto_
auth_ hmacsha256_ verify - Verifies that
macis the correct authenticator formessageusingkey.