@@ -107,10 +107,10 @@ static int Tropic01_GenerateKeyED25519(byte* pubkey, int keySlot, word32 sz)
107107#endif
108108
109109/*
110- * Retrive the AES key from the secure R memory of TROPIC01
110+ * Retrieve the AES key from the secure R memory of TROPIC01
111111 */
112112
113- static int Tropic01_GetKeyAES (Aes * aes , int keySlot , word32 keySz )
113+ static int Tropic01_GetKeyAES (byte * aesKey , int keySlot , word32 keySz )
114114{
115115
116116 lt_ret_t rett ;
@@ -119,7 +119,7 @@ static int Tropic01_GetKeyAES(Aes* aes, int keySlot, word32 keySz)
119119 keySlot
120120 );
121121
122- if (aes == NULL || keySlot < 0 || keySlot >= 511 )
122+ if (aesKey == NULL || keySlot < 0 || keySlot >= 511 )
123123 return BAD_FUNC_ARG ;
124124
125125
@@ -134,7 +134,7 @@ static int Tropic01_GetKeyAES(Aes* aes, int keySlot, word32 keySz)
134134
135135 /* Retrieve key from TROPIC01 */
136136
137- rett = lt_r_mem_data_read (& g_h , keySlot , ( byte * ) aes -> key , keySz );
137+ rett = lt_r_mem_data_read (& g_h , keySlot , aesKey , keySz );
138138 if (rett != LT_OK ) {
139139 WOLFSSL_MSG_EX (
140140 "TROPIC01: Get AES Key: Failed to retrieve key, ret=%d" ,
@@ -149,7 +149,7 @@ static int Tropic01_GetKeyAES(Aes* aes, int keySlot, word32 keySz)
149149}
150150
151151/*
152- * Retrive the ECC key from the secure R memory of TROPIC01
152+ * Retrieve the ECC key from the secure R memory of TROPIC01
153153 */
154154static int Tropic01_GetKeyECC (byte * ecckey , int keySlot , word32 keySz )
155155{
@@ -195,7 +195,8 @@ static int Tropic01_GetKeyECC(byte* ecckey, int keySlot, word32 keySz)
195195int Tropic01_CryptoCb (int devId , wc_CryptoInfo * info , void * ctx )
196196{
197197 int ret = CRYPTOCB_UNAVAILABLE ;
198-
198+ byte lt_key [TROPIC01_AES_MAX_KEY_SIZE ] = {0 };
199+ byte lt_iv [TROPIC01_AES_MAX_KEY_SIZE ] = {0 };
199200
200201 if (info == NULL )
201202 return BAD_FUNC_ARG ;
@@ -296,16 +297,33 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
296297#if !defined(NO_AES )
297298 #ifdef HAVE_AESGCM
298299 if (info -> cipher .type == WC_CIPHER_AES_GCM ) {
299- if (info -> cipher .enc ) {
300-
301- ret = Tropic01_GetKeyAES (
302- info -> cipher .aesgcm_enc .aes ,
303- TROPIC01_AES_RMEM_SLOT_DEFAULT ,
300+ ret = Tropic01_GetKeyAES (
301+ lt_key ,
302+ TROPIC01_AES_KEY_RMEM_SLOT ,
304303 TROPIC01_AES_MAX_KEY_SIZE );
305- if (ret != 0 ) {
306- WOLFSSL_MSG_EX (
304+ if (ret != 0 ) {
305+ WOLFSSL_MSG_EX (
307306 "TROPIC01: CryptoCB: Failed to get AES key,ret=%d" ,
308307 ret );
308+ return ret ;
309+ }
310+ ret = Tropic01_GetKeyAES (
311+ lt_iv ,
312+ TROPIC01_AES_IV_RMEM_SLOT ,
313+ TROPIC01_AES_MAX_KEY_SIZE );
314+ if (ret != 0 ) {
315+ WOLFSSL_MSG_EX (
316+ "TROPIC01: CryptoCB: Failed to get AES IV, ret=%d" ,
317+ ret );
318+ return ret ;
319+ }
320+ if (info -> cipher .enc ) {
321+ ret = wc_AesSetKey (info -> cipher .aesgcm_enc .aes , lt_key ,
322+ WC_AES_BLOCK_SIZE , lt_iv , AES_ENCRYPTION );
323+ if (ret != 0 ) {
324+ WOLFSSL_MSG_EX (
325+ "TROPIC01: CryptoCB: Failed to set AES key, ret=%d" ,
326+ ret );
309327 return ret ;
310328 }
311329 /* set devId to invalid, so software is used */
@@ -327,14 +345,12 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
327345 }
328346 else {
329347
330- ret = Tropic01_GetKeyAES (
331- info -> cipher .aesgcm_dec .aes ,
332- TROPIC01_AES_RMEM_SLOT_DEFAULT ,
333- TROPIC01_AES_MAX_KEY_SIZE );
348+ ret = wc_AesSetKey (info -> cipher .aesgcm_dec .aes , lt_key ,
349+ WC_AES_BLOCK_SIZE , lt_iv , AES_DECRYPTION );
334350 if (ret != 0 ) {
335351 WOLFSSL_MSG_EX (
336- "TROPIC01: CryptoCB: Failed to get AES key,ret=%d" ,
337- ret );
352+ "TROPIC01: CryptoCB: Failed to set AES key, ret=%d" ,
353+ ret );
338354 return ret ;
339355 }
340356 /* set devId to invalid, so software is used */
@@ -358,15 +374,30 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
358374#endif /* HAVE_AESGCM */
359375 #ifdef HAVE_AES_CBC
360376 if (info -> cipher .type == WC_CIPHER_AES_CBC ) {
377+ ret = Tropic01_GetKeyAES (
378+ lt_key ,
379+ TROPIC01_AES_KEY_RMEM_SLOT ,
380+ TROPIC01_AES_MAX_KEY_SIZE );
381+ if (ret != 0 ) {
382+ WOLFSSL_MSG_EX (
383+ "TROPIC01: CryptoCB: Failed to get AES key,ret=%d" , ret );
384+ return ret ;
385+ }
386+ ret = Tropic01_GetKeyAES (
387+ lt_iv ,
388+ TROPIC01_AES_IV_RMEM_SLOT ,
389+ TROPIC01_AES_MAX_KEY_SIZE );
390+ if (ret != 0 ) {
391+ WOLFSSL_MSG_EX (
392+ "TROPIC01: CryptoCB: Failed to get AES IV, ret=%d" , ret );
393+ return ret ;
394+ }
361395 if (info -> cipher .enc ) {
362-
363- ret = Tropic01_GetKeyAES (
364- info -> cipher .aescbc .aes ,
365- TROPIC01_AES_RMEM_SLOT_DEFAULT ,
366- TROPIC01_AES_MAX_KEY_SIZE );
396+ ret = wc_AesSetKey (info -> cipher .aescbc .aes , lt_key ,
397+ WC_AES_BLOCK_SIZE , lt_iv , AES_ENCRYPTION );
367398 if (ret != 0 ) {
368399 WOLFSSL_MSG_EX (
369- "TROPIC01: CryptoCB: Failed to get AES key, ret=%d" ,
400+ "TROPIC01: CryptoCB: Failed to set AES key, ret=%d" ,
370401 ret );
371402 return ret ;
372403 }
@@ -383,14 +414,12 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
383414 }
384415 else {
385416
386- ret = Tropic01_GetKeyAES (
387- info -> cipher .aescbc .aes ,
388- TROPIC01_AES_RMEM_SLOT_DEFAULT ,
389- TROPIC01_AES_MAX_KEY_SIZE );
417+ ret = wc_AesSetKey (info -> cipher .aescbc .aes , lt_key ,
418+ WC_AES_BLOCK_SIZE , lt_iv , AES_DECRYPTION );
390419 if (ret != 0 ) {
391420 WOLFSSL_MSG_EX (
392- "TROPIC01: CryptoCB: Failed to get AES key, ret=%d" ,
393- ret );
421+ "TROPIC01: CryptoCB: Failed to set AES key, ret=%d" ,
422+ ret );
394423 return ret ;
395424 }
396425 /* set devId to invalid, so software is used */
0 commit comments