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@
-/* $OpenBSD: bn_lib.c,v 1.75 2023/02/14 18:06:06 jsing Exp $ */
+/* $OpenBSD: bn_lib.c,v 1.76 2023/02/14 18:22:35 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
{
int i = a->top - 1;
-
if (BN_is_zero(a))
return 0;
return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
}
int
-BN_is_zero(const BIGNUM *a)
+BN_is_zero(const BIGNUM *bn)
{
- return a->top == 0;
+ BN_ULONG bits = 0;
+ int i;
+
+ for (i = 0; i < bn->top; i++)
+ bits |= bn->d[i];
+
+ return bits == 0;
}
int