bntest: make sure file_rshift tests BN_rshift1 as well when appropriate
authorRichard Levitte <levitte@openssl.org>
Tue, 31 Jan 2017 23:46:58 +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 77c7af62c26a0f39adf90990d2d49df79f2b2875..76e91e67c04d701a033e595db8a5bc30f7c107bf 100644 (file)
@@ -1155,21 +1155,28 @@ static int file_rshift(STANZA *s)
     BIGNUM *rshift = getBN(s, "RShift");
     BIGNUM *ret = BN_new();
     int n = 0;
     BIGNUM *rshift = getBN(s, "RShift");
     BIGNUM *ret = BN_new();
     int n = 0;
-    int st = 0;
+    int errcnt = 1;
 
     if (a == NULL || rshift == NULL || ret == NULL || !getint(s, &n, "N"))
         goto err;
 
 
     if (a == NULL || rshift == NULL || ret == NULL || !getint(s, &n, "N"))
         goto err;
 
+    errcnt = 0;
     if (!BN_rshift(ret, a, n)
             || !equalBN("A >> N", rshift, ret))
     if (!BN_rshift(ret, a, n)
             || !equalBN("A >> N", rshift, ret))
-        goto err;
+        errcnt++;
+
+    /* If N == 1, try with rshift1 as well */
+    if (n == 1) {
+        if (!BN_rshift1(ret, a)
+                || !equalBN("A >> 1 (rshift1)", rshift, ret))
+            errcnt++;
+    }
 
 
-    st = 1;
 err:
     BN_free(a);
     BN_free(rshift);
     BN_free(ret);
 err:
     BN_free(a);
     BN_free(rshift);
     BN_free(ret);
-    return st;
+    return errcnt == 0;
 }
 
 static int file_square(STANZA *s)
 }
 
 static int file_square(STANZA *s)