Module dryoc::classic::crypto_auth

source ·
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::{crypto_auth, crypto_auth_keygen, crypto_auth_verify, Mac};

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::{
    crypto_auth_final, crypto_auth_init, crypto_auth_keygen, crypto_auth_update,
    crypto_auth_verify, Mac,
};

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

Functions

Type Definitions

  • Key for secret-key message authentication.
  • Message authentication code type for use with secret-key authentication.