Skip to content

Commit c29abcc

Browse files
committed
src/internal.c: peer review: refactor wolfssl_priv_der_unblind() and wolfssl_priv_der_unblind_free() to use AllocDer() and FreeDer().
1 parent dee0658 commit c29abcc

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/internal.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,36 +295,28 @@ int wolfssl_priv_der_blind(WC_RNG* rng, DerBuffer* key, DerBuffer** mask)
295295

296296
void wolfssl_priv_der_blind_toggle(DerBuffer* key, const DerBuffer* mask)
297297
{
298-
if (key != NULL) {
298+
if ((key != NULL) && (mask != NULL)) {
299299
xorbuf(key->buffer, mask->buffer, mask->length);
300300
}
301301
}
302302

303303
DerBuffer *wolfssl_priv_der_unblind(const DerBuffer* key, const DerBuffer* mask)
304304
{
305305
DerBuffer *ret;
306-
if (key == NULL)
306+
if ((key == NULL) || (mask == NULL))
307307
return NULL;
308308
if (mask->length > key->length)
309309
return NULL;
310-
ret = (DerBuffer *)XMALLOC(sizeof(*key) + key->length, key->heap,
311-
DYNAMIC_TYPE_TMP_BUFFER);
312-
if (ret == NULL)
310+
if (AllocDer(&ret, key->length, key->type, key->heap) != 0)
313311
return NULL;
314-
XMEMCPY(ret, key, sizeof(*key));
315-
ret->buffer = (byte *)ret + sizeof(*key);
316312
xorbufout(ret->buffer, key->buffer, mask->buffer, mask->length);
317313
return ret;
318314
}
319315

320316
void wolfssl_priv_der_unblind_free(DerBuffer* key)
321317
{
322-
if (key != NULL) {
323-
void *heap = key->heap;
324-
ForceZero(key->buffer, key->length);
325-
ForceZero(key, sizeof(*key));
326-
XFREE(key, heap, DYNAMIC_TYPE_TMP_BUFFER);
327-
}
318+
if (key != NULL)
319+
FreeDer(&key);
328320
}
329321

330322
#endif /* !NO_CERT && WOLFSSL_BLIND_PRIVATE_KEY */

0 commit comments

Comments
 (0)