wolfSSL: Fix crypto_ec_point_compute_y_sqr() error case processing
The result (y2) was cleared and freed in error cases, but the pointer itself was not cleared to NULL, so the error path would have returned a pointer to freed memory. Fix this by properly clearing the return value in error cases. In addition, simplify the function to avoid tracking success case separately. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
7302aa7614
commit
f50d5c9a83
1 changed files with 8 additions and 20 deletions
|
@ -1650,34 +1650,22 @@ struct crypto_bignum *
|
||||||
crypto_ec_point_compute_y_sqr(struct crypto_ec *e,
|
crypto_ec_point_compute_y_sqr(struct crypto_ec *e,
|
||||||
const struct crypto_bignum *x)
|
const struct crypto_bignum *x)
|
||||||
{
|
{
|
||||||
mp_int *y2 = NULL;
|
mp_int *y2, t;
|
||||||
mp_int t;
|
|
||||||
int calced = 0;
|
|
||||||
|
|
||||||
if (TEST_FAIL())
|
if (TEST_FAIL())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (mp_init(&t) != MP_OKAY)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
y2 = (mp_int *) crypto_bignum_init();
|
y2 = (mp_int *) crypto_bignum_init();
|
||||||
if (!y2)
|
if (!y2 ||
|
||||||
goto done;
|
mp_init(&t) != MP_OKAY ||
|
||||||
|
mp_sqrmod((mp_int *) x, &e->prime, y2) != 0 ||
|
||||||
if (mp_sqrmod((mp_int *) x, &e->prime, y2) != 0 ||
|
|
||||||
mp_mulmod((mp_int *) x, y2, &e->prime, y2) != 0 ||
|
mp_mulmod((mp_int *) x, y2, &e->prime, y2) != 0 ||
|
||||||
mp_mulmod((mp_int *) x, &e->a, &e->prime, &t) != 0 ||
|
mp_mulmod((mp_int *) x, &e->a, &e->prime, &t) != 0 ||
|
||||||
mp_addmod(y2, &t, &e->prime, y2) != 0 ||
|
mp_addmod(y2, &t, &e->prime, y2) != 0 ||
|
||||||
mp_addmod(y2, &e->b, &e->prime, y2) != 0)
|
mp_addmod(y2, &e->b, &e->prime, y2) != 0) {
|
||||||
goto done;
|
|
||||||
|
|
||||||
calced = 1;
|
|
||||||
done:
|
|
||||||
if (!calced) {
|
|
||||||
if (y2) {
|
|
||||||
mp_clear(y2);
|
mp_clear(y2);
|
||||||
os_free(y2);
|
os_free(y2);
|
||||||
}
|
y2 = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_clear(&t);
|
mp_clear(&t);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue