pmac

Crates.iopmac
lib.rspmac
version0.8.0-rc.1
created_at2017-07-22 19:27:57.281732+00
updated_at2025-09-03 02:29:06.136058+00
descriptionGeneric implementation of Parallelizable Message Authentication Code
homepage
repositoryhttps://github.com/RustCrypto/MACs
max_upload_size
id24553
size35,588
MACs (github:rustcrypto:macs)

documentation

https://docs.rs/pmac

README

RustCrypto: PMAC

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

Generic implementation of Parallelizable Message Authentication Code (PMAC).

Examples

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

To get authentication code:

use aes::Aes128;
use pmac::{digest::KeyInit, Pmac, Mac};

// Create `Mac` trait implementation, namely PMAC-AES128
let mut mac = Pmac::<Aes128>::new_from_slice(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:

# use aes::Aes128;
# use pmac::{digest::KeyInit, Pmac, Mac};
let mut mac = Pmac::<Aes128>::new_from_slice(b"very secret key.").unwrap();

mac.update(b"input message");

# let tag_bytes = mac.clone().finalize().into_bytes();
// `verify` will return `Ok(())` if tag is correct, `Err(MacError)` otherwise
mac.verify(&tag_bytes).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.

Commit count: 238

cargo fmt