pub struct Xts128<C: BlockEncrypt + BlockDecrypt + BlockCipher> { /* private fields */ }
Expand description
Xts128 block cipher. Does not implement implement BlockMode due to XTS differences detailed here.
Implementations§
source§impl<C: BlockEncrypt + BlockDecrypt + BlockCipher> Xts128<C>
impl<C: BlockEncrypt + BlockDecrypt + BlockCipher> Xts128<C>
sourcepub fn new(cipher_1: C, cipher_2: C) -> Xts128<C>
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 cipher’s are the same algorithm and the key is stored as double sized (256 bits for Aes128), and 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.
sourcepub fn encrypt_sector(&self, sector: &mut [u8], tweak: [u8; 16])
pub fn encrypt_sector(&self, sector: &mut [u8], tweak: [u8; 16])
Encrypts a single sector in place using the given tweak.
Panics
- If the block size is not 16 bytes.
- If there’s less than a single block in the sector.
sourcepub fn decrypt_sector(&self, sector: &mut [u8], tweak: [u8; 16])
pub fn decrypt_sector(&self, sector: &mut [u8], tweak: [u8; 16])
Decrypts a single sector in place using the given tweak.
Panics
- If the block size is not 16 bytes.
- If there’s less than a single block in the sector.
sourcepub fn encrypt_area(
&self,
area: &mut [u8],
sector_size: usize,
first_sector_index: u128,
get_tweak_fn: impl Fn(u128) -> [u8; 16]
)
pub fn encrypt_area( &self, area: &mut [u8], sector_size: usize, first_sector_index: u128, get_tweak_fn: impl Fn(u128) -> [u8; 16] )
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 the block size is not 16 bytes.
- If there’s less than a single block in the last sector.
sourcepub fn decrypt_area(
&self,
area: &mut [u8],
sector_size: usize,
first_sector_index: u128,
get_tweak_fn: impl Fn(u128) -> [u8; 16]
)
pub fn decrypt_area( &self, area: &mut [u8], sector_size: usize, first_sector_index: u128, get_tweak_fn: impl Fn(u128) -> [u8; 16] )
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 the block size is not 16 bytes.
- If there’s less than a single block in the last sector.