Crate cmac[][src]

Generic implementation of Cipher-based Message Authentication Code (CMAC), otherwise known as OMAC1.

Usage

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

To get the authentication code:

extern crate cmac;
extern crate aes;

use aes::Aes128;
use cmac::{Cmac, Mac};

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

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

To verify the message:

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

mac.input(b"input message");

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

Re-exports

pub extern crate crypto_mac;

Structs

Cmac

Generic CMAC instance

Traits

Mac

The Mac trait defines methods for a Message Authentication algorithm.