Skip to content

Commit 396b5ec

Browse files
authored
Merge pull request wolfSSL#9896 from embhorn/f278-281-282
Fixes issues in SRP component:
2 parents f02f6d1 + 25f8d6d commit 396b5ec

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

wolfcrypt/src/srp.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ int wc_SrpInit_ex(Srp* srp, SrpType type, SrpSide side, void* heap, int devId)
259259
/* initializing variables */
260260
XMEMSET(srp, 0, sizeof(Srp));
261261

262+
/* default heap hint to NULL or test value */
263+
#ifdef WOLFSSL_HEAP_TEST
264+
srp->heap = (void*)WOLFSSL_HEAP_TEST;
265+
#else
266+
srp->heap = heap;
267+
#endif /* WOLFSSL_HEAP_TEST */
268+
262269
if ((r = SrpHashInit(&srp->client_proof, type, srp->heap)) != 0)
263270
return r;
264271

@@ -280,13 +287,6 @@ int wc_SrpInit_ex(Srp* srp, SrpType type, SrpSide side, void* heap, int devId)
280287

281288
srp->keyGenFunc_cb = wc_SrpSetKey;
282289

283-
/* default heap hint to NULL or test value */
284-
#ifdef WOLFSSL_HEAP_TEST
285-
srp->heap = (void*)WOLFSSL_HEAP_TEST;
286-
#else
287-
srp->heap = heap;
288-
#endif /* WOLFSSL_HEAP_TEST */
289-
290290
(void)devId; /* future */
291291

292292
return 0;
@@ -300,8 +300,8 @@ int wc_SrpInit(Srp* srp, SrpType type, SrpSide side)
300300
void wc_SrpTerm(Srp* srp)
301301
{
302302
if (srp) {
303-
mp_clear(&srp->N); mp_clear(&srp->g);
304-
mp_clear(&srp->auth); mp_clear(&srp->priv);
303+
mp_clear(&srp->N); mp_clear(&srp->g);
304+
mp_forcezero(&srp->auth); mp_forcezero(&srp->priv);
305305
if (srp->salt) {
306306
ForceZero(srp->salt, srp->saltSz);
307307
XFREE(srp->salt, srp->heap, DYNAMIC_TYPE_SRP);
@@ -912,30 +912,30 @@ int wc_SrpComputeKey(Srp* srp, byte* clientPubKey, word32 clientPubKeySz,
912912
XFREE(digest, srp->heap, DYNAMIC_TYPE_SRP);
913913
if (u) {
914914
if (r != WC_NO_ERR_TRACE(MP_INIT_E))
915-
mp_clear(u);
915+
mp_forcezero(u);
916916
XFREE(u, srp->heap, DYNAMIC_TYPE_SRP);
917917
}
918918
if (s) {
919919
if (r != WC_NO_ERR_TRACE(MP_INIT_E))
920-
mp_clear(s);
920+
mp_forcezero(s);
921921
XFREE(s, srp->heap, DYNAMIC_TYPE_SRP);
922922
}
923923
if (temp1) {
924924
if (r != WC_NO_ERR_TRACE(MP_INIT_E))
925-
mp_clear(temp1);
925+
mp_forcezero(temp1);
926926
XFREE(temp1, srp->heap, DYNAMIC_TYPE_SRP);
927927
}
928928
if (temp2) {
929929
if (r != WC_NO_ERR_TRACE(MP_INIT_E))
930-
mp_clear(temp2);
930+
mp_forcezero(temp2);
931931
XFREE(temp2, srp->heap, DYNAMIC_TYPE_SRP);
932932
}
933933
#else
934934
if (r != WC_NO_ERR_TRACE(MP_INIT_E)) {
935-
mp_clear(u);
936-
mp_clear(s);
937-
mp_clear(temp1);
938-
mp_clear(temp2);
935+
mp_forcezero(u);
936+
mp_forcezero(s);
937+
mp_forcezero(temp1);
938+
mp_forcezero(temp2);
939939
}
940940
#endif
941941

0 commit comments

Comments
 (0)