Skip to main content

SymBlockCipherModeEncryptionInstance

Struct SymBlockCipherModeEncryptionInstance 

Source
pub struct SymBlockCipherModeEncryptionInstance { /* private fields */ }

Implementations§

Source§

impl SymBlockCipherModeEncryptionInstance

Source

pub fn new( mode_id: TpmiAlgCipherMode, alg_id: &SymBlockCipherAlg, key: &[u8], ) -> Result<Self, CryptoError>

Instantiate a SymBlockCipherModeEncryptionInstance from a triplet of block cipher mode identifier, symmetric block cipher algorithm identifier and a raw key byte slice.

§Arguments:
Source

pub fn try_clone(&self) -> Result<Self, CryptoError>

Try to clone a SymBlockModeCipherEncryptionInstance.

Source

pub fn block_cipher_block_len(&self) -> usize

Obtain the instance’s associated block cipher algorithm’s block length.

Equivalent to SymBlockCipherAlg::block_len().

Source

pub fn iv_len(&self) -> usize

Determine the IV length for use with SymBlockCipherModeEncryptionInstance.

Equivalent to SymBlockCipherAlg::iv_len_for_mode().

Source

pub fn encrypt<'a, 'b, DI: CryptoWalkableIoSlicesMutIter<'a>, SI: CryptoWalkableIoSlicesIter<'b>>( &self, iv: &[u8], dst: DI, src: SI, iv_out: Option<&mut [u8]>, ) -> Result<(), CryptoError>

Encrypt data from buffer to buffer.

The source and destination buffers must be equal in length or an error will get returned. Depending on the block cipher mode, their lengths must perhaps be aligned to the block cipher block length, an error will get returned otherwise. No padding will get inserted.

Processing a request does not alter self’s state – in particular the IV must get provided for each new requst anew.

§Arguments:
  • iv - The IV to use. Its length must match the expected IV length.
  • dst - The destination buffers to write the encrypted message to.
  • src - The source buffers holding the cleartext message to encrypt.
  • iv_out - Optional buffer receiving the final IV as ouput from the block cipher mode. Attempting to retrieve the final IV when the to be encrypted data’s length is not an integral multiple of the block cipher block size is ill-defined and considered an error.
Source

pub fn encrypt_in_place<'a, 'b, DI: CryptoPeekableIoSlicesMutIter<'a>>( &self, iv: &[u8], dst: DI, iv_out: Option<&mut [u8]>, ) -> Result<(), CryptoError>

Encrypt data in place.

Depending on the block cipher mode, the source/destination buffer’s length must perhaps be aligned to the block cipher block length, an error will get returned otherwise. No padding will get inserted.

Processing a request does not alter self’s state – in particular the IV must get provided for each new requst anew.

Unlike it’s the case with encrypt(), the source/destination buffer’s generic DI type is not dyn compatible. The compiler will emit a separate instance for each individual DI encrypt_in_place() gets invoked with. Be vigilant of template bloat, prefer encrypt() if feasible and try to not use too exotic types for DI here otherwise.

§Arguments:
  • iv - The IV to use. Its length must match the expected IV length.
  • dst - The source/destination buffers initially holding the cleartext message and receiving the encrypted result.
  • iv_out - Optional buffer receiving the final IV as ouput from the block cipher mode. Attempting to retrieve the final IV when the to be encrypted data’s length is not an integral multiple of the block cipher block size is ill-defined and considered an error.

Trait Implementations§

Source§

impl From<&SymBlockCipherModeEncryptionInstance> for SymBlockCipherAlg

Source§

fn from(value: &SymBlockCipherModeEncryptionInstance) -> Self

Converts to this type from the input type.
Source§

impl From<&SymBlockCipherModeEncryptionInstance> for TpmiAlgCipherMode

Source§

fn from(value: &SymBlockCipherModeEncryptionInstance) -> Self

Converts to this type from the input type.
Source§

impl ZeroizeOnDrop for SymBlockCipherModeEncryptionInstance

Available on crate feature zeroize only.

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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.