bntest: make sure that equalBN takes note of negative zero
authorRichard Levitte <levitte@openssl.org>
Tue, 31 Jan 2017 23:46:09 +0000 (00:46 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 1 Feb 2017 01:03:29 +0000 (02:03 +0100)
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2335)

test/bntest.c

index f9e3686..77c7af6 100644 (file)
@@ -146,8 +146,14 @@ static int equalBN(const char *op, const BIGNUM *expected, const BIGNUM *actual)
     if (BN_cmp(expected, actual) == 0)
         return 1;
 
-    exstr = BN_bn2hex(expected);
-    actstr = BN_bn2hex(actual);
+    if (BN_is_zero(expected) && BN_is_negative(expected))
+        exstr = OPENSSL_strdup("-0");
+    else
+        exstr = BN_bn2hex(expected);
+    if (BN_is_zero(actual) && BN_is_negative(actual))
+        actstr = OPENSSL_strdup("-0");
+    else
+        actstr = BN_bn2hex(actual);
     if (exstr == NULL || actstr == NULL)
         goto err;