]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
* testsuite/rsa-test.c (test_main): Use test_rsa_sha256.
authorNiels Möller <nisse@lysator.liu.se>
Mon, 27 Nov 2006 22:15:30 +0000 (23:15 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Mon, 27 Nov 2006 22:15:30 +0000 (23:15 +0100)
* testsuite/testutils.c (test_rsa_sha256): New function.

Rev: src/nettle/testsuite/rsa-test.c:1.8
Rev: src/nettle/testsuite/testutils.c:1.30
Rev: src/nettle/testsuite/testutils.h:1.25

testsuite/rsa-test.c
testsuite/testutils.c
testsuite/testutils.h

index 7b96bbb907302d4fcfe646c521d0391056fc630c..4f41cc2ec2ccc8620d0f76b8cb61b0464ebd9d98 100644 (file)
@@ -39,6 +39,16 @@ test_main(void)
 
   test_rsa_sha1(&pub, &key, expected);
 
+  mpz_set_str(expected,
+             "13f9e43f7a401a73" "0a74985c01520d76" "bf5f2e2dff91e93b"
+             "9267d8c388d6937b" "d4bc6f1fa31618a9" "b5e3a1a875af72f5"
+             "0e805dbfebdf4348" "7d49763f0b365e78" "d2c0ea8fb3785897"
+             "782289a58f998907" "248c9cdf2c643d7e" "6ba6b55026227773"
+             "6f19caa69c4fc6d7" "7e2e5d4cd6b7a82b" "900d201ffd000448"
+             "685e5a4f3e", 16);
+
+  test_rsa_sha256(&pub, &key, expected);
+  
   /* 777-bit key, generated by
    *
    *   lsh-keygen -a rsa -l 777 -f advanced-hex
@@ -147,6 +157,15 @@ test_main(void)
 
   test_rsa_sha1(&pub, &key, expected);
 
+  mpz_set_str(expected,
+             "d759bb28b4d249a2" "f8b67bdbb1ab7f50" "c88712fbcabc2956"
+             "1ec6ca3f8fdafe7a" "38433d7da287b8f7" "87857274c1640b2b"
+             "e652cd89c501d570" "3980a0af5c6bb60c" "f84feab25b099d06"
+             "e2519accb73dac43" "fb8bdad28835f3bd" "84c43678fe2ef41f"
+             "af", 16);
+
+  test_rsa_sha256(&pub, &key, expected);
+
   rsa_private_key_clear(&key);
   rsa_public_key_clear(&pub);
   mpz_clear(expected);
index bac5afbd0ec807a979fc985d37965aacb59b256a..dbd475548de30826008dd19f0896304768d4447a 100644 (file)
@@ -624,6 +624,49 @@ test_rsa_sha1(struct rsa_public_key *pub,
   mpz_clear(signature);
 }
 
+void
+test_rsa_sha256(struct rsa_public_key *pub,
+            struct rsa_private_key *key,
+            mpz_t expected)
+{
+  struct sha256_ctx sha256;
+  mpz_t signature;
+
+  sha256_init(&sha256);
+  mpz_init(signature);
+
+  SIGN(key, sha256, "The magic words are squeamish ossifrage", signature);
+
+  if (verbose)
+    {
+      fprintf(stderr, "rsa-sha256 signature: ");
+      mpz_out_str(stderr, 16, signature);
+      fprintf(stderr, "\n");
+    }
+
+  if (mpz_cmp(signature, expected))
+    FAIL();
+  
+  /* Try bad data */
+  if (VERIFY(pub, sha256,
+            "The magick words are squeamish ossifrage", signature))
+    FAIL();
+
+  /* Try correct data */
+  if (!VERIFY(pub, sha256,
+             "The magic words are squeamish ossifrage", signature))
+    FAIL();
+
+  /* Try bad signature */
+  mpz_togglebit(signature, 17);
+
+  if (VERIFY(pub, sha256,
+            "The magic words are squeamish ossifrage", signature))
+    FAIL();
+
+  mpz_clear(signature);
+}
+
 #undef SIGN
 #undef VERIFY
 
index c69f7e3e7f5e2d93c50a7cb4df067201166a6c29..426239b6bbca81b54ad3ff62d968c78fb38755fd 100644 (file)
@@ -117,6 +117,11 @@ test_rsa_sha1(struct rsa_public_key *pub,
              struct rsa_private_key *key,
              mpz_t expected);
 
+void
+test_rsa_sha256(struct rsa_public_key *pub,
+               struct rsa_private_key *key,
+               mpz_t expected);
+
 void
 test_rsa_key(struct rsa_public_key *pub,
             struct rsa_private_key *key);