Factorise multiple bn_get_top(group->field) calls
Add missing checks on some conditional BN_copy return value
Add missing checks on some BN_copy return value
Add missing checks on a few bn_wexpand return value
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1626)
- if (r != rr)
- BN_copy(r, rr);
+ if (r != rr && BN_copy(r, rr) == NULL)
+ goto err;
+
ret = 1;
err:
BN_CTX_end(ctx);
ret = 1;
err:
BN_CTX_end(ctx);
end:
#endif
bn_correct_top(rr);
end:
#endif
bn_correct_top(rr);
- if (r != rr)
- BN_copy(r, rr);
+ if (r != rr && BN_copy(r, rr) == NULL)
+ goto err;
+
ret = 1;
err:
bn_check_top(r);
ret = 1;
err:
bn_check_top(r);
BIGNUM *t;
if ((t = BN_CTX_get(ctx)) == NULL)
goto err;
BIGNUM *t;
if ((t = BN_CTX_get(ctx)) == NULL)
goto err;
+ if (BN_copy(t, a) == NULL)
+ goto err;
t->neg = 0;
A = t;
} else
t->neg = 0;
A = t;
} else
rr->top = max - 1;
else
rr->top = max;
rr->top = max - 1;
else
rr->top = max;
- if (rr != r)
- BN_copy(r, rr);
+ if (r != rr && BN_copy(r, rr) == NULL)
+ goto err;
+
ret = 1;
err:
bn_check_top(rr);
ret = 1;
err:
bn_check_top(rr);
BN_CTX *ctx)
{
BIGNUM *x1, *x2, *z1, *z2;
BN_CTX *ctx)
{
BIGNUM *x1, *x2, *z1, *z2;
+ int ret = 0, i, group_top;
BN_ULONG mask, word;
if (r == point) {
BN_ULONG mask, word;
if (r == point) {
- bn_wexpand(x1, bn_get_top(group->field));
- bn_wexpand(z1, bn_get_top(group->field));
- bn_wexpand(x2, bn_get_top(group->field));
- bn_wexpand(z2, bn_get_top(group->field));
+ group_top = bn_get_top(group->field);
+ if (bn_wexpand(x1, group_top) == NULL
+ || bn_wexpand(z1, group_top) == NULL
+ || bn_wexpand(x2, group_top) == NULL
+ || bn_wexpand(z2, group_top) == NULL)
+ goto err;
if (!BN_GF2m_mod_arr(x1, point->X, group->poly))
goto err; /* x1 = x */
if (!BN_GF2m_mod_arr(x1, point->X, group->poly))
goto err; /* x1 = x */
for (; i >= 0; i--) {
word = bn_get_words(scalar)[i];
while (mask) {
for (; i >= 0; i--) {
word = bn_get_words(scalar)[i];
while (mask) {
- BN_consttime_swap(word & mask, x1, x2, bn_get_top(group->field));
- BN_consttime_swap(word & mask, z1, z2, bn_get_top(group->field));
+ BN_consttime_swap(word & mask, x1, x2, group_top);
+ BN_consttime_swap(word & mask, z1, z2, group_top);
if (!gf2m_Madd(group, point->X, x2, z2, x1, z1, ctx))
goto err;
if (!gf2m_Mdouble(group, x1, z1, ctx))
goto err;
if (!gf2m_Madd(group, point->X, x2, z2, x1, z1, ctx))
goto err;
if (!gf2m_Mdouble(group, x1, z1, ctx))
goto err;
- BN_consttime_swap(word & mask, x1, x2, bn_get_top(group->field));
- BN_consttime_swap(word & mask, z1, z2, bn_get_top(group->field));
+ BN_consttime_swap(word & mask, x1, x2, group_top);
+ BN_consttime_swap(word & mask, z1, z2, group_top);
mask >>= 1;
}
mask = BN_TBIT;
mask >>= 1;
}
mask = BN_TBIT;
if (!rsa->iqmp && ((rsa->iqmp = BN_secure_new()) == NULL))
goto err;
if (!rsa->iqmp && ((rsa->iqmp = BN_secure_new()) == NULL))
goto err;
- BN_copy(rsa->e, e_value);
+ if (BN_copy(rsa->e, e_value) == NULL)
+ goto err;
/* generate p and q */
for (;;) {
/* generate p and q */
for (;;) {