[go: up one dir, main page]

Struct orion::hmac::Hmac[][src]

pub struct Hmac {
    pub secret_key: Vec<u8>,
    pub message: Vec<u8>,
    pub sha2: ShaVariantOption,
}

HMAC (Hash-based Message Authentication Code) as specified in the RFC 2104.

Fields

Methods

impl Hmac
[src]

HMAC (Hash-based Message Authentication Code) as specified in the RFC 2104.

Usage examples:

Generating HMAC:

use orion::hmac::Hmac;
use orion::core::util::gen_rand_key;
use orion::core::options::ShaVariantOption;

let key = gen_rand_key(16).unwrap();
let message = gen_rand_key(16).unwrap();

let hmac_sha256 = Hmac { secret_key: key, message: message, sha2: ShaVariantOption::SHA256 };

hmac_sha256.hmac_compute();

Verifying HMAC:

use orion::hmac::Hmac;
use orion::core::options::ShaVariantOption;

let key = "Some key.";
let msg = "Some message.";

let hmac_sha256 = Hmac {
    secret_key: key.as_bytes().to_vec(),
    message: msg.as_bytes().to_vec(),
    sha2: ShaVariantOption::SHA256
};
let received_hmac = Hmac {
    secret_key: key.as_bytes().to_vec(),
    message: msg.as_bytes().to_vec(),
    sha2: ShaVariantOption::SHA256
};
assert_eq!(hmac_sha256.hmac_compare(&received_hmac.hmac_compute()).unwrap(), true);

Return the inner and outer padding used for HMAC.

Returns an HMAC for a given key and message.

HMAC used for PBKDF2 which also takes both inner and outer padding as argument.

Check HMAC validity by computing one from the current struct fields and comparing this to the passed HMAC. Comparison is done in constant time and with Double-HMAC Verification.

Trait Implementations

impl Drop for Hmac
[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl Send for Hmac

impl Sync for Hmac