@@ -307,10 +307,13 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
307307#if !defined(NO_AES )
308308 #ifdef HAVE_AESGCM
309309 if (info -> cipher .type == WC_CIPHER_AES_GCM ) {
310+ word32 keyLen = info -> cipher .enc
311+ ? info -> cipher .aesgcm_enc .aes -> keylen
312+ : info -> cipher .aesgcm_dec .aes -> keylen ;
310313 ret = Tropic01_GetKeyAES (
311314 lt_key ,
312315 TROPIC01_AES_KEY_RMEM_SLOT ,
313- TROPIC01_AES_MAX_KEY_SIZE );
316+ keyLen );
314317 if (ret != 0 ) {
315318 WOLFSSL_MSG_EX (
316319 "TROPIC01: CryptoCB: Failed to get AES key,ret=%d" ,
@@ -332,7 +335,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
332335 }
333336 if (info -> cipher .enc ) {
334337 ret = wc_AesSetKey (info -> cipher .aesgcm_enc .aes , lt_key ,
335- WC_AES_BLOCK_SIZE , lt_iv , AES_ENCRYPTION );
338+ keyLen , lt_iv , AES_ENCRYPTION );
336339 ForceZero (lt_key , sizeof (lt_key ));
337340 ForceZero (lt_iv , sizeof (lt_iv ));
338341 if (ret != 0 ) {
@@ -360,7 +363,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
360363 }
361364 else {
362365 ret = wc_AesSetKey (info -> cipher .aesgcm_dec .aes , lt_key ,
363- WC_AES_BLOCK_SIZE , lt_iv , AES_DECRYPTION );
366+ keyLen , lt_iv , AES_DECRYPTION );
364367 ForceZero (lt_key , sizeof (lt_key ));
365368 ForceZero (lt_iv , sizeof (lt_iv ));
366369 if (ret != 0 ) {
@@ -390,10 +393,11 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
390393#endif /* HAVE_AESGCM */
391394 #ifdef HAVE_AES_CBC
392395 if (info -> cipher .type == WC_CIPHER_AES_CBC ) {
396+ word32 keyLen = info -> cipher .aescbc .aes -> keylen ;
393397 ret = Tropic01_GetKeyAES (
394398 lt_key ,
395399 TROPIC01_AES_KEY_RMEM_SLOT ,
396- TROPIC01_AES_MAX_KEY_SIZE );
400+ keyLen );
397401 if (ret != 0 ) {
398402 WOLFSSL_MSG_EX (
399403 "TROPIC01: CryptoCB: Failed to get AES key,ret=%d" , ret );
@@ -413,7 +417,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
413417 }
414418 if (info -> cipher .enc ) {
415419 ret = wc_AesSetKey (info -> cipher .aescbc .aes , lt_key ,
416- WC_AES_BLOCK_SIZE , lt_iv , AES_ENCRYPTION );
420+ keyLen , lt_iv , AES_ENCRYPTION );
417421 ForceZero (lt_key , sizeof (lt_key ));
418422 ForceZero (lt_iv , sizeof (lt_iv ));
419423 if (ret != 0 ) {
@@ -436,7 +440,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
436440 else {
437441
438442 ret = wc_AesSetKey (info -> cipher .aescbc .aes , lt_key ,
439- WC_AES_BLOCK_SIZE , lt_iv , AES_DECRYPTION );
443+ keyLen , lt_iv , AES_DECRYPTION );
440444 ForceZero (lt_key , sizeof (lt_key ));
441445 ForceZero (lt_iv , sizeof (lt_iv ));
442446 if (ret != 0 ) {
0 commit comments