Struct BinaryFF1

Source
pub struct BinaryFF1<'a, C: BlockEncrypt> { /* private fields */ }
Expand description

A struct for performing FF1 encryption in radix 2.

The block cipher must have a 16 byte block size and should be AES-128, AES-192, or AES-256.

Implementations§

Source§

impl<'a, C> BinaryFF1<'a, C>
where C: BlockEncrypt<BlockSize = U16>, C::ParBlocks: ArrayLength<GenericArray<u8, U16>>,

Source

pub fn new( cipher: &'a C, len: usize, tweak: &[u8], scratch: &'a mut [u8], ) -> Result<Self, Error>

Creates an BinaryFF1 instance for a given block cipher, input length, and tweak. The scratch buffer must be at least len + 1 bytes.

§Errors

Returns Error::ScratchTooSmall if the scratch buffer is too small.

§Examples
let mut scratch = vec![0; 128];

assert!(BinaryFF1::new(&cipher, 126, &tweak, &mut scratch).is_ok());
assert!(BinaryFF1::new(&cipher, 127, &tweak, &mut scratch).is_ok());

// Scratch buffer must be at least len + 1 bytes
assert_eq!(
    BinaryFF1::new(&cipher, 128, &tweak, &mut scratch).err(),
    Some(Error::ScratchTooSmall)
);
Source

pub fn encrypt(&mut self, x: &mut [u8]) -> Result<(), Error>

Encrypts the given plaintext.

§Errors

Returns Error::InvalidInputLength if the length of x is not the same as the input length defined in this BinaryFF1 structure.

Source

pub fn decrypt(&mut self, x: &mut [u8]) -> Result<(), Error>

Decrypts the given ciphertext.

§Errors

Returns Error::InvalidInputLength if the length of x is not the same as the input length defined in this BinaryFF1 structure.

Auto Trait Implementations§

§

impl<'a, C> Freeze for BinaryFF1<'a, C>

§

impl<'a, C> RefUnwindSafe for BinaryFF1<'a, C>

§

impl<'a, C> Send for BinaryFF1<'a, C>
where C: Sync,

§

impl<'a, C> Sync for BinaryFF1<'a, C>
where C: Sync,

§

impl<'a, C> Unpin for BinaryFF1<'a, C>

§

impl<'a, C> !UnwindSafe for BinaryFF1<'a, C>

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.