Ocb3

Struct Ocb3 

Source
pub struct Ocb3<Cipher, NonceSize = U12, TagSize = U16>
where NonceSize: NonceSizes, TagSize: TagSizes,
{ pub(crate) cipher: Cipher, pub(crate) nonce_size: PhantomData<NonceSize>, pub(crate) tag_size: PhantomData<TagSize>, pub(crate) ll_star: GenericArray<u8, U16>, pub(crate) ll_dollar: GenericArray<u8, U16>, pub(crate) ll: [GenericArray<u8, U16>; 32], }
Expand description

OCB3: generic over a block cipher implementation, nonce size, and tag size.

  • NonceSize: max of 15-bytes, default and recommended size of 12-bytes (96-bits). We further restrict the minimum nonce size to 6-bytes to prevent an attack described in the following paper: https://eprint.iacr.org/2023/326.pdf.
  • TagSize: non-zero, max of 16-bytes, default and recommended size of 16-bytes.

Compilation will fail if the size conditions are not satisfied:

// Invalid nonce size equal to 5 bytes
let cipher = Ocb3::<Aes128, U5>::new(&key);
// Invalid nonce size equal to 16 bytes
let cipher = Ocb3::<Aes128, U16>::new(&key);
// Invalid tag size equal to 0 bytes
let cipher = Ocb3::<Aes128, U12, U0>::new(&key);
// Invalid tag size equal to 20 bytes
let cipher = Ocb3::<Aes128, U12, U20>::new(&key);

Fields§

§cipher: Cipher§nonce_size: PhantomData<NonceSize>§tag_size: PhantomData<TagSize>§ll_star: GenericArray<u8, U16>§ll_dollar: GenericArray<u8, U16>§ll: [GenericArray<u8, U16>; 32]

Implementations§

Source§

impl<Cipher, NonceSize, TagSize> Ocb3<Cipher, NonceSize, TagSize>
where Cipher: BlockSizeUser<BlockSize = U16> + BlockEncrypt + BlockDecrypt, NonceSize: NonceSizes, TagSize: TagSizes,

Source

pub(crate) fn decrypt_in_place_return_tag( &self, nonce: &Nonce<NonceSize>, associated_data: &[u8], buffer: &mut [u8], ) -> Tag<Self>

Decrypts in place and returns expected tag.

Source

pub(crate) fn wide_encrypt( &self, nonce: &Nonce<NonceSize>, buffer: &mut [u8], ) -> (usize, GenericArray<u8, U16>, GenericArray<u8, U16>)

Encrypts plaintext in groups of two.

Adapted from https://www.cs.ucdavis.edu/~rogaway/ocb/news/code/ocb.c

Source

pub(crate) fn wide_decrypt( &self, nonce: &Nonce<NonceSize>, buffer: &mut [u8], ) -> (usize, GenericArray<u8, U16>, GenericArray<u8, U16>)

Decrypts plaintext in groups of two.

Adapted from https://www.cs.ucdavis.edu/~rogaway/ocb/news/code/ocb.c

Source§

impl<Cipher, NonceSize, TagSize> Ocb3<Cipher, NonceSize, TagSize>
where Cipher: BlockSizeUser<BlockSize = U16> + BlockEncrypt, NonceSize: NonceSizes, TagSize: TagSizes,

Source

pub(crate) fn hash(&self, associated_data: &[u8]) -> GenericArray<u8, U16>

Computes HASH function defined in https://www.rfc-editor.org/rfc/rfc7253.html#section-4.1

Source

pub(crate) fn compute_tag( &self, associated_data: &[u8], checksum_m: &mut GenericArray<u8, U16>, offset_m: &GenericArray<u8, U16>, ) -> Tag<TagSize>

Trait Implementations§

Source§

impl<Cipher, NonceSize, TagSize> AeadCore for Ocb3<Cipher, NonceSize, TagSize>
where NonceSize: NonceSizes, TagSize: TagSizes,

Source§

type NonceSize = NonceSize

The length of a nonce.
Source§

type TagSize = TagSize

The maximum length of the nonce.
Source§

type CiphertextOverhead = UTerm

The upper bound amount of additional space required to support a ciphertext vs. a plaintext.
Source§

fn generate_nonce( rng: impl CryptoRng + RngCore, ) -> GenericArray<u8, Self::NonceSize>

Generate a random nonce for this AEAD algorithm. Read more
Source§

impl<Cipher, NonceSize, TagSize> AeadInPlace for Ocb3<Cipher, NonceSize, TagSize>
where Cipher: BlockSizeUser<BlockSize = U16> + BlockEncrypt + BlockDecrypt, NonceSize: NonceSizes, TagSize: TagSizes,

Source§

fn encrypt_in_place_detached( &self, nonce: &Nonce<NonceSize>, associated_data: &[u8], buffer: &mut [u8], ) -> Result<Tag<Self>>

Encrypt the data in-place, returning the authentication tag
Source§

fn decrypt_in_place_detached( &self, nonce: &Nonce<NonceSize>, associated_data: &[u8], buffer: &mut [u8], tag: &Tag<Self>, ) -> Result<()>

Decrypt the message in-place, returning an error in the event the provided authentication tag does not match the given ciphertext (i.e. ciphertext is modified/unauthentic)
Source§

fn encrypt_in_place( &self, nonce: &GenericArray<u8, Self::NonceSize>, associated_data: &[u8], buffer: &mut dyn Buffer, ) -> Result<(), Error>

Encrypt the given buffer containing a plaintext message in-place. Read more
Source§

fn decrypt_in_place( &self, nonce: &GenericArray<u8, Self::NonceSize>, associated_data: &[u8], buffer: &mut dyn Buffer, ) -> Result<(), Error>

Decrypt the message in-place, returning an error in the event the provided authentication tag does not match the given ciphertext. Read more
Source§

impl<Cipher: Clone, NonceSize, TagSize> Clone for Ocb3<Cipher, NonceSize, TagSize>
where NonceSize: NonceSizes + Clone, TagSize: TagSizes + Clone,

Source§

fn clone(&self) -> Ocb3<Cipher, NonceSize, TagSize>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Cipher, NonceSize, TagSize> From<Cipher> for Ocb3<Cipher, NonceSize, TagSize>
where Cipher: BlockSizeUser<BlockSize = U16> + BlockEncrypt + BlockDecrypt, NonceSize: NonceSizes, TagSize: TagSizes,

Source§

fn from(cipher: Cipher) -> Self

Converts to this type from the input type.
Source§

impl<Cipher, NonceSize, TagSize> KeyInit for Ocb3<Cipher, NonceSize, TagSize>
where Cipher: BlockSizeUser<BlockSize = U16> + BlockEncrypt + KeyInit + BlockDecrypt, NonceSize: NonceSizes, TagSize: TagSizes,

Source§

fn new(key: &Key<Self>) -> Self

Create new value from fixed size key.
Source§

fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength>

Create new value from variable size key.
Source§

fn generate_key( rng: impl CryptoRng + RngCore, ) -> GenericArray<u8, Self::KeySize>

Generate random key using the provided CryptoRng.
Source§

impl<Cipher, NonceSize, TagSize> KeySizeUser for Ocb3<Cipher, NonceSize, TagSize>
where Cipher: KeySizeUser, NonceSize: NonceSizes, TagSize: TagSizes,

Source§

type KeySize = <Cipher as KeySizeUser>::KeySize

Key size in bytes.
Source§

fn key_size() -> usize

Return key size in bytes.

Auto Trait Implementations§

§

impl<Cipher, NonceSize, TagSize> Freeze for Ocb3<Cipher, NonceSize, TagSize>
where Cipher: Freeze,

§

impl<Cipher, NonceSize, TagSize> RefUnwindSafe for Ocb3<Cipher, NonceSize, TagSize>
where Cipher: RefUnwindSafe, NonceSize: RefUnwindSafe, TagSize: RefUnwindSafe,

§

impl<Cipher, NonceSize, TagSize> Send for Ocb3<Cipher, NonceSize, TagSize>
where Cipher: Send, NonceSize: Send, TagSize: Send,

§

impl<Cipher, NonceSize, TagSize> Sync for Ocb3<Cipher, NonceSize, TagSize>
where Cipher: Sync, NonceSize: Sync, TagSize: Sync,

§

impl<Cipher, NonceSize, TagSize> Unpin for Ocb3<Cipher, NonceSize, TagSize>
where Cipher: Unpin, NonceSize: Unpin, TagSize: Unpin,

§

impl<Cipher, NonceSize, TagSize> UnwindSafe for Ocb3<Cipher, NonceSize, TagSize>
where Cipher: UnwindSafe, NonceSize: UnwindSafe, TagSize: UnwindSafe,

Blanket Implementations§

Source§

impl<Alg> Aead for Alg
where Alg: AeadInPlace,

Source§

fn encrypt<'msg, 'aad>( &self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, plaintext: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>, Error>

Encrypt the given plaintext payload, and return the resulting ciphertext as a vector of bytes. Read more
Source§

fn decrypt<'msg, 'aad>( &self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, ciphertext: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>, Error>

Decrypt the given ciphertext slice, and return the resulting plaintext as a vector of bytes. Read more
Source§

impl<Alg> AeadMut for Alg
where Alg: AeadMutInPlace,

Source§

fn encrypt<'msg, 'aad>( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, plaintext: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>, Error>

Encrypt the given plaintext slice, and return the resulting ciphertext as a vector of bytes. Read more
Source§

fn decrypt<'msg, 'aad>( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, ciphertext: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>, Error>

Decrypt the given ciphertext slice, and return the resulting plaintext as a vector of bytes. Read more
Source§

impl<Alg> AeadMutInPlace for Alg
where Alg: AeadInPlace,

Source§

fn encrypt_in_place( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut impl Buffer, ) -> Result<(), Error>

Encrypt the given buffer containing a plaintext message in-place. Read more
Source§

fn encrypt_in_place_detached( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut [u8], ) -> Result<GenericArray<u8, <Alg as AeadCore>::TagSize>, Error>

Encrypt the data in-place, returning the authentication tag
Source§

fn decrypt_in_place( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut impl Buffer, ) -> Result<(), Error>

Decrypt the message in-place, returning an error in the event the provided authentication tag does not match the given ciphertext. Read more
Source§

fn decrypt_in_place_detached( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut [u8], tag: &GenericArray<u8, <Alg as AeadCore>::TagSize>, ) -> Result<(), Error>

Decrypt the data in-place, returning an error in the event the provided authentication tag does not match the given ciphertext (i.e. ciphertext is modified/unauthentic)
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.