@@ -11,6 +11,7 @@ use rustls::crypto::cipher::{
1111 UnsupportedOperationError ,
1212} ;
1313use rustls:: { ConnectionTrafficSecrets , ContentType , ProtocolVersion } ;
14+ use zeroize:: Zeroizing ;
1415
1516use alloc:: vec:: Vec ;
1617use core:: ptr;
@@ -30,7 +31,7 @@ impl Tls12AeadAlgorithm for Aes128Gcm {
3031
3132 Box :: new ( WCTls12Encrypter {
3233 iv : iv_as_array. into ( ) ,
33- key : key_as_slice. to_vec ( ) ,
34+ key : Zeroizing :: new ( key_as_slice. to_vec ( ) ) ,
3435 } )
3536 }
3637
@@ -45,7 +46,7 @@ impl Tls12AeadAlgorithm for Aes128Gcm {
4546
4647 Box :: new ( WCTls12Decrypter {
4748 implicit_iv : iv_implicit_as_array,
48- key : key_as_slice. to_vec ( ) ,
49+ key : Zeroizing :: new ( key_as_slice. to_vec ( ) ) ,
4950 } )
5051 }
5152
@@ -65,8 +66,8 @@ impl Tls12AeadAlgorithm for Aes128Gcm {
6566 ) -> Result < ConnectionTrafficSecrets , UnsupportedOperationError > {
6667 let mut iv_as_vec = vec ! [ 0u8 ; GCM_NONCE_LENGTH ] ;
6768
68- iv_as_vec. copy_from_slice ( iv) ;
69- iv_as_vec. copy_from_slice ( explicit) ;
69+ iv_as_vec[ .. 4 ] . copy_from_slice ( iv) ;
70+ iv_as_vec[ 4 .. ] . copy_from_slice ( explicit) ;
7071
7172 Ok ( ConnectionTrafficSecrets :: Aes128Gcm {
7273 key,
@@ -80,12 +81,12 @@ impl Tls12AeadAlgorithm for Aes128Gcm {
8081// We separate the structs for the implementation.
8182pub struct WCTls12Encrypter {
8283 iv : Iv ,
83- key : Vec < u8 > ,
84+ key : Zeroizing < Vec < u8 > > ,
8485}
8586
8687pub struct WCTls12Decrypter {
8788 implicit_iv : [ u8 ; 4 ] ,
88- key : Vec < u8 > ,
89+ key : Zeroizing < Vec < u8 > > ,
8990}
9091
9192impl MessageEncrypter for WCTls12Encrypter {
@@ -237,14 +238,14 @@ impl MessageDecrypter for WCTls12Decrypter {
237238impl Tls13AeadAlgorithm for Aes128Gcm {
238239 fn encrypter ( & self , key : AeadKey , iv : Iv ) -> Box < dyn MessageEncrypter > {
239240 Box :: new ( WCTls13Cipher {
240- key : key. as_ref ( ) . into ( ) ,
241+ key : Zeroizing :: new ( key. as_ref ( ) . into ( ) ) ,
241242 iv,
242243 } )
243244 }
244245
245246 fn decrypter ( & self , key : AeadKey , iv : Iv ) -> Box < dyn MessageDecrypter > {
246247 Box :: new ( WCTls13Cipher {
247- key : key. as_ref ( ) . into ( ) ,
248+ key : Zeroizing :: new ( key. as_ref ( ) . into ( ) ) ,
248249 iv,
249250 } )
250251 }
@@ -263,7 +264,7 @@ impl Tls13AeadAlgorithm for Aes128Gcm {
263264}
264265
265266pub struct WCTls13Cipher {
266- key : Vec < u8 > ,
267+ key : Zeroizing < Vec < u8 > > ,
267268 iv : Iv ,
268269}
269270
0 commit comments