RustCrypto: CMAC
Generic implementation of Cipher-based Message Authentication Code (CMAC), otherwise known as OMAC1.
Examples
We will use AES-128 block cipher from the aes crate.
To get the authentication code:
use Aes128;
use ;
// Create `Mac` trait implementation, namely CMAC-AES128
let mut mac = new_from_slice.unwrap;
mac.update;
// `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 the `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:
use Aes128;
use ;
let mut mac = new_from_slice.unwrap;
mac.update;
# let tag_bytes = mac.clone.finalize.into_bytes;
// `verify` will return `Ok(())` if tag is correct, `Err(MacError)` otherwise
mac.verify.unwrap;
License
Licensed under either of:
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.