Skip to content

Commit 93a41da

Browse files
committed
quic/crypto: remove use of GenericArray
Its not needed, and gets rid of the deprecation warnings.
1 parent 7620812 commit 93a41da

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

rust/src/quic/crypto.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
* 02110-1301, USA.
1616
*/
1717

18-
// For now suppress deprecation warning from GenericArray.
19-
#![allow(deprecated)]
20-
21-
use aes::cipher::generic_array::GenericArray;
2218
use aes::cipher::{BlockEncrypt, KeyInit};
2319
use aes::Aes128;
2420
use aes_gcm::aead::AeadInPlace;
2521
use aes_gcm::Aes128Gcm;
2622
use hkdf::Hkdf;
2723
use sha2::Sha256;
24+
use std::convert::TryInto;
2825

2926
pub const AES128_KEY_LEN: usize = 16;
3027
pub const AES128_TAG_LEN: usize = 16;
@@ -42,14 +39,15 @@ impl HeaderProtectionKey {
4239
b"quic hp" as &[u8]
4340
};
4441
hkdf_expand_label(&hk, quichp, &mut secret, AES128_KEY_LEN as u16);
45-
return Self(Aes128::new(GenericArray::from_slice(&secret)));
42+
return Self(Aes128::new((&secret).into()));
4643
}
4744

4845
pub fn decrypt_in_place(
4946
&self, sample: &[u8], first: &mut u8, packet_number: &mut [u8],
5047
) -> Result<(), ()> {
51-
let mut mask = GenericArray::clone_from_slice(sample);
52-
self.0.encrypt_block(&mut mask);
48+
debug_validate_bug_on!(sample.len() != AES128_KEY_LEN);
49+
let mut mask: [u8; AES128_KEY_LEN] = sample[..AES128_KEY_LEN].try_into().map_err(|_| ())?;
50+
self.0.encrypt_block((&mut mask).into());
5351

5452
let (first_mask, pn_mask) = mask.split_first().unwrap();
5553

@@ -85,7 +83,7 @@ impl PacketKey {
8583
b"quic key" as &[u8]
8684
};
8785
hkdf_expand_label(&hk, quickey, &mut secret, AES128_KEY_LEN as u16);
88-
let key = Aes128Gcm::new(GenericArray::from_slice(&secret));
86+
let key = Aes128Gcm::new((&secret).into());
8987

9088
let mut r = PacketKey {
9189
key,
@@ -113,9 +111,8 @@ impl PacketKey {
113111
}
114112
let tag_pos = payload.len() - AES128_TAG_LEN;
115113
let (buffer, tag) = payload.split_at_mut(tag_pos);
116-
let taga = GenericArray::from_slice(tag);
117114
self.key
118-
.decrypt_in_place_detached(GenericArray::from_slice(&nonce), header, buffer, taga)
115+
.decrypt_in_place_detached((&nonce).into(), header, buffer, (&*tag).into())
119116
.map_err(|_| ())?;
120117
Ok(&payload[..tag_pos])
121118
}

0 commit comments

Comments
 (0)