Skip to content

Commit 8574fa9

Browse files
authored
Merge pull request #10470 from JacobBarthelmeh/tropic
fix for tropic port AES key length used
2 parents 7bad79a + 70288b0 commit 8574fa9

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

wolfcrypt/src/port/tropicsquare/tropic01.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,17 @@ 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;
320+
if (keyLen != AES_128_KEY_SIZE &&
321+
keyLen != AES_192_KEY_SIZE &&
322+
keyLen != AES_256_KEY_SIZE) {
323+
WOLFSSL_MSG_EX(
324+
"TROPIC01: CryptoCB: invalid AES key length %u",
325+
keyLen);
326+
return BAD_FUNC_ARG;
327+
}
317328
ret = Tropic01_GetKeyAES(
318329
lt_key,
319330
TROPIC01_AES_KEY_RMEM_SLOT,
@@ -339,7 +350,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
339350
}
340351
if (info->cipher.enc) {
341352
ret = wc_AesSetKey(info->cipher.aesgcm_enc.aes, lt_key,
342-
WC_AES_BLOCK_SIZE, lt_iv, AES_ENCRYPTION);
353+
keyLen, lt_iv, AES_ENCRYPTION);
343354
ForceZero(lt_key, sizeof(lt_key));
344355
ForceZero(lt_iv, sizeof(lt_iv));
345356
if (ret != 0) {
@@ -367,7 +378,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
367378
}
368379
else {
369380
ret = wc_AesSetKey(info->cipher.aesgcm_dec.aes, lt_key,
370-
WC_AES_BLOCK_SIZE, lt_iv, AES_DECRYPTION);
381+
keyLen, lt_iv, AES_DECRYPTION);
371382
ForceZero(lt_key, sizeof(lt_key));
372383
ForceZero(lt_iv, sizeof(lt_iv));
373384
if (ret != 0) {
@@ -397,6 +408,14 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
397408
#endif /* HAVE_AESGCM */
398409
#ifdef HAVE_AES_CBC
399410
if (info->cipher.type == WC_CIPHER_AES_CBC) {
411+
word32 keyLen = info->cipher.aescbc.aes->keylen;
412+
if (keyLen != AES_128_KEY_SIZE &&
413+
keyLen != AES_192_KEY_SIZE &&
414+
keyLen != AES_256_KEY_SIZE) {
415+
WOLFSSL_MSG_EX(
416+
"TROPIC01: CryptoCB: invalid AES key length %u", keyLen);
417+
return BAD_FUNC_ARG;
418+
}
400419
ret = Tropic01_GetKeyAES(
401420
lt_key,
402421
TROPIC01_AES_KEY_RMEM_SLOT,
@@ -420,7 +439,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
420439
}
421440
if (info->cipher.enc) {
422441
ret = wc_AesSetKey(info->cipher.aescbc.aes, lt_key,
423-
WC_AES_BLOCK_SIZE, lt_iv, AES_ENCRYPTION);
442+
keyLen, lt_iv, AES_ENCRYPTION);
424443
ForceZero(lt_key, sizeof(lt_key));
425444
ForceZero(lt_iv, sizeof(lt_iv));
426445
if (ret != 0) {
@@ -443,7 +462,7 @@ int Tropic01_CryptoCb(int devId, wc_CryptoInfo* info, void* ctx)
443462
else {
444463

445464
ret = wc_AesSetKey(info->cipher.aescbc.aes, lt_key,
446-
WC_AES_BLOCK_SIZE, lt_iv, AES_DECRYPTION);
465+
keyLen, lt_iv, AES_DECRYPTION);
447466
ForceZero(lt_key, sizeof(lt_key));
448467
ForceZero(lt_iv, sizeof(lt_iv));
449468
if (ret != 0) {

0 commit comments

Comments
 (0)