Skip to main content

Ocb

Struct Ocb 

Source
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

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl Freeze for Ocb

§

impl RefUnwindSafe for Ocb

§

impl Send for Ocb

§

impl Sync for Ocb

§

impl Unpin for Ocb

§

impl UnsafeUnpin for Ocb

§

impl UnwindSafe for Ocb

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.