Skip to main content

Xts128

Struct Xts128 

Source
pub struct Xts128<C> { /* private fields */ }
Expand description

Xts128 block cipher. Does not implement implement BlockMode due to XTS differences detailed here.

Implementations§

Source§

impl<C> Xts128<C>
where C: BlockSizeUser<BlockSize = U16>,

Source

pub fn new(cipher_1: C, cipher_2: C) -> Xts128<C>

Creates a new Xts128 using two cipher instances: the first one’s used to encrypt the blocks and the second one to compute the tweak at the start of each sector.

Usually both ciphers are the same algorithm, the key is stored as double sized (256 bits for Aes128). When using, the key is split in half, the first half used for cipher_1 and the other for cipher_2.

If you require support for different cipher types, or block sizes different than 16 bytes, open an issue.

Source§

impl<C> Xts128<C>
where C: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt,

Source

pub fn encrypt_sector(&self, sector: &mut [u8], tweak: Array<u8, U16>)

Encrypts a single sector in place using the given tweak.

§Panics
  • If there’s less than a single block in the sector.
Source

pub fn encrypt_area( &self, area: &mut [u8], sector_size: usize, first_sector_index: u128, get_tweak_fn: impl Fn(u128) -> Array<u8, U16>, )

Encrypts a whole area in place, usually consisting of multiple sectors.

The tweak is computed at the start of every sector using get_tweak_fn(sector_index). get_tweak_fn is usually get_tweak_default.

§Panics
  • If there’s less than a single block in the last sector.
Source§

impl<C> Xts128<C>

Source

pub fn decrypt_sector(&self, sector: &mut [u8], tweak: Array<u8, U16>)

Decrypts a single sector in place using the given tweak.

§Panics
  • If there’s less than a single block in the sector.
Source

pub fn decrypt_area( &self, area: &mut [u8], sector_size: usize, first_sector_index: u128, get_tweak_fn: impl Fn(u128) -> Array<u8, U16>, )

Decrypts a whole area in place, usually consisting of multiple sectors.

The tweak is computed at the start of every sector using get_tweak_fn(sector_index). get_tweak_fn is usually get_tweak_default.

§Panics
  • If there’s less than a single block in the last sector.

Auto Trait Implementations§

§

impl<C> Freeze for Xts128<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for Xts128<C>
where C: RefUnwindSafe,

§

impl<C> Send for Xts128<C>
where C: Send,

§

impl<C> Sync for Xts128<C>
where C: Sync,

§

impl<C> Unpin for Xts128<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for Xts128<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for Xts128<C>
where C: UnwindSafe,

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.