From 8a7c8abfd4f8805f2a5101e89356e9411d908a0c Mon Sep 17 00:00:00 2001
From: jsing <>
Date: Thu, 24 Nov 2022 01:30:01 +0000
Subject: 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@
---
 src/lib/libcrypto/bn/bn_add.c       |  6 +++---
 src/lib/libcrypto/bn/bn_div.c       |  6 +++---
 src/lib/libcrypto/bn/bn_exp.c       |  4 ++--
 src/lib/libcrypto/bn/bn_gf2m.c      |  4 ++--
 src/lib/libcrypto/bn/bn_lcl.h       |  6 +++---
 src/lib/libcrypto/bn/bn_lib.c       | 36 ++++++++++++++++++------------------
 src/lib/libcrypto/bn/bn_mont.c      | 10 +++++-----
 src/lib/libcrypto/bn/bn_mul.c       | 28 ++++++++++++++--------------
 src/lib/libcrypto/bn/bn_print.c     |  6 +++---
 src/lib/libcrypto/bn/bn_shift.c     | 12 ++++++------
 src/lib/libcrypto/bn/bn_sqr.c       | 10 +++++-----
 src/lib/libcrypto/bn/bn_word.c      |  6 +++---
 src/lib/libcrypto/ec/ec2_smpl.c     | 10 +++++-----
 src/lib/libcrypto/ec/ecp_nistz256.c |  4 ++--
 src/lib/libcrypto/ec/ecp_smpl.c     | 18 +++++++++---------
 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 @@
-/* $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.
  *
@@ -115,7 +115,7 @@ BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
 	min = b->top;
 	dif = max - min;
 
-	if (bn_wexpand(r, max + 1) == NULL)
+	if (!bn_wexpand(r, max + 1))
 		return 0;
 
 	r->top = max;
@@ -162,7 +162,7 @@ BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
 		return 0;
 	}
 
-	if (bn_wexpand(r, max) == NULL)
+	if (!bn_wexpand(r, max))
 		return 0;
 
 	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 @@
-/* $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.
  *
@@ -187,13 +187,13 @@ BN_div_internal(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor
 		 * 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 ++;
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 @@
-/* $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.
  *
@@ -590,7 +590,7 @@ MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, int top, unsigned char *buf, int idx,
 	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) {
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 @@
-/* $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.
  *
@@ -336,7 +336,7 @@ BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
 		bt = b;
 	}
 
-	if (bn_wexpand(r, at->top) == NULL)
+	if (!bn_wexpand(r, at->top))
 		return 0;
 
 	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 @@
-/* $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.
  *
@@ -521,8 +521,8 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
     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
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 @@
-/* $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.
  *
@@ -334,15 +334,15 @@ bn_expand_internal(const BIGNUM *b, int words)
  * 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;
@@ -371,32 +371,32 @@ bn_expand2(BIGNUM *b, int words)
 	}
 #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);
 }
@@ -432,7 +432,7 @@ BN_copy(BIGNUM *a, const BIGNUM *b)
 
 	if (a == b)
 		return (a);
-	if (bn_wexpand(a, b->top) == NULL)
+	if (!bn_wexpand(a, b->top))
 		return (NULL);
 
 #if 1
@@ -518,7 +518,7 @@ int
 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;
@@ -550,7 +550,7 @@ BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
 	}
 	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;
 	}
@@ -673,7 +673,7 @@ BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret)
 
 	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;
 	}
@@ -791,7 +791,7 @@ BN_set_bit(BIGNUM *a, int n)
 	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;
@@ -989,7 +989,7 @@ BN_swap_ct(BN_ULONG condition, BIGNUM *a, BIGNUM *b, size_t nwords)
 	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);
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 @@
-/* $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.
  *
@@ -137,7 +137,7 @@ BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
 	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;
@@ -197,7 +197,7 @@ BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
 	}
 
 	max = (2 * nl); /* carry is stored separately */
-	if (bn_wexpand(r, max) == NULL)
+	if (!bn_wexpand(r, max))
 		return (0);
 
 	r->neg ^= n->neg;
@@ -226,7 +226,7 @@ BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
 		rp[nl] = v;
 	}
 
-	if (bn_wexpand(ret, nl) == NULL)
+	if (!bn_wexpand(ret, nl))
 		return (0);
 	ret->top = nl;
 	ret->neg = r->neg;
@@ -419,7 +419,7 @@ BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
 		}
 		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;
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 @@
-/* $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.
  *
@@ -982,7 +982,7 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
 	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);
@@ -990,7 +990,7 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
 		}
 # 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);
@@ -1015,18 +1015,18 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
 			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);
@@ -1037,14 +1037,14 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
 #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++;
@@ -1060,15 +1060,15 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
 				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);
@@ -1079,7 +1079,7 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
 #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);
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 @@
-/* $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.
  *
@@ -221,7 +221,7 @@ BN_hex2bn(BIGNUM **bn, const char *a)
 	}
 
 	/* 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' */
@@ -298,7 +298,7 @@ BN_dec2bn(BIGNUM **bn, const char *a)
 	}
 
 	/* 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);
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 @@
-/* $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.
  *
@@ -74,11 +74,11 @@ BN_lshift1(BIGNUM *r, const BIGNUM *a)
 
 	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;
@@ -114,7 +114,7 @@ BN_rshift1(BIGNUM *r, const BIGNUM *a)
 	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;
 	}
@@ -150,7 +150,7 @@ BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
 
 	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;
@@ -200,7 +200,7 @@ BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
 	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)
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 @@
-/* $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.
  *
@@ -88,7 +88,7 @@ BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
 		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) {
@@ -117,17 +117,17 @@ BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
 			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
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 @@
-/* $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.
  *
@@ -166,7 +166,7 @@ BN_add_word(BIGNUM *a, BN_ULONG w)
 		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;
@@ -236,7 +236,7 @@ BN_mul_word(BIGNUM *a, BN_ULONG 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;
 			}
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 @@
-/* $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.
  *
@@ -186,9 +186,9 @@ ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
 	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;
@@ -216,7 +216,7 @@ ec_GF2m_simple_group_set_curve(EC_GROUP *group,
 	/* 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;
@@ -224,7 +224,7 @@ ec_GF2m_simple_group_set_curve(EC_GROUP *group,
 	/* 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;
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 @@
-/*	$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
@@ -310,7 +310,7 @@ is_one(const BIGNUM *z)
 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;
 	}
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 @@
-/* $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.
@@ -1556,8 +1556,8 @@ ec_GFp_simple_mul_ct(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
 	 */
 	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))
@@ -1588,12 +1588,12 @@ ec_GFp_simple_mul_ct(const EC_GROUP *group, EC_POINT *r, const BIGNUM *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;
 
 	/*
-- 
cgit v1.2.3-55-g6feb