summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2023-02-14 18:22:35 +0000
committerjsing <>2023-02-14 18:22:35 +0000
commitc6e3089538d69e8e70c037404ec0d7cb5bcece4d (patch)
tree9920ce0f43d626c04695693d0578cf7c14df80c9 /src
parent9ce34d33ab5e28ffa5d1cd29ccc09a8651396e96 (diff)
downloadopenbsd-c6e3089538d69e8e70c037404ec0d7cb5bcece4d.tar.gz
openbsd-c6e3089538d69e8e70c037404ec0d7cb5bcece4d.tar.bz2
openbsd-c6e3089538d69e8e70c037404ec0d7cb5bcece4d.zip
Make BN_is_zero() check word values.
Rather than completely relying on top, check the words of a bignum. This gets us one step away from being dependent on top and additionally means that we correctly report zero even if top is not yet correct. ok tb@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index b792250fbc..89e2713a0f 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.75 2023/02/14 18:06:06 jsing Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.76 2023/02/14 18:22:35 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 *
@@ -252,7 +252,6 @@ BN_num_bits(const BIGNUM *a)
252{ 252{
253 int i = a->top - 1; 253 int i = a->top - 1;
254 254
255
256 if (BN_is_zero(a)) 255 if (BN_is_zero(a))
257 return 0; 256 return 0;
258 return ((i * BN_BITS2) + BN_num_bits_word(a->d[i])); 257 return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
@@ -917,9 +916,15 @@ BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)
917} 916}
918 917
919int 918int
920BN_is_zero(const BIGNUM *a) 919BN_is_zero(const BIGNUM *bn)
921{ 920{
922 return a->top == 0; 921 BN_ULONG bits = 0;
922 int i;
923
924 for (i = 0; i < bn->top; i++)
925 bits |= bn->d[i];
926
927 return bits == 0;
923} 928}
924 929
925int 930int