Expand description
§Secret-key authentication
Implements secret-key authentication using HMAC-SHA512-256, compatible
with libsodium’s crypto_auth_* functions.
§Classic API single-part example
use dryoc::classic::crypto_auth::{Mac, crypto_auth, crypto_auth_keygen, crypto_auth_verify};
let key = crypto_auth_keygen();
let mut mac = Mac::default();
crypto_auth(&mut mac, b"Data to authenticate", &key);
// This should be valid
crypto_auth_verify(&mac, b"Data to authenticate", &key).expect("failed to authenticate");
// This should not be valid
crypto_auth_verify(&mac, b"Invalid data", &key).expect_err("should not authenticate");§Classic API multi-part example
use dryoc::classic::crypto_auth::{
Mac, crypto_auth_final, crypto_auth_init, crypto_auth_keygen, crypto_auth_update,
crypto_auth_verify,
};
let key = crypto_auth_keygen();
let mut mac = Mac::default();
let mut state = crypto_auth_init(&key);
crypto_auth_update(&mut state, b"Multi-part");
crypto_auth_update(&mut state, b"data");
crypto_auth_final(state, &mut mac);
// This should be valid
crypto_auth_verify(&mac, b"Multi-partdata", &key).expect("failed to authenticate");
// This should not be valid
crypto_auth_verify(&mac, b"Invalid data", &key).expect_err("should not authenticate");Structs§
- Auth
State - Internal state for
crypto_auth.
Functions§
- crypto_
auth - Authenticates
messageusingkey, and places the result intomac. - crypto_
auth_ final - Finalizes the message authentication code for
state, and places the result intooutput. - crypto_
auth_ init - Initialize the incremental interface for HMAC-SHA512-256 secret-key.
- crypto_
auth_ keygen - Generates a random key using
copy_randombytes, suitable for use withcrypto_auth_initandcrypto_auth. - crypto_
auth_ update - Updates
statefor the secret-key authentication function, based oninput. - crypto_
auth_ verify - Verifies that
macis the correct authenticator formessageusingkey. ReturnsOk(())if the message authentication code is valid.