AES-GCM: DRY Iv
-> Block
conversion.
This commit is contained in:
parent
e6085e717f
commit
faf347a24c
@ -202,7 +202,7 @@ impl Key {
|
||||
|
||||
#[inline]
|
||||
pub fn encrypt_iv_xor_block(&self, iv: Iv, input: Block) -> Block {
|
||||
let encrypted_iv = self.encrypt_block(Block::from(iv.as_bytes_less_safe()));
|
||||
let encrypted_iv = self.encrypt_block(iv.into_block_less_safe());
|
||||
encrypted_iv ^ input
|
||||
}
|
||||
|
||||
@ -355,8 +355,10 @@ impl From<Counter> for Iv {
|
||||
}
|
||||
|
||||
impl Iv {
|
||||
pub(super) fn as_bytes_less_safe(&self) -> &[u8; 16] {
|
||||
self.0.as_byte_array()
|
||||
/// "Less safe" because it defeats attempts to use the type system to prevent reuse of the IV.
|
||||
#[inline]
|
||||
pub(super) fn into_block_less_safe(self) -> Block {
|
||||
Block::from(self.0.as_byte_array())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ fn finish(
|
||||
|
||||
// Finalize the tag and return it.
|
||||
gcm_ctx.pre_finish(|pre_tag| {
|
||||
let encrypted_iv = aes_key.encrypt_block(Block::from(tag_iv.as_bytes_less_safe()));
|
||||
let encrypted_iv = aes_key.encrypt_block(tag_iv.into_block_less_safe());
|
||||
let tag = pre_tag ^ encrypted_iv;
|
||||
Tag(*tag.as_ref())
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user