summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2022-11-24 01:30:01 +0000
committerjsing <>2022-11-24 01:30:01 +0000
commit8a7c8abfd4f8805f2a5101e89356e9411d908a0c (patch)
treefaea38f1c86dae9f6d4b143b2aa9f7752ecd0a34
parent095ccaedd0631462c52a1a2d9aa19b35c3e45b12 (diff)
downloadopenbsd-8a7c8abfd4f8805f2a5101e89356e9411d908a0c.tar.gz
openbsd-8a7c8abfd4f8805f2a5101e89356e9411d908a0c.tar.bz2
openbsd-8a7c8abfd4f8805f2a5101e89356e9411d908a0c.zip
Change bn_expand()/bn_wexpand() to indicate failure/success via 0/1.
Currently bn_expand()/bn_wexpand() return a BIGNUM *, however none of the callers use this (and many already treat it as a true/false value). Change these functions to return 0 on failure and 1 on success, revising callers that test against NULL in the process. ok tb@
-rw-r--r--src/lib/libcrypto/bn/bn_add.c6
-rw-r--r--src/lib/libcrypto/bn/bn_div.c6
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c4
-rw-r--r--src/lib/libcrypto/bn/bn_gf2m.c4
-rw-r--r--src/lib/libcrypto/bn/bn_lcl.h6
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c36
-rw-r--r--src/lib/libcrypto/bn/bn_mont.c10
-rw-r--r--src/lib/libcrypto/bn/bn_mul.c28
-rw-r--r--src/lib/libcrypto/bn/bn_print.c6
-rw-r--r--src/lib/libcrypto/bn/bn_shift.c12
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c10
-rw-r--r--src/lib/libcrypto/bn/bn_word.c6
-rw-r--r--src/lib/libcrypto/ec/ec2_smpl.c10
-rw-r--r--src/lib/libcrypto/ec/ecp_nistz256.c4
-rw-r--r--src/lib/libcrypto/ec/ecp_smpl.c18
15 files changed, 83 insertions, 83 deletions
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c
index 048a136b95..3a8c0e847a 100644
--- a/src/lib/libcrypto/bn/bn_add.c
+++ b/src/lib/libcrypto/bn/bn_add.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_add.c,v 1.13 2018/07/23 18:07:21 tb Exp $ */ 1/* $OpenBSD: bn_add.c,v 1.14 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -115,7 +115,7 @@ BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
115 min = b->top; 115 min = b->top;
116 dif = max - min; 116 dif = max - min;
117 117
118 if (bn_wexpand(r, max + 1) == NULL) 118 if (!bn_wexpand(r, max + 1))
119 return 0; 119 return 0;
120 120
121 r->top = max; 121 r->top = max;
@@ -162,7 +162,7 @@ BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
162 return 0; 162 return 0;
163 } 163 }
164 164
165 if (bn_wexpand(r, max) == NULL) 165 if (!bn_wexpand(r, max))
166 return 0; 166 return 0;
167 167
168 ap = a->d; 168 ap = a->d;
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c
index f3a97bcc8d..f641386eb8 100644
--- a/src/lib/libcrypto/bn/bn_div.c
+++ b/src/lib/libcrypto/bn/bn_div.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_div.c,v 1.25 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: bn_div.c,v 1.26 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -187,13 +187,13 @@ BN_div_internal(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor
187 * value. 187 * value.
188 */ 188 */
189 if (snum->top <= sdiv->top + 1) { 189 if (snum->top <= sdiv->top + 1) {
190 if (bn_wexpand(snum, sdiv->top + 2) == NULL) 190 if (!bn_wexpand(snum, sdiv->top + 2))
191 goto err; 191 goto err;
192 for (i = snum->top; i < sdiv->top + 2; i++) 192 for (i = snum->top; i < sdiv->top + 2; i++)
193 snum->d[i] = 0; 193 snum->d[i] = 0;
194 snum->top = sdiv->top + 2; 194 snum->top = sdiv->top + 2;
195 } else { 195 } else {
196 if (bn_wexpand(snum, snum->top + 1) == NULL) 196 if (!bn_wexpand(snum, snum->top + 1))
197 goto err; 197 goto err;
198 snum->d[snum->top] = 0; 198 snum->d[snum->top] = 0;
199 snum->top ++; 199 snum->top ++;
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
index 3525b50388..64156f716f 100644
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ b/src/lib/libcrypto/bn/bn_exp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_exp.c,v 1.32 2022/04/20 13:32:34 tb Exp $ */ 1/* $OpenBSD: bn_exp.c,v 1.33 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -590,7 +590,7 @@ MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, int top, unsigned char *buf, int idx,
590 int width = 1 << window; 590 int width = 1 << window;
591 volatile BN_ULONG *table = (volatile BN_ULONG *)buf; 591 volatile BN_ULONG *table = (volatile BN_ULONG *)buf;
592 592
593 if (bn_wexpand(b, top) == NULL) 593 if (!bn_wexpand(b, top))
594 return 0; 594 return 0;
595 595
596 if (window <= 3) { 596 if (window <= 3) {
diff --git a/src/lib/libcrypto/bn/bn_gf2m.c b/src/lib/libcrypto/bn/bn_gf2m.c
index b9e3ba8566..eceaba47c3 100644
--- a/src/lib/libcrypto/bn/bn_gf2m.c
+++ b/src/lib/libcrypto/bn/bn_gf2m.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_gf2m.c,v 1.25 2022/11/20 23:35:00 schwarze Exp $ */ 1/* $OpenBSD: bn_gf2m.c,v 1.26 2022/11/24 01:30:01 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -336,7 +336,7 @@ BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
336 bt = b; 336 bt = b;
337 } 337 }
338 338
339 if (bn_wexpand(r, at->top) == NULL) 339 if (!bn_wexpand(r, at->top))
340 return 0; 340 return 0;
341 341
342 for (i = 0; i < bt->top; i++) { 342 for (i = 0; i < bt->top; i++) {
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h
index 63289f66fb..d5f1250cfd 100644
--- a/src/lib/libcrypto/bn/bn_lcl.h
+++ b/src/lib/libcrypto/bn/bn_lcl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_lcl.h,v 1.37 2022/11/23 03:00:12 jsing Exp $ */ 1/* $OpenBSD: bn_lcl.h,v 1.38 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -521,8 +521,8 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
521 int cl, int dl); 521 int cl, int dl);
522int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num); 522int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num);
523 523
524BIGNUM *bn_expand(BIGNUM *a, int bits); 524int bn_expand(BIGNUM *a, int bits);
525BIGNUM *bn_wexpand(BIGNUM *a, int words); 525int bn_wexpand(BIGNUM *a, int words);
526 526
527/* Bignum consistency macros 527/* Bignum consistency macros
528 * There is one "API" macro, bn_fix_top(), for stripping leading zeroes from 528 * There is one "API" macro, bn_fix_top(), for stripping leading zeroes from
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index 1c079b004a..e67abf90b1 100644
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ b/src/lib/libcrypto/bn/bn_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_lib.c,v 1.60 2022/11/23 03:10:10 jsing Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.61 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -334,15 +334,15 @@ bn_expand_internal(const BIGNUM *b, int words)
334 * It is mostly used by the various BIGNUM routines. If there is an error, 334 * It is mostly used by the various BIGNUM routines. If there is an error,
335 * NULL is returned. If not, 'b' is returned. */ 335 * NULL is returned. If not, 'b' is returned. */
336 336
337static BIGNUM * 337static int
338bn_expand2(BIGNUM *b, int words) 338bn_expand2(BIGNUM *b, int words)
339{ 339{
340 bn_check_top(b); 340 bn_check_top(b);
341 341
342 if (words > b->dmax) { 342 if (words > b->dmax) {
343 BN_ULONG *a = bn_expand_internal(b, words); 343 BN_ULONG *a = bn_expand_internal(b, words);
344 if (!a) 344 if (a == NULL)
345 return NULL; 345 return 0;
346 if (b->d) 346 if (b->d)
347 freezero(b->d, b->dmax * sizeof(b->d[0])); 347 freezero(b->d, b->dmax * sizeof(b->d[0]));
348 b->d = a; 348 b->d = a;
@@ -371,32 +371,32 @@ bn_expand2(BIGNUM *b, int words)
371 } 371 }
372#endif 372#endif
373 bn_check_top(b); 373 bn_check_top(b);
374 return b; 374 return 1;
375} 375}
376 376
377BIGNUM * 377int
378bn_expand(BIGNUM *a, int bits) 378bn_expand(BIGNUM *a, int bits)
379{ 379{
380 if (bits < 0) 380 if (bits < 0)
381 return (NULL); 381 return 0;
382 382
383 if (bits > (INT_MAX - BN_BITS2 + 1)) 383 if (bits > (INT_MAX - BN_BITS2 + 1))
384 return (NULL); 384 return 0;
385 385
386 if (((bits + BN_BITS2 - 1) / BN_BITS2) <= a->dmax) 386 if (((bits + BN_BITS2 - 1) / BN_BITS2) <= a->dmax)
387 return (a); 387 return 1;
388 388
389 return bn_expand2(a, (bits + BN_BITS2 - 1) / BN_BITS2); 389 return bn_expand2(a, (bits + BN_BITS2 - 1) / BN_BITS2);
390} 390}
391 391
392BIGNUM * 392int
393bn_wexpand(BIGNUM *a, int words) 393bn_wexpand(BIGNUM *a, int words)
394{ 394{
395 if (words < 0) 395 if (words < 0)
396 return NULL; 396 return 0;
397 397
398 if (words <= a->dmax) 398 if (words <= a->dmax)
399 return a; 399 return 1;
400 400
401 return bn_expand2(a, words); 401 return bn_expand2(a, words);
402} 402}
@@ -432,7 +432,7 @@ BN_copy(BIGNUM *a, const BIGNUM *b)
432 432
433 if (a == b) 433 if (a == b)
434 return (a); 434 return (a);
435 if (bn_wexpand(a, b->top) == NULL) 435 if (!bn_wexpand(a, b->top))
436 return (NULL); 436 return (NULL);
437 437
438#if 1 438#if 1
@@ -518,7 +518,7 @@ int
518BN_set_word(BIGNUM *a, BN_ULONG w) 518BN_set_word(BIGNUM *a, BN_ULONG w)
519{ 519{
520 bn_check_top(a); 520 bn_check_top(a);
521 if (bn_wexpand(a, 1) == NULL) 521 if (!bn_wexpand(a, 1))
522 return (0); 522 return (0);
523 a->neg = 0; 523 a->neg = 0;
524 a->d[0] = w; 524 a->d[0] = w;
@@ -550,7 +550,7 @@ BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
550 } 550 }
551 i = ((n - 1) / BN_BYTES) + 1; 551 i = ((n - 1) / BN_BYTES) + 1;
552 m = ((n - 1) % (BN_BYTES)); 552 m = ((n - 1) % (BN_BYTES));
553 if (bn_wexpand(ret, (int)i) == NULL) { 553 if (!bn_wexpand(ret, (int)i)) {
554 BN_free(bn); 554 BN_free(bn);
555 return NULL; 555 return NULL;
556 } 556 }
@@ -673,7 +673,7 @@ BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret)
673 673
674 i = ((n - 1) / BN_BYTES) + 1; 674 i = ((n - 1) / BN_BYTES) + 1;
675 m = (n - 1) % BN_BYTES; 675 m = (n - 1) % BN_BYTES;
676 if (bn_wexpand(ret, (int)i) == NULL) { 676 if (!bn_wexpand(ret, (int)i)) {
677 BN_free(bn); 677 BN_free(bn);
678 return NULL; 678 return NULL;
679 } 679 }
@@ -791,7 +791,7 @@ BN_set_bit(BIGNUM *a, int n)
791 i = n / BN_BITS2; 791 i = n / BN_BITS2;
792 j = n % BN_BITS2; 792 j = n % BN_BITS2;
793 if (a->top <= i) { 793 if (a->top <= i) {
794 if (bn_wexpand(a, i + 1) == NULL) 794 if (!bn_wexpand(a, i + 1))
795 return (0); 795 return (0);
796 for (k = a->top; k < i + 1; k++) 796 for (k = a->top; k < i + 1; k++)
797 a->d[k] = 0; 797 a->d[k] = 0;
@@ -989,7 +989,7 @@ BN_swap_ct(BN_ULONG condition, BIGNUM *a, BIGNUM *b, size_t nwords)
989 if (nwords > INT_MAX) 989 if (nwords > INT_MAX)
990 return 0; 990 return 0;
991 words = (int)nwords; 991 words = (int)nwords;
992 if (bn_wexpand(a, words) == NULL || bn_wexpand(b, words) == NULL) 992 if (!bn_wexpand(a, words) || !bn_wexpand(b, words))
993 return 0; 993 return 0;
994 if (a->top > words || b->top > words) { 994 if (a->top > words || b->top > words) {
995 BNerror(BN_R_INVALID_LENGTH); 995 BNerror(BN_R_INVALID_LENGTH);
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c
index 4555f6146b..251c67b89d 100644
--- a/src/lib/libcrypto/bn/bn_mont.c
+++ b/src/lib/libcrypto/bn/bn_mont.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_mont.c,v 1.29 2022/11/23 03:10:10 jsing Exp $ */ 1/* $OpenBSD: bn_mont.c,v 1.30 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -137,7 +137,7 @@ BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
137 int num = mont->N.top; 137 int num = mont->N.top;
138 138
139 if (num > 1 && a->top == num && b->top == num) { 139 if (num > 1 && a->top == num && b->top == num) {
140 if (bn_wexpand(r, num) == NULL) 140 if (!bn_wexpand(r, num))
141 return (0); 141 return (0);
142 if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) { 142 if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {
143 r->neg = a->neg^b->neg; 143 r->neg = a->neg^b->neg;
@@ -197,7 +197,7 @@ BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
197 } 197 }
198 198
199 max = (2 * nl); /* carry is stored separately */ 199 max = (2 * nl); /* carry is stored separately */
200 if (bn_wexpand(r, max) == NULL) 200 if (!bn_wexpand(r, max))
201 return (0); 201 return (0);
202 202
203 r->neg ^= n->neg; 203 r->neg ^= n->neg;
@@ -226,7 +226,7 @@ BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
226 rp[nl] = v; 226 rp[nl] = v;
227 } 227 }
228 228
229 if (bn_wexpand(ret, nl) == NULL) 229 if (!bn_wexpand(ret, nl))
230 return (0); 230 return (0);
231 ret->top = nl; 231 ret->top = nl;
232 ret->neg = r->neg; 232 ret->neg = r->neg;
@@ -419,7 +419,7 @@ BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
419 } 419 }
420 else /* if N mod word size == 1 */ 420 else /* if N mod word size == 1 */
421 { 421 {
422 if (bn_wexpand(Ri, 2) == NULL) 422 if (!bn_wexpand(Ri, 2))
423 goto err; 423 goto err;
424 /* Ri-- (mod double word size) */ 424 /* Ri-- (mod double word size) */
425 Ri->neg = 0; 425 Ri->neg = 0;
diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c
index 7794d59707..fa9d559da9 100644
--- a/src/lib/libcrypto/bn/bn_mul.c
+++ b/src/lib/libcrypto/bn/bn_mul.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_mul.c,v 1.20 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: bn_mul.c,v 1.21 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -982,7 +982,7 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
982 if (i == 0) { 982 if (i == 0) {
983# if 0 983# if 0
984 if (al == 4) { 984 if (al == 4) {
985 if (bn_wexpand(rr, 8) == NULL) 985 if (!bn_wexpand(rr, 8))
986 goto err; 986 goto err;
987 rr->top = 8; 987 rr->top = 8;
988 bn_mul_comba4(rr->d, a->d, b->d); 988 bn_mul_comba4(rr->d, a->d, b->d);
@@ -990,7 +990,7 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
990 } 990 }
991# endif 991# endif
992 if (al == 8) { 992 if (al == 8) {
993 if (bn_wexpand(rr, 16) == NULL) 993 if (!bn_wexpand(rr, 16))
994 goto err; 994 goto err;
995 rr->top = 16; 995 rr->top = 16;
996 bn_mul_comba8(rr->d, a->d, b->d); 996 bn_mul_comba8(rr->d, a->d, b->d);
@@ -1015,18 +1015,18 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1015 if ((t = BN_CTX_get(ctx)) == NULL) 1015 if ((t = BN_CTX_get(ctx)) == NULL)
1016 goto err; 1016 goto err;
1017 if (al > j || bl > j) { 1017 if (al > j || bl > j) {
1018 if (bn_wexpand(t, k * 4) == NULL) 1018 if (!bn_wexpand(t, k * 4))
1019 goto err; 1019 goto err;
1020 if (bn_wexpand(rr, k * 4) == NULL) 1020 if (!bn_wexpand(rr, k * 4))
1021 goto err; 1021 goto err;
1022 bn_mul_part_recursive(rr->d, a->d, b->d, 1022 bn_mul_part_recursive(rr->d, a->d, b->d,
1023 j, al - j, bl - j, t->d); 1023 j, al - j, bl - j, t->d);
1024 } 1024 }
1025 else /* al <= j || bl <= j */ 1025 else /* al <= j || bl <= j */
1026 { 1026 {
1027 if (bn_wexpand(t, k * 2) == NULL) 1027 if (!bn_wexpand(t, k * 2))
1028 goto err; 1028 goto err;
1029 if (bn_wexpand(rr, k * 2) == NULL) 1029 if (!bn_wexpand(rr, k * 2))
1030 goto err; 1030 goto err;
1031 bn_mul_recursive(rr->d, a->d, b->d, 1031 bn_mul_recursive(rr->d, a->d, b->d,
1032 j, al - j, bl - j, t->d); 1032 j, al - j, bl - j, t->d);
@@ -1037,14 +1037,14 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1037#if 0 1037#if 0
1038 if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) { 1038 if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {
1039 BIGNUM *tmp_bn = (BIGNUM *)b; 1039 BIGNUM *tmp_bn = (BIGNUM *)b;
1040 if (bn_wexpand(tmp_bn, al) == NULL) 1040 if (!bn_wexpand(tmp_bn, al))
1041 goto err; 1041 goto err;
1042 tmp_bn->d[bl] = 0; 1042 tmp_bn->d[bl] = 0;
1043 bl++; 1043 bl++;
1044 i--; 1044 i--;
1045 } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) { 1045 } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {
1046 BIGNUM *tmp_bn = (BIGNUM *)a; 1046 BIGNUM *tmp_bn = (BIGNUM *)a;
1047 if (bn_wexpand(tmp_bn, bl) == NULL) 1047 if (!bn_wexpand(tmp_bn, bl))
1048 goto err; 1048 goto err;
1049 tmp_bn->d[al] = 0; 1049 tmp_bn->d[al] = 0;
1050 al++; 1050 al++;
@@ -1060,15 +1060,15 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1060 goto err; 1060 goto err;
1061 if (al == j) /* exact multiple */ 1061 if (al == j) /* exact multiple */
1062 { 1062 {
1063 if (bn_wexpand(t, k * 2) == NULL) 1063 if (!bn_wexpand(t, k * 2))
1064 goto err; 1064 goto err;
1065 if (bn_wexpand(rr, k * 2) == NULL) 1065 if (!bn_wexpand(rr, k * 2))
1066 goto err; 1066 goto err;
1067 bn_mul_recursive(rr->d, a->d, b->d, al, t->d); 1067 bn_mul_recursive(rr->d, a->d, b->d, al, t->d);
1068 } else { 1068 } else {
1069 if (bn_wexpand(t, k * 4) == NULL) 1069 if (!bn_wexpand(t, k * 4))
1070 goto err; 1070 goto err;
1071 if (bn_wexpand(rr, k * 4) == NULL) 1071 if (!bn_wexpand(rr, k * 4))
1072 goto err; 1072 goto err;
1073 bn_mul_part_recursive(rr->d, a->d, b->d, 1073 bn_mul_part_recursive(rr->d, a->d, b->d,
1074 al - j, j, t->d); 1074 al - j, j, t->d);
@@ -1079,7 +1079,7 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1079#endif 1079#endif
1080 } 1080 }
1081#endif /* BN_RECURSION */ 1081#endif /* BN_RECURSION */
1082 if (bn_wexpand(rr, top) == NULL) 1082 if (!bn_wexpand(rr, top))
1083 goto err; 1083 goto err;
1084 rr->top = top; 1084 rr->top = top;
1085 bn_mul_normal(rr->d, a->d, al, b->d, bl); 1085 bn_mul_normal(rr->d, a->d, al, b->d, bl);
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c
index 584903491f..ad2e3ba16c 100644
--- a/src/lib/libcrypto/bn/bn_print.c
+++ b/src/lib/libcrypto/bn/bn_print.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_print.c,v 1.34 2022/11/22 08:46:27 tb Exp $ */ 1/* $OpenBSD: bn_print.c,v 1.35 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -221,7 +221,7 @@ BN_hex2bn(BIGNUM **bn, const char *a)
221 } 221 }
222 222
223 /* i is the number of hex digits */ 223 /* i is the number of hex digits */
224 if (bn_expand(ret, i * 4) == NULL) 224 if (!bn_expand(ret, i * 4))
225 goto err; 225 goto err;
226 226
227 j = i; /* least significant 'hex' */ 227 j = i; /* least significant 'hex' */
@@ -298,7 +298,7 @@ BN_dec2bn(BIGNUM **bn, const char *a)
298 } 298 }
299 299
300 /* i is the number of digits, a bit of an over expand */ 300 /* i is the number of digits, a bit of an over expand */
301 if (bn_expand(ret, i * 4) == NULL) 301 if (!bn_expand(ret, i * 4))
302 goto err; 302 goto err;
303 303
304 j = BN_DEC_NUM - (i % BN_DEC_NUM); 304 j = BN_DEC_NUM - (i % BN_DEC_NUM);
diff --git a/src/lib/libcrypto/bn/bn_shift.c b/src/lib/libcrypto/bn/bn_shift.c
index e89e157446..e2612d1e9d 100644
--- a/src/lib/libcrypto/bn/bn_shift.c
+++ b/src/lib/libcrypto/bn/bn_shift.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_shift.c,v 1.14 2022/06/22 09:03:06 tb Exp $ */ 1/* $OpenBSD: bn_shift.c,v 1.15 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -74,11 +74,11 @@ BN_lshift1(BIGNUM *r, const BIGNUM *a)
74 74
75 if (r != a) { 75 if (r != a) {
76 r->neg = a->neg; 76 r->neg = a->neg;
77 if (bn_wexpand(r, a->top + 1) == NULL) 77 if (!bn_wexpand(r, a->top + 1))
78 return (0); 78 return (0);
79 r->top = a->top; 79 r->top = a->top;
80 } else { 80 } else {
81 if (bn_wexpand(r, a->top + 1) == NULL) 81 if (!bn_wexpand(r, a->top + 1))
82 return (0); 82 return (0);
83 } 83 }
84 ap = a->d; 84 ap = a->d;
@@ -114,7 +114,7 @@ BN_rshift1(BIGNUM *r, const BIGNUM *a)
114 ap = a->d; 114 ap = a->d;
115 j = i - (ap[i - 1]==1); 115 j = i - (ap[i - 1]==1);
116 if (a != r) { 116 if (a != r) {
117 if (bn_wexpand(r, j) == NULL) 117 if (!bn_wexpand(r, j))
118 return (0); 118 return (0);
119 r->neg = a->neg; 119 r->neg = a->neg;
120 } 120 }
@@ -150,7 +150,7 @@ BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
150 150
151 r->neg = a->neg; 151 r->neg = a->neg;
152 nw = n / BN_BITS2; 152 nw = n / BN_BITS2;
153 if (bn_wexpand(r, a->top + nw + 1) == NULL) 153 if (!bn_wexpand(r, a->top + nw + 1))
154 return (0); 154 return (0);
155 lb = n % BN_BITS2; 155 lb = n % BN_BITS2;
156 rb = BN_BITS2 - lb; 156 rb = BN_BITS2 - lb;
@@ -200,7 +200,7 @@ BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
200 i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2; 200 i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;
201 if (r != a) { 201 if (r != a) {
202 r->neg = a->neg; 202 r->neg = a->neg;
203 if (bn_wexpand(r, i) == NULL) 203 if (!bn_wexpand(r, i))
204 return (0); 204 return (0);
205 } else { 205 } else {
206 if (n == 0) 206 if (n == 0)
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c
index bdfeda5c66..36b3965207 100644
--- a/src/lib/libcrypto/bn/bn_sqr.c
+++ b/src/lib/libcrypto/bn/bn_sqr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_sqr.c,v 1.13 2022/11/22 20:43:43 tb Exp $ */ 1/* $OpenBSD: bn_sqr.c,v 1.14 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -88,7 +88,7 @@ BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
88 goto err; 88 goto err;
89 89
90 max = 2 * al; /* Non-zero (from above) */ 90 max = 2 * al; /* Non-zero (from above) */
91 if (bn_wexpand(rr, max) == NULL) 91 if (!bn_wexpand(rr, max))
92 goto err; 92 goto err;
93 93
94 if (al == 4) { 94 if (al == 4) {
@@ -117,17 +117,17 @@ BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
117 j = 1 << (j - 1); 117 j = 1 << (j - 1);
118 k = j + j; 118 k = j + j;
119 if (al == j) { 119 if (al == j) {
120 if (bn_wexpand(tmp, k * 2) == NULL) 120 if (!bn_wexpand(tmp, k * 2))
121 goto err; 121 goto err;
122 bn_sqr_recursive(rr->d, a->d, al, tmp->d); 122 bn_sqr_recursive(rr->d, a->d, al, tmp->d);
123 } else { 123 } else {
124 if (bn_wexpand(tmp, max) == NULL) 124 if (!bn_wexpand(tmp, max))
125 goto err; 125 goto err;
126 bn_sqr_normal(rr->d, a->d, al, tmp->d); 126 bn_sqr_normal(rr->d, a->d, al, tmp->d);
127 } 127 }
128 } 128 }
129#else 129#else
130 if (bn_wexpand(tmp, max) == NULL) 130 if (!bn_wexpand(tmp, max))
131 goto err; 131 goto err;
132 bn_sqr_normal(rr->d, a->d, al, tmp->d); 132 bn_sqr_normal(rr->d, a->d, al, tmp->d);
133#endif 133#endif
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
index 71654586a1..683668c52d 100644
--- a/src/lib/libcrypto/bn/bn_word.c
+++ b/src/lib/libcrypto/bn/bn_word.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_word.c,v 1.13 2016/07/05 02:54:35 bcook Exp $ */ 1/* $OpenBSD: bn_word.c,v 1.14 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -166,7 +166,7 @@ BN_add_word(BIGNUM *a, BN_ULONG w)
166 w = (w > l) ? 1 : 0; 166 w = (w > l) ? 1 : 0;
167 } 167 }
168 if (w && i == a->top) { 168 if (w && i == a->top) {
169 if (bn_wexpand(a, a->top + 1) == NULL) 169 if (!bn_wexpand(a, a->top + 1))
170 return 0; 170 return 0;
171 a->top++; 171 a->top++;
172 a->d[i] = w; 172 a->d[i] = w;
@@ -236,7 +236,7 @@ BN_mul_word(BIGNUM *a, BN_ULONG w)
236 else { 236 else {
237 ll = bn_mul_words(a->d, a->d, a->top, w); 237 ll = bn_mul_words(a->d, a->d, a->top, w);
238 if (ll) { 238 if (ll) {
239 if (bn_wexpand(a, a->top + 1) == NULL) 239 if (!bn_wexpand(a, a->top + 1))
240 return (0); 240 return (0);
241 a->d[a->top++] = ll; 241 a->d[a->top++] = ll;
242 } 242 }
diff --git a/src/lib/libcrypto/ec/ec2_smpl.c b/src/lib/libcrypto/ec/ec2_smpl.c
index b6c06a45a2..b4d7f5db2e 100644
--- a/src/lib/libcrypto/ec/ec2_smpl.c
+++ b/src/lib/libcrypto/ec/ec2_smpl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec2_smpl.c,v 1.26 2022/11/24 01:24:37 jsing Exp $ */ 1/* $OpenBSD: ec2_smpl.c,v 1.27 2022/11/24 01:30:01 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -186,9 +186,9 @@ ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
186 dest->poly[3] = src->poly[3]; 186 dest->poly[3] = src->poly[3];
187 dest->poly[4] = src->poly[4]; 187 dest->poly[4] = src->poly[4];
188 dest->poly[5] = src->poly[5]; 188 dest->poly[5] = src->poly[5];
189 if (bn_expand(&dest->a, dest->poly[0]) == NULL) 189 if (!bn_expand(&dest->a, dest->poly[0]))
190 return 0; 190 return 0;
191 if (bn_expand(&dest->b, dest->poly[0]) == NULL) 191 if (!bn_expand(&dest->b, dest->poly[0]))
192 return 0; 192 return 0;
193 for (i = dest->a.top; i < dest->a.dmax; i++) 193 for (i = dest->a.top; i < dest->a.dmax; i++)
194 dest->a.d[i] = 0; 194 dest->a.d[i] = 0;
@@ -216,7 +216,7 @@ ec_GF2m_simple_group_set_curve(EC_GROUP *group,
216 /* group->a */ 216 /* group->a */
217 if (!BN_GF2m_mod_arr(&group->a, a, group->poly)) 217 if (!BN_GF2m_mod_arr(&group->a, a, group->poly))
218 goto err; 218 goto err;
219 if (bn_expand(&group->a, group->poly[0]) == NULL) 219 if (!bn_expand(&group->a, group->poly[0]))
220 goto err; 220 goto err;
221 for (i = group->a.top; i < group->a.dmax; i++) 221 for (i = group->a.top; i < group->a.dmax; i++)
222 group->a.d[i] = 0; 222 group->a.d[i] = 0;
@@ -224,7 +224,7 @@ ec_GF2m_simple_group_set_curve(EC_GROUP *group,
224 /* group->b */ 224 /* group->b */
225 if (!BN_GF2m_mod_arr(&group->b, b, group->poly)) 225 if (!BN_GF2m_mod_arr(&group->b, b, group->poly))
226 goto err; 226 goto err;
227 if (bn_expand(&group->b, group->poly[0]) == NULL) 227 if (!bn_expand(&group->b, group->poly[0]))
228 goto err; 228 goto err;
229 for (i = group->b.top; i < group->b.dmax; i++) 229 for (i = group->b.top; i < group->b.dmax; i++)
230 group->b.d[i] = 0; 230 group->b.d[i] = 0;
diff --git a/src/lib/libcrypto/ec/ecp_nistz256.c b/src/lib/libcrypto/ec/ecp_nistz256.c
index e4929b92bb..e3a6cc855a 100644
--- a/src/lib/libcrypto/ec/ecp_nistz256.c
+++ b/src/lib/libcrypto/ec/ecp_nistz256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistz256.c,v 1.12 2022/11/19 07:00:57 tb Exp $ */ 1/* $OpenBSD: ecp_nistz256.c,v 1.13 2022/11/24 01:30:01 jsing Exp $ */
2/* Copyright (c) 2014, Intel Corporation. 2/* Copyright (c) 2014, Intel Corporation.
3 * 3 *
4 * Permission to use, copy, modify, and/or distribute this software for any 4 * Permission to use, copy, modify, and/or distribute this software for any
@@ -310,7 +310,7 @@ is_one(const BIGNUM *z)
310static int 310static int
311ecp_nistz256_set_words(BIGNUM *a, BN_ULONG words[P256_LIMBS]) 311ecp_nistz256_set_words(BIGNUM *a, BN_ULONG words[P256_LIMBS])
312{ 312{
313 if (bn_wexpand(a, P256_LIMBS) == NULL) { 313 if (!bn_wexpand(a, P256_LIMBS)) {
314 ECerror(ERR_R_MALLOC_FAILURE); 314 ECerror(ERR_R_MALLOC_FAILURE);
315 return 0; 315 return 0;
316 } 316 }
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c
index 55fb46869d..71d403b854 100644
--- a/src/lib/libcrypto/ec/ecp_smpl.c
+++ b/src/lib/libcrypto/ec/ecp_smpl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_smpl.c,v 1.36 2022/11/19 07:29:29 tb Exp $ */ 1/* $OpenBSD: ecp_smpl.c,v 1.37 2022/11/24 01:30:01 jsing Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. 3 * for the OpenSSL project.
4 * Includes code written by Bodo Moeller for the OpenSSL project. 4 * Includes code written by Bodo Moeller for the OpenSSL project.
@@ -1556,8 +1556,8 @@ ec_GFp_simple_mul_ct(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
1556 */ 1556 */
1557 cardinality_bits = BN_num_bits(cardinality); 1557 cardinality_bits = BN_num_bits(cardinality);
1558 group_top = cardinality->top; 1558 group_top = cardinality->top;
1559 if ((bn_wexpand(k, group_top + 2) == NULL) || 1559 if (!bn_wexpand(k, group_top + 2) ||
1560 (bn_wexpand(lambda, group_top + 2) == NULL)) 1560 !bn_wexpand(lambda, group_top + 2))
1561 goto err; 1561 goto err;
1562 1562
1563 if (!BN_copy(k, scalar)) 1563 if (!BN_copy(k, scalar))
@@ -1588,12 +1588,12 @@ ec_GFp_simple_mul_ct(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
1588 goto err; 1588 goto err;
1589 1589
1590 group_top = group->field.top; 1590 group_top = group->field.top;
1591 if ((bn_wexpand(&s->X, group_top) == NULL) || 1591 if (!bn_wexpand(&s->X, group_top) ||
1592 (bn_wexpand(&s->Y, group_top) == NULL) || 1592 !bn_wexpand(&s->Y, group_top) ||
1593 (bn_wexpand(&s->Z, group_top) == NULL) || 1593 !bn_wexpand(&s->Z, group_top) ||
1594 (bn_wexpand(&r->X, group_top) == NULL) || 1594 !bn_wexpand(&r->X, group_top) ||
1595 (bn_wexpand(&r->Y, group_top) == NULL) || 1595 !bn_wexpand(&r->Y, group_top) ||
1596 (bn_wexpand(&r->Z, group_top) == NULL)) 1596 !bn_wexpand(&r->Z, group_top))
1597 goto err; 1597 goto err;
1598 1598
1599 /* 1599 /*