Skip to content

Commit dbf72c4

Browse files
authored
Merge pull request #10601 from kareem-wolfssl/f3772
Fenrir fixes
2 parents c9cb0ef + 4a854b0 commit dbf72c4

7 files changed

Lines changed: 47 additions & 6 deletions

File tree

src/internal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18819,7 +18819,7 @@ int DoHandShakeMsgType(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1881918819
if (ssl->options.handShakeState == HANDSHAKE_DONE && type == client_hello &&
1882018820
ssl->options.side == WOLFSSL_SERVER_END) {
1882118821
WOLFSSL_MSG("Renegotiation request rejected");
18822-
SendAlert(ssl, alert_fatal, no_renegotiation);
18822+
SendAlert(ssl, alert_warning, no_renegotiation);
1882318823
WOLFSSL_ERROR_VERBOSE(SECURE_RENEGOTIATION_E);
1882418824
return SECURE_RENEGOTIATION_E;
1882518825
}

tests/api/test_aes.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7730,6 +7730,15 @@ int test_wc_AesEaxStream(void)
77307730
ExpectIntEQ(wc_AesEaxEncryptFinal(NULL, tagBuf, WC_AES_BLOCK_SIZE),
77317731
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
77327732

7733+
/* wc_AesEaxEncryptFinal authTagSz below WOLFSSL_MIN_AUTH_TAG_SZ must be
7734+
* rejected, even on an otherwise valid context */
7735+
ExpectIntEQ(wc_AesEaxInit(&eax, key1, sizeof(key1),
7736+
nonce1, sizeof(nonce1), NULL, 0), 0);
7737+
ExpectIntEQ(wc_AesEaxEncryptFinal(&eax, tagBuf,
7738+
WOLFSSL_MIN_AUTH_TAG_SZ - 1),
7739+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
7740+
ExpectIntEQ(wc_AesEaxFree(&eax), 0);
7741+
77337742
/* wc_AesEaxDecryptFinal NULL eax */
77347743
ExpectIntEQ(wc_AesEaxDecryptFinal(NULL, tag1, sizeof(tag1)),
77357744
WC_NO_ERR_TRACE(BAD_FUNC_ARG));

wolfcrypt/src/aes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17556,7 +17556,7 @@ int wc_AesEaxEncryptFinal(AesEax* eax, byte* authTag, word32 authTagSz)
1755617556
word32 i;
1755717557

1755817558
if (eax == NULL || authTag == NULL || authTagSz == 0 ||
17559-
authTagSz > WC_AES_BLOCK_SIZE) {
17559+
authTagSz > WC_AES_BLOCK_SIZE || authTagSz < WOLFSSL_MIN_AUTH_TAG_SZ) {
1756017560
return BAD_FUNC_ARG;
1756117561
}
1756217562

wolfcrypt/src/port/Renesas/renesas_tsip_rsa.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ This code assumes at least one is enabled
5555
int wc_tsip_MakeRsaKey(int size, void* ctx)
5656
{
5757
e_tsip_err_t ret;
58+
int wcRet = WC_HW_E;
5859
TsipUserCtx *info = (TsipUserCtx*)ctx;
5960
#if defined(TSIP_RSAES_1024) && TSIP_RSAES_1024 == 1
6061
tsip_rsa1024_key_pair_index_t *tsip_pair1024_key = NULL;
@@ -148,6 +149,7 @@ int wc_tsip_MakeRsaKey(int size, void* ctx)
148149
info->keyflgs_crypt.bits.rsapri1024_key_set = 1;
149150
info->keyflgs_crypt.bits.rsapub1024_key_set = 1;
150151
info->wrappedKeyType = TSIP_KEY_TYPE_RSA1024;
152+
wcRet = 0;
151153
#endif
152154
}
153155
else if (size == 2048) {
@@ -191,13 +193,31 @@ int wc_tsip_MakeRsaKey(int size, void* ctx)
191193
info->keyflgs_crypt.bits.rsapri2048_key_set = 1;
192194
info->keyflgs_crypt.bits.rsapub2048_key_set = 1;
193195
info->wrappedKeyType = TSIP_KEY_TYPE_RSA2048;
196+
wcRet = 0;
194197
#endif
195198
}
196199
}
200+
else {
201+
/* hardware key generation failed; free the key pair buffer that
202+
* was allocated above so it does not leak, and report the error */
203+
WOLFSSL_MSG_EX("TSIP RSA key generation failed: %d", ret);
204+
#if defined(TSIP_RSAES_1024) && TSIP_RSAES_1024 == 1
205+
XFREE(tsip_pair1024_key, NULL, DYNAMIC_TYPE_RSA_BUFFER);
206+
#endif
207+
#if defined(TSIP_RSAES_2048) && TSIP_RSAES_2048 == 1
208+
XFREE(tsip_pair2048_key, NULL, DYNAMIC_TYPE_RSA_BUFFER);
209+
#endif
210+
wcRet = WC_HW_E;
211+
}
197212
tsip_hw_unlock();
198213
}
214+
else {
215+
/* could not obtain the TSIP hardware lock */
216+
WOLFSSL_MSG_EX("TSIP hardware lock failed: %d", ret);
217+
wcRet = WC_HW_E;
218+
}
199219

200-
return 0;
220+
return wcRet;
201221
}
202222

203223
/* Generate TSIP key index if needed
@@ -260,7 +280,9 @@ int wc_tsip_RsaFunction(wc_CryptoInfo* info, TsipUserCtx* tuc)
260280
return BAD_FUNC_ARG;
261281
}
262282

263-
if (tsip_RsakeyImport(tuc) == 0) {
283+
ret = tsip_RsakeyImport(tuc);
284+
285+
if (ret == 0) {
264286
type = info->pk.rsa.type;
265287
keySize = (int)tuc->wrappedKeyType;
266288

@@ -364,7 +386,10 @@ int wc_tsip_RsaVerifyPkcs(wc_CryptoInfo* info, TsipUserCtx* tuc)
364386
ret = CRYPTOCB_UNAVAILABLE;
365387
}
366388

367-
if (tsip_RsakeyImport(tuc) == 0) {
389+
if (ret == 0)
390+
ret = tsip_RsakeyImport(tuc);
391+
392+
if (ret == 0) {
368393
hashData.pdata = (uint8_t*)info->pk.rsa.out;
369394
hashData.data_length = *(info->pk.rsa.outLen);
370395
hashData.data_type =

wolfcrypt/src/port/cypress/psoc6_crypto.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ int wc_Sha512_224Final(wc_Sha512* sha, byte* hash)
644644
wolfSSL_CryptHwMutexUnLock();
645645
}
646646

647+
if (ret != 0)
648+
return ret;
649+
647650
/* Reset state */
648651
return wc_InitSha512_224(sha);
649652
}

wolfcrypt/src/random.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,10 @@ int wc_rng_new_ex(WC_RNG **rng, byte* nonce, word32 nonceSz,
21752175
{
21762176
int ret;
21772177

2178+
if (rng == NULL) {
2179+
return BAD_FUNC_ARG;
2180+
}
2181+
21782182
*rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), heap, DYNAMIC_TYPE_RNG);
21792183
if (*rng == NULL) {
21802184
return MEMORY_E;

wolfcrypt/src/wc_xmss.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ int wc_XmssKey_GetPubLen(const XmssKey* key, word32* len)
15751575
int ret = 0;
15761576

15771577
/* Validate parameters. */
1578-
if ((key == NULL) || (len == NULL)) {
1578+
if ((key == NULL) || (key->params == NULL) || (len == NULL)) {
15791579
ret = BAD_FUNC_ARG;
15801580
}
15811581
else {

0 commit comments

Comments
 (0)