Skip to main content

AesXts

Struct AesXts 

Source
pub struct AesXts { /* private fields */ }
Expand description

AES-XTS state. Holds the two AES key schedules K1 (for the data block encryption) and K2 (for the tweak encryption).

Construction is the bottleneck — both key schedules are expanded once at new and reused for every sector.

Implementations§

Source§

impl AesXts

Source

pub fn new(key: &[u8]) -> Option<Self>

Initialise XTS with a concatenated key K = K1 || K2.

Accepts:

  • 32 bytes – XTS-AES-128 (each half is a 16-byte AES-128 key)
  • 64 bytes – XTS-AES-256 (each half is a 32-byte AES-256 key)

Returns None if the key length is invalid or if K1 == K2 (the IEEE 1619 spec mandates the two halves be distinct, since K1 == K2 collapses XTS to a degenerate variant of XEX with a tweak that’s just AES_K(i) and exposes a known-plaintext distinguishing attack).

Source

pub fn encrypt_sector(&self, tweak: &[u8; 16], data: &mut [u8])

Encrypt one sector in place.

tweak is 16 bytes (little-endian encoding of the sector sequence number; pad with zeros for sequence numbers smaller than 128 bits, which is the common case).

data may be any length >= 16 bytes (XTS is not defined for < 16 bytes — fewer than one block has nothing to “steal” from). Returns silently with the data unchanged if the length is below 16. For lengths that are multiples of 16, it is plain XEX. Otherwise the last full block and the partial tail are joined via ciphertext stealing per IEEE 1619 §5.3.2.

Source

pub fn decrypt_sector(&self, tweak: &[u8; 16], data: &mut [u8])

Decrypt one sector in place.

Inverse of Self::encrypt_sector. Same length / tweak conventions.

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, 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.