From 23fc5ac64685cd972e40475297858f6e68081f5e Mon Sep 17 00:00:00 2001 From: Geoff Thorpe Date: Sun, 30 Nov 2003 22:02:10 +0000 Subject: [PATCH] Improve a couple of the bignum macros. Note, this doesn't eliminate tolerance of ambiguous zero-representation, it just improves BN_abs_is_word() and simplifies other macros that depend on it. --- crypto/bn/bn.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crypto/bn/bn.h b/crypto/bn/bn.h index 5f16fbad00..edf9c3ee75 100644 --- a/crypto/bn/bn.h +++ b/crypto/bn/bn.h @@ -341,12 +341,12 @@ int BN_GENCB_call(BN_GENCB *cb, int a, int b); #define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) -/* Note that BN_abs_is_word does not work reliably for w == 0 */ -#define BN_abs_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) -#define BN_is_zero(a) (((a)->top == 0) || BN_abs_is_word(a,0)) +/* Note that BN_abs_is_word didn't work reliably for w == 0 until 0.9.8 */ +#define BN_abs_is_word(a,w) ((((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) || \ + (((w) == 0) && ((a)->top == 0))) +#define BN_is_zero(a) BN_abs_is_word(a,0) #define BN_is_one(a) (BN_abs_is_word((a),1) && !(a)->neg) -#define BN_is_word(a,w) ((w) ? BN_abs_is_word((a),(w)) && !(a)->neg : \ - BN_is_zero((a))) +#define BN_is_word(a,w) (BN_abs_is_word((a),(w)) && (!(w) || !(a)->neg)) #define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1)) #define BN_one(a) (BN_set_word((a),1))