Add a BN_mod_word test()
authorMatt Caswell <matt@openssl.org>
Tue, 31 May 2016 10:38:52 +0000 (11:38 +0100)
committerMatt Caswell <matt@openssl.org>
Tue, 7 Jun 2016 20:55:31 +0000 (21:55 +0100)
The previous commit fixed a bug with BN_mod_word() which would have been
caught if we had a test for it. This commit adds one.

Reviewed-by: Andy Polyakov <appro@openssl.org>
test/bntest.c

index 804406c94d439f2142ab09a8ba41e36117c9d512..763a8c29f9746d2c8e2204ba897cf9e03bf942dc 100644 (file)
@@ -504,7 +504,7 @@ static void print_word(BIO *bp, BN_ULONG w)
 int test_div_word(BIO *bp)
 {
     BIGNUM *a, *b;
-    BN_ULONG r, s;
+    BN_ULONG r, rmod, s;
     int i;
 
     a = BN_new();
@@ -518,8 +518,14 @@ int test_div_word(BIO *bp)
 
         s = b->d[0];
         BN_copy(b, a);
+        rmod = BN_mod_word(b, s);
         r = BN_div_word(b, s);
 
+        if (rmod != r) {
+            fprintf(stderr, "Mod (word) test failed!\n");
+            return 0;
+        }
+
         if (bp != NULL) {
             if (!results) {
                 BN_print(bp, a);