literate_crypto/
mac.rs

1mod hmac;
2
3pub use hmac::Hmac;
4
5/// A message authentication code algorithm is a method for computing a keyed
6/// [hash](crate::Hash).
7///
8/// A MAC algorithm takes a message and a key, and produces a fixed-size _tag_,
9/// which is essentially a hash specific to the given message and key. The tag
10/// can be used to prove that a message was encrypted with the given pre-shared
11/// key. The tag should be checked before decrypting the message to make sure
12/// that it is authentic and hasn't been tampered.
13///
14/// A message authentication code does not prevent man-in-the-middle attacks or
15/// replay attacks.
16pub trait Mac {
17    type Tag;
18
19    fn mac(&mut self, msg: &[u8], key: &[u8]) -> Self::Tag;
20}