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::util::gen_rand_key;
use orion::options::ShaVariantOption;

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

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

hmac_sha256.hmac_compute();

Verifying HMAC:

use orion::hmac::Hmac;
use orion::util::gen_rand_key;
use orion::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()), true);

[src]

Returns an HMAC for a given key and message.

[src]

Check HMAC validity by computing one from the current struct fields and comparing this to the passed HMAC.

Trait Implementations

impl Drop for Hmac
[src]

[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl Send for Hmac

impl Sync for Hmac