From 99e8976d555a39496b13e57dea1b6417183025b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Tue, 23 Mar 2010 16:41:34 +0100
Subject: [PATCH] (test_rsa_sha512): New function.

Rev: nettle/testsuite/testutils.c:1.4
Rev: nettle/testsuite/testutils.h:1.3
---
 testsuite/testutils.c | 51 +++++++++++++++++++++++++++++++++++++++----
 testsuite/testutils.h |  5 +++++
 2 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/testsuite/testutils.c b/testsuite/testutils.c
index 0f2594e4..4a316a60 100644
--- a/testsuite/testutils.c
+++ b/testsuite/testutils.c
@@ -600,8 +600,8 @@ test_rsa_md5(struct rsa_public_key *pub,
 
 void
 test_rsa_sha1(struct rsa_public_key *pub,
-	     struct rsa_private_key *key,
-	     mpz_t expected)
+	      struct rsa_private_key *key,
+	      mpz_t expected)
 {
   struct sha1_ctx sha1;
   mpz_t signature;
@@ -643,8 +643,8 @@ test_rsa_sha1(struct rsa_public_key *pub,
 
 void
 test_rsa_sha256(struct rsa_public_key *pub,
-	     struct rsa_private_key *key,
-	     mpz_t expected)
+		struct rsa_private_key *key,
+		mpz_t expected)
 {
   struct sha256_ctx sha256;
   mpz_t signature;
@@ -684,6 +684,49 @@ test_rsa_sha256(struct rsa_public_key *pub,
   mpz_clear(signature);
 }
 
+void
+test_rsa_sha512(struct rsa_public_key *pub,
+		struct rsa_private_key *key,
+		mpz_t expected)
+{
+  struct sha512_ctx sha512;
+  mpz_t signature;
+
+  sha512_init(&sha512);
+  mpz_init(signature);
+
+  SIGN(key, sha512, "The magic words are squeamish ossifrage", signature);
+
+  if (verbose)
+    {
+      fprintf(stderr, "rsa-sha512 signature: ");
+      mpz_out_str(stderr, 16, signature);
+      fprintf(stderr, "\n");
+    }
+
+  if (mpz_cmp(signature, expected))
+    FAIL();
+  
+  /* Try bad data */
+  if (VERIFY(pub, sha512,
+	     "The magick words are squeamish ossifrage", signature))
+    FAIL();
+
+  /* Try correct data */
+  if (!VERIFY(pub, sha512,
+	      "The magic words are squeamish ossifrage", signature))
+    FAIL();
+
+  /* Try bad signature */
+  mpz_togglebit(signature, 17);
+
+  if (VERIFY(pub, sha512,
+	     "The magic words are squeamish ossifrage", signature))
+    FAIL();
+
+  mpz_clear(signature);
+}
+
 #undef SIGN
 #undef VERIFY
 
diff --git a/testsuite/testutils.h b/testsuite/testutils.h
index 352e1e84..d46b5d83 100644
--- a/testsuite/testutils.h
+++ b/testsuite/testutils.h
@@ -122,6 +122,11 @@ test_rsa_sha256(struct rsa_public_key *pub,
 		struct rsa_private_key *key,
 		mpz_t expected);
 
+void
+test_rsa_sha512(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);
-- 
GitLab