Skip to content

Commit 24c40b5

Browse files
committed
reset ret after CRYPTOCB_UNAVAILABLE fall-through in _InitCmac_common, add test_RsaInit_Pub/test_RsaNew_Pub helpers for keypub, re-add (void)heap, reject oversized CMAC id.
1 parent 8b49e0a commit 24c40b5

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

wolfcrypt/src/cmac.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ static int _InitCmac_common(Cmac* cmac, const byte* key, word32 keySz,
128128
* inspect them to determine the hardware key slot. */
129129
#ifdef WOLF_PRIVATE_KEY_ID
130130
cmac->aesInitType = aesInitType;
131-
if (aesInitType == CMAC_AES_INIT_ID && id != NULL &&
132-
idLen > 0 &&
133-
idLen <= (int)sizeof(cmac->id)) {
131+
if (aesInitType == CMAC_AES_INIT_ID && id != NULL && idLen > 0) {
132+
if (idLen > (int)sizeof(cmac->id)) {
133+
return BAD_FUNC_ARG;
134+
}
134135
XMEMCPY(cmac->id, id, (word32)idLen);
135136
cmac->idLen = idLen;
136137
}
@@ -161,12 +162,14 @@ static int _InitCmac_common(Cmac* cmac, const byte* key, word32 keySz,
161162
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
162163
return ret;
163164
}
164-
/* fall-through when unavailable, reset ret for software path */
165+
/* fall-through when unavailable */
166+
ret = 0;
165167
}
166168
#else
167169
(void)devId;
168170
#endif
169171
(void)unused;
172+
(void)heap;
170173

171174
if (key == NULL || keySz == 0) {
172175
return BAD_FUNC_ARG;

wolfcrypt/test/test.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,17 @@ static WC_MAYBE_UNUSED int test_RsaInit(RsaKey* key, void* heap,
644644
return wc_InitRsaKey_ex(key, heap, declaredDevId);
645645
#endif
646646
}
647+
648+
static WC_MAYBE_UNUSED int test_RsaInit_Pub(RsaKey* key, void* heap,
649+
int declaredDevId)
650+
{
651+
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_RSA_PUB_ID)
652+
return wc_InitRsaKey_Id(key, testRsaPubId, testRsaPubIdLen, heap,
653+
declaredDevId);
654+
#else
655+
return wc_InitRsaKey_ex(key, heap, declaredDevId);
656+
#endif
657+
}
647658
#endif /* !NO_RSA */
648659

649660
/* --- CMAC id[] and init helper --- */
@@ -1425,6 +1436,17 @@ static WC_MAYBE_UNUSED RsaKey* test_RsaNew(void* heap, int declaredDevId,
14251436
return wc_NewRsaKey(heap, declaredDevId, ret);
14261437
#endif
14271438
}
1439+
1440+
static WC_MAYBE_UNUSED RsaKey* test_RsaNew_Pub(void* heap, int declaredDevId,
1441+
int* ret)
1442+
{
1443+
#if defined(WOLF_PRIVATE_KEY_ID) && defined(WC_TEST_RSA_PUB_ID)
1444+
return wc_NewRsaKey_Id(testRsaPubId, testRsaPubIdLen, heap,
1445+
declaredDevId, ret);
1446+
#else
1447+
return wc_NewRsaKey(heap, declaredDevId, ret);
1448+
#endif
1449+
}
14281450
#endif /* !NO_RSA */
14291451

14301452
#endif /* !WC_NO_CONSTRUCTORS && !HAVE_SELFTEST */
@@ -25809,7 +25831,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
2580925831
if (key == NULL)
2581025832
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
2581125833
#if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
25812-
keypub = test_RsaNew(HEAP_HINT, devId, &ret);
25834+
keypub = test_RsaNew_Pub(HEAP_HINT, devId, &ret);
2581325835
if (keypub == NULL)
2581425836
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
2581525837
#endif
@@ -25824,7 +25846,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
2582425846
if (ret != 0)
2582525847
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
2582625848
#if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
25827-
ret = test_RsaInit(keypub, HEAP_HINT, devId);
25849+
ret = test_RsaInit_Pub(keypub, HEAP_HINT, devId);
2582825850
if (ret != 0)
2582925851
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
2583025852
#endif

0 commit comments

Comments
 (0)