pub struct Ocb { /* private fields */ }Expand description
AES-OCB (OCB3, RFC 7253) with a 128-bit tag.
Holds the AES key schedule and the precomputed L_*, L_$, and a
small cache of L_i doubling values. The cache grows on demand up
to the number of blocks seen; for typical messages a handful of
entries suffice.
Implementations§
Source§impl Ocb
impl Ocb
Sourcepub fn new(key: &[u8]) -> Option<Self>
pub fn new(key: &[u8]) -> Option<Self>
Create an AES-OCB context. key must be 16, 24, or 32 bytes
(AES-128/192/256). Returns None for an invalid key length.
Sourcepub fn encrypt(
&mut self,
nonce: &[u8],
aad: &[u8],
plaintext: &[u8],
) -> Option<Vec<u8>>
pub fn encrypt( &mut self, nonce: &[u8], aad: &[u8], plaintext: &[u8], ) -> Option<Vec<u8>>
Encrypt and authenticate. Returns ciphertext ‖ tag
(out.len() == plaintext.len() + 16).
nonce.len() must be 1..=15; returns None otherwise.
Sourcepub fn decrypt(
&mut self,
nonce: &[u8],
aad: &[u8],
input: &[u8],
) -> Option<Vec<u8>>
pub fn decrypt( &mut self, nonce: &[u8], aad: &[u8], input: &[u8], ) -> Option<Vec<u8>>
Decrypt and verify. input is ciphertext ‖ tag. Returns
Some(plaintext) only if the 16-byte tag verifies (constant-
time compare); returns None on any malformed input or tag
mismatch, and never releases plaintext on failure.
nonce.len() must be 1..=15.