tor_llcrypto/
traits.rs

1//! Cryptographic traits for general use throughout Arti.
2
3use subtle::Choice;
4
5/// A simple trait to describe a keyed message authentication code.
6///
7/// Unlike RustCrypto's
8/// [`crypto_mac::Mac`](https://docs.rs/crypto-mac/latest/crypto_mac/trait.Mac.html),
9/// this trait does not support incremental processing.
10pub trait ShortMac<const MAC_LEN: usize> {
11    /// Calculate a message authentication code for `input` using this key.
12    fn mac(&self, input: &[u8]) -> crate::util::ct::CtByteArray<MAC_LEN>;
13
14    /// Check whether `mac` is a valid message authentication code for `input`
15    /// using this key.
16    fn validate(&self, input: &[u8], mac: &[u8; MAC_LEN]) -> Choice;
17}