Skip to main content

Module crypto_auth_hmacsha512

Module crypto_auth_hmacsha512 

Source
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§

HmacSha512State
Internal state for HMAC-SHA-512.

Functions§

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

Type Aliases§

Key
Key for HMAC-SHA-512 message authentication.
Mac
Message authentication code type for HMAC-SHA-512.