chore: don't import deprecated GenericArray use the aes crate Block instead

- allow deprecated methods for now since aes 0.9 is not out yet
This commit is contained in:
Arthur Meyre
2025-10-13 12:04:03 +02:00
parent fb4033edea
commit 96d976215d

View File

@@ -1,9 +1,8 @@
use crate::generators::aes_ctr::{
AesBlockCipher, AesKey, AES_CALLS_PER_BATCH, BYTES_PER_AES_CALL, BYTES_PER_BATCH,
};
use aes::cipher::generic_array::GenericArray;
use aes::cipher::{BlockEncrypt, KeyInit};
use aes::Aes128;
use aes::{Aes128, Block};
#[derive(Clone)]
pub struct SoftwareBlockCipher {
@@ -14,7 +13,8 @@ pub struct SoftwareBlockCipher {
impl AesBlockCipher for SoftwareBlockCipher {
fn new(key: AesKey) -> SoftwareBlockCipher {
let key: [u8; BYTES_PER_AES_CALL] = key.0.to_ne_bytes();
let key = GenericArray::clone_from_slice(&key[..]);
#[allow(deprecated, reason = "aes 0.9 is not out yet and we can't update")]
let key = Block::clone_from_slice(&key[..]);
let aes = Aes128::new(&key);
SoftwareBlockCipher { aes }
}
@@ -31,7 +31,8 @@ impl AesBlockCipher for SoftwareBlockCipher {
}
fn aes_encrypt_one(message: u128, cipher: &Aes128) -> [u8; BYTES_PER_AES_CALL] {
let mut b1 = GenericArray::clone_from_slice(&message.to_ne_bytes()[..]);
#[allow(deprecated, reason = "aes 0.9 is not out yet and we can't update")]
let mut b1 = Block::clone_from_slice(&message.to_ne_bytes()[..]);
cipher.encrypt_block(&mut b1);
@@ -41,6 +42,7 @@ fn aes_encrypt_one(message: u128, cipher: &Aes128) -> [u8; BYTES_PER_AES_CALL] {
// Uses aes to encrypt many values at once. This allows a substantial speedup (around 30%)
// compared to the naive approach.
#[allow(clippy::too_many_arguments)]
#[allow(deprecated, reason = "aes 0.9 is not out yet and we can't update")]
fn aes_encrypt_many(
message_1: u128,
message_2: u128,
@@ -52,14 +54,14 @@ fn aes_encrypt_many(
message_8: u128,
cipher: &Aes128,
) -> [u8; BYTES_PER_BATCH] {
let mut b1 = GenericArray::clone_from_slice(&message_1.to_ne_bytes()[..]);
let mut b2 = GenericArray::clone_from_slice(&message_2.to_ne_bytes()[..]);
let mut b3 = GenericArray::clone_from_slice(&message_3.to_ne_bytes()[..]);
let mut b4 = GenericArray::clone_from_slice(&message_4.to_ne_bytes()[..]);
let mut b5 = GenericArray::clone_from_slice(&message_5.to_ne_bytes()[..]);
let mut b6 = GenericArray::clone_from_slice(&message_6.to_ne_bytes()[..]);
let mut b7 = GenericArray::clone_from_slice(&message_7.to_ne_bytes()[..]);
let mut b8 = GenericArray::clone_from_slice(&message_8.to_ne_bytes()[..]);
let mut b1 = Block::clone_from_slice(&message_1.to_ne_bytes()[..]);
let mut b2 = Block::clone_from_slice(&message_2.to_ne_bytes()[..]);
let mut b3 = Block::clone_from_slice(&message_3.to_ne_bytes()[..]);
let mut b4 = Block::clone_from_slice(&message_4.to_ne_bytes()[..]);
let mut b5 = Block::clone_from_slice(&message_5.to_ne_bytes()[..]);
let mut b6 = Block::clone_from_slice(&message_6.to_ne_bytes()[..]);
let mut b7 = Block::clone_from_slice(&message_7.to_ne_bytes()[..]);
let mut b8 = Block::clone_from_slice(&message_8.to_ne_bytes()[..]);
cipher.encrypt_block(&mut b1);
cipher.encrypt_block(&mut b2);
@@ -97,7 +99,7 @@ mod test {
fn test_encrypt_many_messages() {
// Checks that encrypting many plaintext at the same time gives the correct output.
let key: [u8; BYTES_PER_AES_CALL] = CIPHER_KEY.to_ne_bytes();
let aes = Aes128::new(&GenericArray::from(key));
let aes = Aes128::new(&Block::from(key));
let ciphertexts = aes_encrypt_many(
PLAINTEXT, PLAINTEXT, PLAINTEXT, PLAINTEXT, PLAINTEXT, PLAINTEXT, PLAINTEXT, PLAINTEXT,
&aes,
@@ -118,7 +120,7 @@ mod test {
#[test]
fn test_encrypt_one_message() {
let key: [u8; BYTES_PER_AES_CALL] = CIPHER_KEY.to_ne_bytes();
let aes = Aes128::new(&GenericArray::from(key));
let aes = Aes128::new(&Block::from(key));
let ciphertext = aes_encrypt_one(PLAINTEXT, &aes);
assert_eq!(u128::from_ne_bytes(ciphertext), CIPHERTEXT);
}