retail-mac 0.1.0-pre.1

Implementation of Retail Message Authentication Code (Retail MAC)
Documentation

RustCrypto: Retail MAC

crate Docs Build Status Apache2/MIT licensed Rust Version Project Chat

Pure Rust implementation of the Retail Message Authentication Code, also known as ISO/IEC 9797-1 MAC algorithm 3.

WARNING! The algorithm has known weaknesses in case of variable-length messages. See the Wikipedia article for CBC-MAC for more information.

Examples

use retail_mac::{digest::KeyInit, RetailMac, Mac};
use des::Des;
use hex_literal::hex;

type RetailMacDes = RetailMac<Des>;

// test from ISO/IEC 9797-1:2011 section B.4
// K and K' are concatenated:
let key = hex!("0123456789ABCDEFFEDCBA9876543210");

let mut mac = RetailMacDes::new_from_slice(&key).unwrap();
mac.update(b"Now is the time for all ");
let correct = hex!("A1C72E74EA3FA9B6");
mac.verify_slice(&correct).unwrap();

let mut mac2 = RetailMacDes::new_from_slice(&key).unwrap();
mac2.update(b"Now is the time for it");
let correct2 = hex!("2E2B1428CC78254F");
mac2.verify_slice(&correct2).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.