Skip to main content

Module crypto_auth_hmacsha512256

Module crypto_auth_hmacsha512256 

Source
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 message using key, and places the result into mac.
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 state for HMAC-SHA-512-256 with input.
crypto_auth_hmacsha512256_verify
Verifies that mac is the correct authenticator for message using key.

Type Aliases§

HmacSha512256State
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.