[][src]Crate pmac

Generic implementation of Parallelizable Message Authentication Code (PMAC), otherwise known as OMAC1.

Usage

We will use AES-128 block cipher from aes crate.

To get the authentication code:

use aes::Aes128;
use pmac::{Pmac, Mac, NewMac};

// Create `Mac` trait implementation, namely PMAC-AES128
let mut mac = Pmac::<Aes128>::new_varkey(b"very secret key.").unwrap();
mac.update(b"input message");

// `result` has type `Output` which is a thin wrapper around array of
// bytes for providing constant time equality check
let result = mac.finalize();
// To get underlying array use `into_bytes` method, but be careful, since
// incorrect use of the tag value may permit timing attacks which defeat
// the security provided by the `Output` wrapper
let tag_bytes = result.into_bytes();

To verify the message:

let mut mac = Pmac::<Aes128>::new_varkey(b"very secret key.").unwrap();

mac.update(b"input message");

// `verify` will return `Ok(())` if tag is correct, `Err(MacError)` otherwise
mac.verify(&tag_bytes).unwrap();

Re-exports

pub use crypto_mac;

Structs

Pmac

Generic PMAC instance

Traits

FromBlockCipher

Trait for MAC functions which can be created from block cipher.

Mac

The Mac trait defines methods for a Message Authentication algorithm.

NewMac

Instantiate a Mac algorithm.