11use crate :: generators:: aes_ctr:: {
22 AesBlockCipher , AesKey , AES_CALLS_PER_BATCH , BYTES_PER_AES_CALL , BYTES_PER_BATCH ,
33} ;
4- use aes:: cipher:: generic_array:: GenericArray ;
54use aes:: cipher:: { BlockEncrypt , KeyInit } ;
6- use aes:: Aes128 ;
5+ use aes:: { Aes128 , Block } ;
76
87#[ derive( Clone ) ]
98pub struct SoftwareBlockCipher {
@@ -14,7 +13,8 @@ pub struct SoftwareBlockCipher {
1413impl AesBlockCipher for SoftwareBlockCipher {
1514 fn new ( key : AesKey ) -> SoftwareBlockCipher {
1615 let key: [ u8 ; BYTES_PER_AES_CALL ] = key. 0 . to_ne_bytes ( ) ;
17- let key = GenericArray :: clone_from_slice ( & key[ ..] ) ;
16+ #[ allow( deprecated, reason = "aes 0.9 is not out yet and we can't update" ) ]
17+ let key = Block :: clone_from_slice ( & key[ ..] ) ;
1818 let aes = Aes128 :: new ( & key) ;
1919 SoftwareBlockCipher { aes }
2020 }
@@ -31,7 +31,8 @@ impl AesBlockCipher for SoftwareBlockCipher {
3131}
3232
3333fn aes_encrypt_one ( message : u128 , cipher : & Aes128 ) -> [ u8 ; BYTES_PER_AES_CALL ] {
34- let mut b1 = GenericArray :: clone_from_slice ( & message. to_ne_bytes ( ) [ ..] ) ;
34+ #[ allow( deprecated, reason = "aes 0.9 is not out yet and we can't update" ) ]
35+ let mut b1 = Block :: clone_from_slice ( & message. to_ne_bytes ( ) [ ..] ) ;
3536
3637 cipher. encrypt_block ( & mut b1) ;
3738
@@ -41,6 +42,7 @@ fn aes_encrypt_one(message: u128, cipher: &Aes128) -> [u8; BYTES_PER_AES_CALL] {
4142// Uses aes to encrypt many values at once. This allows a substantial speedup (around 30%)
4243// compared to the naive approach.
4344#[ allow( clippy:: too_many_arguments) ]
45+ #[ allow( deprecated, reason = "aes 0.9 is not out yet and we can't update" ) ]
4446fn aes_encrypt_many (
4547 message_1 : u128 ,
4648 message_2 : u128 ,
@@ -52,14 +54,14 @@ fn aes_encrypt_many(
5254 message_8 : u128 ,
5355 cipher : & Aes128 ,
5456) -> [ u8 ; BYTES_PER_BATCH ] {
55- let mut b1 = GenericArray :: clone_from_slice ( & message_1. to_ne_bytes ( ) [ ..] ) ;
56- let mut b2 = GenericArray :: clone_from_slice ( & message_2. to_ne_bytes ( ) [ ..] ) ;
57- let mut b3 = GenericArray :: clone_from_slice ( & message_3. to_ne_bytes ( ) [ ..] ) ;
58- let mut b4 = GenericArray :: clone_from_slice ( & message_4. to_ne_bytes ( ) [ ..] ) ;
59- let mut b5 = GenericArray :: clone_from_slice ( & message_5. to_ne_bytes ( ) [ ..] ) ;
60- let mut b6 = GenericArray :: clone_from_slice ( & message_6. to_ne_bytes ( ) [ ..] ) ;
61- let mut b7 = GenericArray :: clone_from_slice ( & message_7. to_ne_bytes ( ) [ ..] ) ;
62- let mut b8 = GenericArray :: clone_from_slice ( & message_8. to_ne_bytes ( ) [ ..] ) ;
57+ let mut b1 = Block :: clone_from_slice ( & message_1. to_ne_bytes ( ) [ ..] ) ;
58+ let mut b2 = Block :: clone_from_slice ( & message_2. to_ne_bytes ( ) [ ..] ) ;
59+ let mut b3 = Block :: clone_from_slice ( & message_3. to_ne_bytes ( ) [ ..] ) ;
60+ let mut b4 = Block :: clone_from_slice ( & message_4. to_ne_bytes ( ) [ ..] ) ;
61+ let mut b5 = Block :: clone_from_slice ( & message_5. to_ne_bytes ( ) [ ..] ) ;
62+ let mut b6 = Block :: clone_from_slice ( & message_6. to_ne_bytes ( ) [ ..] ) ;
63+ let mut b7 = Block :: clone_from_slice ( & message_7. to_ne_bytes ( ) [ ..] ) ;
64+ let mut b8 = Block :: clone_from_slice ( & message_8. to_ne_bytes ( ) [ ..] ) ;
6365
6466 cipher. encrypt_block ( & mut b1) ;
6567 cipher. encrypt_block ( & mut b2) ;
@@ -97,7 +99,7 @@ mod test {
9799 fn test_encrypt_many_messages ( ) {
98100 // Checks that encrypting many plaintext at the same time gives the correct output.
99101 let key: [ u8 ; BYTES_PER_AES_CALL ] = CIPHER_KEY . to_ne_bytes ( ) ;
100- let aes = Aes128 :: new ( & GenericArray :: from ( key) ) ;
102+ let aes = Aes128 :: new ( & Block :: from ( key) ) ;
101103 let ciphertexts = aes_encrypt_many (
102104 PLAINTEXT , PLAINTEXT , PLAINTEXT , PLAINTEXT , PLAINTEXT , PLAINTEXT , PLAINTEXT , PLAINTEXT ,
103105 & aes,
@@ -118,7 +120,7 @@ mod test {
118120 #[ test]
119121 fn test_encrypt_one_message ( ) {
120122 let key: [ u8 ; BYTES_PER_AES_CALL ] = CIPHER_KEY . to_ne_bytes ( ) ;
121- let aes = Aes128 :: new ( & GenericArray :: from ( key) ) ;
123+ let aes = Aes128 :: new ( & Block :: from ( key) ) ;
122124 let ciphertext = aes_encrypt_one ( PLAINTEXT , & aes) ;
123125 assert_eq ! ( u128 :: from_ne_bytes( ciphertext) , CIPHERTEXT ) ;
124126 }
0 commit comments