From 5d735465d1b5b7853506979946ad5730cc3615bb Mon Sep 17 00:00:00 2001 From: Geoff Thorpe Date: Sat, 13 Mar 2004 23:04:15 +0000 Subject: [PATCH] The efforts to eliminate the dual-representation of zero and to ensure bignums are passed in and out of functions and APIs in a consistent form has highlighted that zero-valued bignums don't need any allocated word data. The use of BN_set_word() to initialise a bignum to zero causes needless allocation and gives it a return value that must be checked. This change converts BN_zero() to a self-contained macro that has no return/expression value and does not cause any expansion of bignum data. Note, it would be tempting to rewrite the deprecated version as a success-valued comma expression, such as; #define BN_zero(a) ((a)->top = (a)->neg = 0, 1) However, this evaluates 'a' twice and would confuse initialisation loops (eg. while(..) { BN_zero(bn++) } ). As such, the deprecated version continues to use BN_set_word(). --- crypto/bn/bn.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crypto/bn/bn.h b/crypto/bn/bn.h index f58d5f55a0..a01f193daa 100644 --- a/crypto/bn/bn.h +++ b/crypto/bn/bn.h @@ -372,7 +372,17 @@ int BN_GENCB_call(BN_GENCB *cb, int a, int b); #define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1)) #define BN_one(a) (BN_set_word((a),1)) +#define BN_zero_ex(a) \ + do { \ + BIGNUM *_tmp_bn = (a); \ + _tmp_bn->top = 0; \ + _tmp_bn->neg = 0; \ + } while(0) +#ifdef OPENSSL_NO_DEPRECATED +#define BN_zero(a) BN_zero_ex(a) +#else #define BN_zero(a) (BN_set_word((a),0)) +#endif /* BN_set_sign(BIGNUM *, int) sets the sign of a BIGNUM * (0 for a non-negative value, 1 for negative) */ #define BN_set_sign(a,b) ((a)->neg = (b)) -- GitLab