Skip to content

Commit 6ac6e50

Browse files
fix for tropic port AES key length used
1 parent dc56e87 commit 6ac6e50

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

wolfcrypt/src/port/tropicsquare/tropic01.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,13 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
314314
#if !defined(NO_AES)
315315
#ifdef HAVE_AESGCM
316316
if (info->cipher.type == WC_CIPHER_AES_GCM) {
317+
word32 keyLen = info->cipher.enc
318+
? info->cipher.aesgcm_enc.aes->keylen
319+
: info->cipher.aesgcm_dec.aes->keylen;
317320
ret = Tropic01_GetKeyAES(
318321
lt_key,
319322
TROPIC01_AES_KEY_RMEM_SLOT,
320-
TROPIC01_AES_MAX_KEY_SIZE);
323+
keyLen);
321324
if (ret != 0) {
322325
WOLFSSL_MSG_EX(
323326
"TROPIC01: CryptoCB: Failed to get AES key,ret=%d",
@@ -339,7 +342,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
339342
}
340343
if (info->cipher.enc) {
341344
ret = wc_AesSetKey(info->cipher.aesgcm_enc.aes, lt_key,
342-
WC_AES_BLOCK_SIZE, lt_iv, AES_ENCRYPTION);
345+
keyLen, lt_iv, AES_ENCRYPTION);
343346
ForceZero(lt_key, sizeof(lt_key));
344347
ForceZero(lt_iv, sizeof(lt_iv));
345348
if (ret != 0) {
@@ -367,7 +370,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
367370
}
368371
else {
369372
ret = wc_AesSetKey(info->cipher.aesgcm_dec.aes, lt_key,
370-
WC_AES_BLOCK_SIZE, lt_iv, AES_DECRYPTION);
373+
keyLen, lt_iv, AES_DECRYPTION);
371374
ForceZero(lt_key, sizeof(lt_key));
372375
ForceZero(lt_iv, sizeof(lt_iv));
373376
if (ret != 0) {
@@ -397,10 +400,11 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
397400
#endif /* HAVE_AESGCM */
398401
#ifdef HAVE_AES_CBC
399402
if (info->cipher.type == WC_CIPHER_AES_CBC) {
403+
word32 keyLen = info->cipher.aescbc.aes->keylen;
400404
ret = Tropic01_GetKeyAES(
401405
lt_key,
402406
TROPIC01_AES_KEY_RMEM_SLOT,
403-
TROPIC01_AES_MAX_KEY_SIZE);
407+
keyLen);
404408
if (ret != 0) {
405409
WOLFSSL_MSG_EX(
406410
"TROPIC01: CryptoCB: Failed to get AES key,ret=%d", ret);
@@ -420,7 +424,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
420424
}
421425
if (info->cipher.enc) {
422426
ret = wc_AesSetKey(info->cipher.aescbc.aes, lt_key,
423-
WC_AES_BLOCK_SIZE, lt_iv, AES_ENCRYPTION);
427+
keyLen, lt_iv, AES_ENCRYPTION);
424428
ForceZero(lt_key, sizeof(lt_key));
425429
ForceZero(lt_iv, sizeof(lt_iv));
426430
if (ret != 0) {
@@ -443,7 +447,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
443447
else {
444448

445449
ret = wc_AesSetKey(info->cipher.aescbc.aes, lt_key,
446-
WC_AES_BLOCK_SIZE, lt_iv, AES_DECRYPTION);
450+
keyLen, lt_iv, AES_DECRYPTION);
447451
ForceZero(lt_key, sizeof(lt_key));
448452
ForceZero(lt_iv, sizeof(lt_iv));
449453
if (ret != 0) {

0 commit comments

Comments
 (0)