bn: fix occurances of negative zero
authorGeoff Thorpe <geoff@openssl.org>
Thu, 6 Oct 2016 15:04:56 +0000 (10:04 -0500)
committerRichard Levitte <levitte@openssl.org>
Wed, 1 Feb 2017 02:17:37 +0000 (03:17 +0100)
commit12ac28e0928a9cb2b970042b86c0a5ff4476590b
treefd887e8eef85bb8f11ce76720763956f79081e0b
parent0feb2207e7ff4ecbf9edea1521e44e0b809ad69d
bn: fix occurances of negative zero

The BIGNUM behaviour is supposed to be "consistent" when going into and
out of APIs, where "consistent" means 'top' is set minimally and that
'neg' (negative) is not set if the BIGNUM is zero (which is iff 'top' is
zero, due to the previous point).

The BN_DEBUG testing (make test) caught the cases that this patch
corrects.

Note, bn_correct_top() could have been used instead, but that is intended
for where 'top' is expected to (sometimes) require adjustment after direct
word-array manipulation, and so is heavier-weight. Here, we are just
catching the negative-zero case, so we test and correct for that
explicitly, in-place.

Change-Id: Iddefbd3c28a13d935648932beebcc765d5b85ae7
Signed-off-by: Geoff Thorpe <geoff@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1672)
(cherry picked from commit 38d1b3cc0271008b8bd130a2c4b442775b028a08)
crypto/bn/bn_div.c
crypto/bn/bn_mul.c
crypto/bn/bn_shift.c
crypto/bn/bn_word.c