Skip to content

Commit

Permalink
Merge pull request #127 from ANSSI-FR/dependabot/cargo/ghash-0.5
Browse files Browse the repository at this point in the history
Update ghash requirement from 0.4 to 0.5
  • Loading branch information
commial committed Aug 19, 2022
2 parents 44bd5e0 + de5d8a6 commit 7280b4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion mla/Cargo.toml
Expand Up @@ -22,7 +22,7 @@ bincode = { version = "1.3", default-features = false}
# Crypto needs
# Version fixed due to avoid conflict dependencies with `aes`, `aes-ctr` and `ghash`
generic-array = { version = "0.14", default-features = false}
ghash = { version = "0.4", default-features = false}
ghash = { version = "0.5", default-features = false}
aes = { version = "0.8", default-features = false}
ctr = { version = "0.9", default-features = false}
subtle = { version = "2", default-features = false}
Expand Down
22 changes: 10 additions & 12 deletions mla/src/crypto/aesgcm.rs
Expand Up @@ -3,10 +3,7 @@ use crate::Error;
use aes::Aes256;

use generic_array::{typenum::U16, GenericArray};
use ghash::{
universal_hash::{NewUniversalHash, UniversalHash},
GHash,
};
use ghash::{universal_hash::UniversalHash, GHash};
pub use subtle::ConstantTimeEq;

use ctr::cipher::{BlockEncrypt, KeyInit, KeyIvInit, StreamCipher, StreamCipherSeek};
Expand Down Expand Up @@ -93,8 +90,9 @@ impl AesGcm256 {
self.current_block.extend_from_slice(in_block);
// `current_block` length is now BLOCK_SIZE -> update GHash and
// clear it
self.ghash
.update(GenericArray::from_slice(self.current_block.as_slice()));
self.ghash.update(&[GenericArray::clone_from_slice(
self.current_block.as_slice(),
)]);
self.current_block.clear();

// Deals with the rest of the data, now aligned on BLOCK_SIZE
Expand All @@ -107,7 +105,7 @@ impl AesGcm256 {
// Interleaved ghash update
for chunk in &mut chunks {
self.cipher.apply_keystream(chunk);
self.ghash.update(GenericArray::from_slice(chunk));
self.ghash.update(&[GenericArray::clone_from_slice(chunk)]);
}

// Encrypt and save extra encrypted bytes for further GHash computation
Expand All @@ -130,10 +128,10 @@ impl AesGcm256 {
block[..8].copy_from_slice(&self.associated_data_bits_len.to_be_bytes());
block[8..].copy_from_slice(&buffer_bits.to_be_bytes());

self.ghash.update(&block);
self.ghash.update(&[block]);

// Final update
let mut tag = self.ghash.finalize().into_bytes();
let mut tag = self.ghash.finalize();
self.cipher.seek(0);
self.cipher.apply_keystream(tag.as_mut_slice());
tag
Expand All @@ -151,7 +149,7 @@ impl AesGcm256 {

// Interleaved ghash update
for chunk in &mut chunks {
self.ghash.update(GenericArray::from_slice(chunk));
self.ghash.update(&[GenericArray::clone_from_slice(chunk)]);
self.cipher.apply_keystream(chunk);
}

Expand All @@ -167,10 +165,10 @@ impl AesGcm256 {
block[..8].copy_from_slice(&self.associated_data_bits_len.to_be_bytes());
block[8..].copy_from_slice(&buffer_bits.to_be_bytes());

self.ghash.update(&block);
self.ghash.update(&[block]);

// Final update
let mut tag = self.ghash.clone().finalize().into_bytes();
let mut tag = self.ghash.clone().finalize();
self.cipher.seek(0);
self.cipher.apply_keystream(tag.as_mut_slice());
tag
Expand Down

0 comments on commit 7280b4f

Please sign in to comment.