-/* $OpenBSD: bn_add.c,v 1.13 2018/07/23 18:07:21 tb Exp $ */
+/* $OpenBSD: bn_add.c,v 1.14 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
min = b->top;
dif = max - min;
- if (bn_wexpand(r, max + 1) == NULL)
+ if (!bn_wexpand(r, max + 1))
return 0;
r->top = max;
return 0;
}
- if (bn_wexpand(r, max) == NULL)
+ if (!bn_wexpand(r, max))
return 0;
ap = a->d;
-/* $OpenBSD: bn_div.c,v 1.25 2017/01/29 17:49:22 beck Exp $ */
+/* $OpenBSD: bn_div.c,v 1.26 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* value.
*/
if (snum->top <= sdiv->top + 1) {
- if (bn_wexpand(snum, sdiv->top + 2) == NULL)
+ if (!bn_wexpand(snum, sdiv->top + 2))
goto err;
for (i = snum->top; i < sdiv->top + 2; i++)
snum->d[i] = 0;
snum->top = sdiv->top + 2;
} else {
- if (bn_wexpand(snum, snum->top + 1) == NULL)
+ if (!bn_wexpand(snum, snum->top + 1))
goto err;
snum->d[snum->top] = 0;
snum->top ++;
-/* $OpenBSD: bn_exp.c,v 1.32 2022/04/20 13:32:34 tb Exp $ */
+/* $OpenBSD: bn_exp.c,v 1.33 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
int width = 1 << window;
volatile BN_ULONG *table = (volatile BN_ULONG *)buf;
- if (bn_wexpand(b, top) == NULL)
+ if (!bn_wexpand(b, top))
return 0;
if (window <= 3) {
-/* $OpenBSD: bn_gf2m.c,v 1.25 2022/11/20 23:35:00 schwarze Exp $ */
+/* $OpenBSD: bn_gf2m.c,v 1.26 2022/11/24 01:30:01 jsing Exp $ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
bt = b;
}
- if (bn_wexpand(r, at->top) == NULL)
+ if (!bn_wexpand(r, at->top))
return 0;
for (i = 0; i < bt->top; i++) {
-/* $OpenBSD: bn_lcl.h,v 1.37 2022/11/23 03:00:12 jsing Exp $ */
+/* $OpenBSD: bn_lcl.h,v 1.38 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
int cl, int dl);
int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num);
-BIGNUM *bn_expand(BIGNUM *a, int bits);
-BIGNUM *bn_wexpand(BIGNUM *a, int words);
+int bn_expand(BIGNUM *a, int bits);
+int bn_wexpand(BIGNUM *a, int words);
/* Bignum consistency macros
* There is one "API" macro, bn_fix_top(), for stripping leading zeroes from
-/* $OpenBSD: bn_lib.c,v 1.60 2022/11/23 03:10:10 jsing Exp $ */
+/* $OpenBSD: bn_lib.c,v 1.61 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* It is mostly used by the various BIGNUM routines. If there is an error,
* NULL is returned. If not, 'b' is returned. */
-static BIGNUM *
+static int
bn_expand2(BIGNUM *b, int words)
{
bn_check_top(b);
if (words > b->dmax) {
BN_ULONG *a = bn_expand_internal(b, words);
- if (!a)
- return NULL;
+ if (a == NULL)
+ return 0;
if (b->d)
freezero(b->d, b->dmax * sizeof(b->d[0]));
b->d = a;
}
#endif
bn_check_top(b);
- return b;
+ return 1;
}
-BIGNUM *
+int
bn_expand(BIGNUM *a, int bits)
{
if (bits < 0)
- return (NULL);
+ return 0;
if (bits > (INT_MAX - BN_BITS2 + 1))
- return (NULL);
+ return 0;
if (((bits + BN_BITS2 - 1) / BN_BITS2) <= a->dmax)
- return (a);
+ return 1;
return bn_expand2(a, (bits + BN_BITS2 - 1) / BN_BITS2);
}
-BIGNUM *
+int
bn_wexpand(BIGNUM *a, int words)
{
if (words < 0)
- return NULL;
+ return 0;
if (words <= a->dmax)
- return a;
+ return 1;
return bn_expand2(a, words);
}
if (a == b)
return (a);
- if (bn_wexpand(a, b->top) == NULL)
+ if (!bn_wexpand(a, b->top))
return (NULL);
#if 1
BN_set_word(BIGNUM *a, BN_ULONG w)
{
bn_check_top(a);
- if (bn_wexpand(a, 1) == NULL)
+ if (!bn_wexpand(a, 1))
return (0);
a->neg = 0;
a->d[0] = w;
}
i = ((n - 1) / BN_BYTES) + 1;
m = ((n - 1) % (BN_BYTES));
- if (bn_wexpand(ret, (int)i) == NULL) {
+ if (!bn_wexpand(ret, (int)i)) {
BN_free(bn);
return NULL;
}
i = ((n - 1) / BN_BYTES) + 1;
m = (n - 1) % BN_BYTES;
- if (bn_wexpand(ret, (int)i) == NULL) {
+ if (!bn_wexpand(ret, (int)i)) {
BN_free(bn);
return NULL;
}
i = n / BN_BITS2;
j = n % BN_BITS2;
if (a->top <= i) {
- if (bn_wexpand(a, i + 1) == NULL)
+ if (!bn_wexpand(a, i + 1))
return (0);
for (k = a->top; k < i + 1; k++)
a->d[k] = 0;
if (nwords > INT_MAX)
return 0;
words = (int)nwords;
- if (bn_wexpand(a, words) == NULL || bn_wexpand(b, words) == NULL)
+ if (!bn_wexpand(a, words) || !bn_wexpand(b, words))
return 0;
if (a->top > words || b->top > words) {
BNerror(BN_R_INVALID_LENGTH);
-/* $OpenBSD: bn_mont.c,v 1.29 2022/11/23 03:10:10 jsing Exp $ */
+/* $OpenBSD: bn_mont.c,v 1.30 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
int num = mont->N.top;
if (num > 1 && a->top == num && b->top == num) {
- if (bn_wexpand(r, num) == NULL)
+ if (!bn_wexpand(r, num))
return (0);
if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {
r->neg = a->neg^b->neg;
}
max = (2 * nl); /* carry is stored separately */
- if (bn_wexpand(r, max) == NULL)
+ if (!bn_wexpand(r, max))
return (0);
r->neg ^= n->neg;
rp[nl] = v;
}
- if (bn_wexpand(ret, nl) == NULL)
+ if (!bn_wexpand(ret, nl))
return (0);
ret->top = nl;
ret->neg = r->neg;
}
else /* if N mod word size == 1 */
{
- if (bn_wexpand(Ri, 2) == NULL)
+ if (!bn_wexpand(Ri, 2))
goto err;
/* Ri-- (mod double word size) */
Ri->neg = 0;
-/* $OpenBSD: bn_mul.c,v 1.20 2015/02/09 15:49:22 jsing Exp $ */
+/* $OpenBSD: bn_mul.c,v 1.21 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
if (i == 0) {
# if 0
if (al == 4) {
- if (bn_wexpand(rr, 8) == NULL)
+ if (!bn_wexpand(rr, 8))
goto err;
rr->top = 8;
bn_mul_comba4(rr->d, a->d, b->d);
}
# endif
if (al == 8) {
- if (bn_wexpand(rr, 16) == NULL)
+ if (!bn_wexpand(rr, 16))
goto err;
rr->top = 16;
bn_mul_comba8(rr->d, a->d, b->d);
if ((t = BN_CTX_get(ctx)) == NULL)
goto err;
if (al > j || bl > j) {
- if (bn_wexpand(t, k * 4) == NULL)
+ if (!bn_wexpand(t, k * 4))
goto err;
- if (bn_wexpand(rr, k * 4) == NULL)
+ if (!bn_wexpand(rr, k * 4))
goto err;
bn_mul_part_recursive(rr->d, a->d, b->d,
j, al - j, bl - j, t->d);
}
else /* al <= j || bl <= j */
{
- if (bn_wexpand(t, k * 2) == NULL)
+ if (!bn_wexpand(t, k * 2))
goto err;
- if (bn_wexpand(rr, k * 2) == NULL)
+ if (!bn_wexpand(rr, k * 2))
goto err;
bn_mul_recursive(rr->d, a->d, b->d,
j, al - j, bl - j, t->d);
#if 0
if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BIGNUM *tmp_bn = (BIGNUM *)b;
- if (bn_wexpand(tmp_bn, al) == NULL)
+ if (!bn_wexpand(tmp_bn, al))
goto err;
tmp_bn->d[bl] = 0;
bl++;
i--;
} else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {
BIGNUM *tmp_bn = (BIGNUM *)a;
- if (bn_wexpand(tmp_bn, bl) == NULL)
+ if (!bn_wexpand(tmp_bn, bl))
goto err;
tmp_bn->d[al] = 0;
al++;
goto err;
if (al == j) /* exact multiple */
{
- if (bn_wexpand(t, k * 2) == NULL)
+ if (!bn_wexpand(t, k * 2))
goto err;
- if (bn_wexpand(rr, k * 2) == NULL)
+ if (!bn_wexpand(rr, k * 2))
goto err;
bn_mul_recursive(rr->d, a->d, b->d, al, t->d);
} else {
- if (bn_wexpand(t, k * 4) == NULL)
+ if (!bn_wexpand(t, k * 4))
goto err;
- if (bn_wexpand(rr, k * 4) == NULL)
+ if (!bn_wexpand(rr, k * 4))
goto err;
bn_mul_part_recursive(rr->d, a->d, b->d,
al - j, j, t->d);
#endif
}
#endif /* BN_RECURSION */
- if (bn_wexpand(rr, top) == NULL)
+ if (!bn_wexpand(rr, top))
goto err;
rr->top = top;
bn_mul_normal(rr->d, a->d, al, b->d, bl);
-/* $OpenBSD: bn_print.c,v 1.34 2022/11/22 08:46:27 tb Exp $ */
+/* $OpenBSD: bn_print.c,v 1.35 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
}
/* i is the number of hex digits */
- if (bn_expand(ret, i * 4) == NULL)
+ if (!bn_expand(ret, i * 4))
goto err;
j = i; /* least significant 'hex' */
}
/* i is the number of digits, a bit of an over expand */
- if (bn_expand(ret, i * 4) == NULL)
+ if (!bn_expand(ret, i * 4))
goto err;
j = BN_DEC_NUM - (i % BN_DEC_NUM);
-/* $OpenBSD: bn_shift.c,v 1.14 2022/06/22 09:03:06 tb Exp $ */
+/* $OpenBSD: bn_shift.c,v 1.15 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
if (r != a) {
r->neg = a->neg;
- if (bn_wexpand(r, a->top + 1) == NULL)
+ if (!bn_wexpand(r, a->top + 1))
return (0);
r->top = a->top;
} else {
- if (bn_wexpand(r, a->top + 1) == NULL)
+ if (!bn_wexpand(r, a->top + 1))
return (0);
}
ap = a->d;
ap = a->d;
j = i - (ap[i - 1]==1);
if (a != r) {
- if (bn_wexpand(r, j) == NULL)
+ if (!bn_wexpand(r, j))
return (0);
r->neg = a->neg;
}
r->neg = a->neg;
nw = n / BN_BITS2;
- if (bn_wexpand(r, a->top + nw + 1) == NULL)
+ if (!bn_wexpand(r, a->top + nw + 1))
return (0);
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;
if (r != a) {
r->neg = a->neg;
- if (bn_wexpand(r, i) == NULL)
+ if (!bn_wexpand(r, i))
return (0);
} else {
if (n == 0)
-/* $OpenBSD: bn_sqr.c,v 1.13 2022/11/22 20:43:43 tb Exp $ */
+/* $OpenBSD: bn_sqr.c,v 1.14 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
goto err;
max = 2 * al; /* Non-zero (from above) */
- if (bn_wexpand(rr, max) == NULL)
+ if (!bn_wexpand(rr, max))
goto err;
if (al == 4) {
j = 1 << (j - 1);
k = j + j;
if (al == j) {
- if (bn_wexpand(tmp, k * 2) == NULL)
+ if (!bn_wexpand(tmp, k * 2))
goto err;
bn_sqr_recursive(rr->d, a->d, al, tmp->d);
} else {
- if (bn_wexpand(tmp, max) == NULL)
+ if (!bn_wexpand(tmp, max))
goto err;
bn_sqr_normal(rr->d, a->d, al, tmp->d);
}
}
#else
- if (bn_wexpand(tmp, max) == NULL)
+ if (!bn_wexpand(tmp, max))
goto err;
bn_sqr_normal(rr->d, a->d, al, tmp->d);
#endif
-/* $OpenBSD: bn_word.c,v 1.13 2016/07/05 02:54:35 bcook Exp $ */
+/* $OpenBSD: bn_word.c,v 1.14 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
w = (w > l) ? 1 : 0;
}
if (w && i == a->top) {
- if (bn_wexpand(a, a->top + 1) == NULL)
+ if (!bn_wexpand(a, a->top + 1))
return 0;
a->top++;
a->d[i] = w;
else {
ll = bn_mul_words(a->d, a->d, a->top, w);
if (ll) {
- if (bn_wexpand(a, a->top + 1) == NULL)
+ if (!bn_wexpand(a, a->top + 1))
return (0);
a->d[a->top++] = ll;
}
-/* $OpenBSD: ec2_smpl.c,v 1.26 2022/11/24 01:24:37 jsing Exp $ */
+/* $OpenBSD: ec2_smpl.c,v 1.27 2022/11/24 01:30:01 jsing Exp $ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
dest->poly[3] = src->poly[3];
dest->poly[4] = src->poly[4];
dest->poly[5] = src->poly[5];
- if (bn_expand(&dest->a, dest->poly[0]) == NULL)
+ if (!bn_expand(&dest->a, dest->poly[0]))
return 0;
- if (bn_expand(&dest->b, dest->poly[0]) == NULL)
+ if (!bn_expand(&dest->b, dest->poly[0]))
return 0;
for (i = dest->a.top; i < dest->a.dmax; i++)
dest->a.d[i] = 0;
/* group->a */
if (!BN_GF2m_mod_arr(&group->a, a, group->poly))
goto err;
- if (bn_expand(&group->a, group->poly[0]) == NULL)
+ if (!bn_expand(&group->a, group->poly[0]))
goto err;
for (i = group->a.top; i < group->a.dmax; i++)
group->a.d[i] = 0;
/* group->b */
if (!BN_GF2m_mod_arr(&group->b, b, group->poly))
goto err;
- if (bn_expand(&group->b, group->poly[0]) == NULL)
+ if (!bn_expand(&group->b, group->poly[0]))
goto err;
for (i = group->b.top; i < group->b.dmax; i++)
group->b.d[i] = 0;
-/* $OpenBSD: ecp_nistz256.c,v 1.12 2022/11/19 07:00:57 tb Exp $ */
+/* $OpenBSD: ecp_nistz256.c,v 1.13 2022/11/24 01:30:01 jsing Exp $ */
/* Copyright (c) 2014, Intel Corporation.
*
* Permission to use, copy, modify, and/or distribute this software for any
static int
ecp_nistz256_set_words(BIGNUM *a, BN_ULONG words[P256_LIMBS])
{
- if (bn_wexpand(a, P256_LIMBS) == NULL) {
+ if (!bn_wexpand(a, P256_LIMBS)) {
ECerror(ERR_R_MALLOC_FAILURE);
return 0;
}
-/* $OpenBSD: ecp_smpl.c,v 1.36 2022/11/19 07:29:29 tb Exp $ */
+/* $OpenBSD: ecp_smpl.c,v 1.37 2022/11/24 01:30:01 jsing Exp $ */
/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
* for the OpenSSL project.
* Includes code written by Bodo Moeller for the OpenSSL project.
*/
cardinality_bits = BN_num_bits(cardinality);
group_top = cardinality->top;
- if ((bn_wexpand(k, group_top + 2) == NULL) ||
- (bn_wexpand(lambda, group_top + 2) == NULL))
+ if (!bn_wexpand(k, group_top + 2) ||
+ !bn_wexpand(lambda, group_top + 2))
goto err;
if (!BN_copy(k, scalar))
goto err;
group_top = group->field.top;
- if ((bn_wexpand(&s->X, group_top) == NULL) ||
- (bn_wexpand(&s->Y, group_top) == NULL) ||
- (bn_wexpand(&s->Z, group_top) == NULL) ||
- (bn_wexpand(&r->X, group_top) == NULL) ||
- (bn_wexpand(&r->Y, group_top) == NULL) ||
- (bn_wexpand(&r->Z, group_top) == NULL))
+ if (!bn_wexpand(&s->X, group_top) ||
+ !bn_wexpand(&s->Y, group_top) ||
+ !bn_wexpand(&s->Z, group_top) ||
+ !bn_wexpand(&r->X, group_top) ||
+ !bn_wexpand(&r->Y, group_top) ||
+ !bn_wexpand(&r->Z, group_top))
goto err;
/*