@@ -17,7 +17,7 @@ use ghash::GHash;
1717use ghash:: Key ;
1818use kernel:: hil:: symmetric_encryption;
1919use kernel:: hil:: symmetric_encryption:: {
20- AESCtr , AES , AES128 , AES128_KEY_SIZE , AESCBC , AESCCM , AESECB , AES_BLOCK_SIZE ,
20+ AESCtr , AESKey , AES , AES128 , AES128_KEY_SIZE , AESCBC , AESCCM , AESECB , AES_BLOCK_SIZE ,
2121} ;
2222use kernel:: utilities:: cells:: { OptionalCell , TakeCell } ;
2323use kernel:: ErrorCode ;
@@ -76,7 +76,7 @@ impl<'a, A: AES<'a, AES128> + AESCtr + AESCBC + AESECB + AESCCM<'a, AES128>> Aes
7676 fn start_ctr_encrypt ( & self ) -> Result < ( ) , ErrorCode > {
7777 self . aes . set_mode_aesctr ( self . encrypting . get ( ) ) ?;
7878
79- let res = AES :: set_key ( self . aes , & self . key . get ( ) ) ;
79+ let res = AES :: set_key ( self . aes , AESKey :: PlainText ( & self . key . get ( ) ) ) ;
8080 if res != Ok ( ( ) ) {
8181 return res;
8282 }
@@ -120,7 +120,7 @@ impl<'a, A: AES<'a, AES128> + AESCtr + AESCBC + AESECB + AESCCM<'a, AES128>> Aes
120120 self . encrypting . set ( encrypting) ;
121121
122122 self . aes . set_mode_aesctr ( self . encrypting . get ( ) ) . unwrap ( ) ;
123- AES :: set_key ( self . aes , & self . key . get ( ) ) . unwrap ( ) ;
123+ AES :: set_key ( self . aes , AESKey :: PlainText ( & self . key . get ( ) ) ) . unwrap ( ) ;
124124 self . aes . set_iv ( & [ 0 ; AES_BLOCK_SIZE ] ) . unwrap ( ) ;
125125
126126 self . aes . start_message ( ) ;
@@ -162,7 +162,11 @@ impl<'a, A: AES<'a, AES128> + AESCtr + AESCBC + AESECB + AESCCM<'a, AES128>>
162162 self . gcm_client . set ( client) ;
163163 }
164164
165- fn set_key ( & self , key : & [ u8 ] ) -> Result < ( ) , ErrorCode > {
165+ fn set_key ( & self , key : AESKey ) -> Result < ( ) , ErrorCode > {
166+ let key = match key {
167+ AESKey :: PlainText ( key) => key,
168+ _ => return Err ( ErrorCode :: INVAL ) ,
169+ } ;
166170 if key. len ( ) < AES128_KEY_SIZE {
167171 Err ( ErrorCode :: INVAL )
168172 } else {
@@ -230,7 +234,7 @@ impl<'a, A: AES<'a, AES128> + AESCtr + AESCBC + AESECB + AESCCM<'a, AES128>>
230234 self . client . set ( client) ;
231235 }
232236
233- fn set_key ( & self , key : & [ u8 ] ) -> Result < ( ) , ErrorCode > {
237+ fn set_key ( & self , key : AESKey ) -> Result < ( ) , ErrorCode > {
234238 AES :: set_key ( self . aes , key)
235239 }
236240
@@ -266,7 +270,7 @@ impl<
266270 self . ccm_client . set ( client) ;
267271 }
268272
269- fn set_key ( & self , key : & [ u8 ] ) -> Result < ( ) , ErrorCode > {
273+ fn set_key ( & self , key : AESKey ) -> Result < ( ) , ErrorCode > {
270274 AESCCM :: set_key ( self . aes , key)
271275 }
272276
0 commit comments