From dc3f8c4a06285aa1353b4e359c2e4faf680a2813 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Wed, 16 Jan 2002 21:12:03 +0100
Subject: [PATCH] * testsuite/testutils.c (test_rsa_md5, test_rsa_sha1): Moved
 functions here... * testsuite/rsa-test.c: ...from here.

Rev: src/nettle/testsuite/rsa-test.c:1.4
Rev: src/nettle/testsuite/testutils.c:1.7
Rev: src/nettle/testsuite/testutils.h:1.6
---
 testsuite/rsa-test.c  | 120 ------------------------------------------
 testsuite/testutils.c | 110 ++++++++++++++++++++++++++++++++++++++
 testsuite/testutils.h |  21 ++++++++
 3 files changed, 131 insertions(+), 120 deletions(-)

diff --git a/testsuite/rsa-test.c b/testsuite/rsa-test.c
index 3062fd99..40161738 100644
--- a/testsuite/rsa-test.c
+++ b/testsuite/rsa-test.c
@@ -1,125 +1,5 @@
 #include "testutils.h"
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdio.h>
-
-#if HAVE_LIBGMP
-# include "rsa.h"
-#endif
-
-#define SIGN(key, hash, msg, signature) do {	\
-  hash##_update(&hash, LDATA(msg));		\
-  rsa_##hash##_sign(key, &hash, signature);	\
-} while(0)
-
-#define VERIFY(key, hash, msg, signature) (	\
-  hash##_update(&hash, LDATA(msg)),		\
-  rsa_##hash##_verify(key, &hash, signature)	\
-)
-
-#if HAVE_LIBGMP
-
-/* Missing in current gmp */
-static void
-mpz_togglebit (mpz_t x, unsigned long int bit)
-{
-  if (mpz_tstbit(x, bit))
-    mpz_clrbit(x, bit);
-  else
-    mpz_setbit(x, bit);
-}
-
-#endif /* HAVE_LIBGMP */
-
-static void
-test_rsa_md5(struct rsa_public_key *pub,
-	     struct rsa_private_key *key,
-	     mpz_t expected)
-{
-  struct md5_ctx md5;
-  mpz_t signature;
-
-  md5_init(&md5);
-  mpz_init(signature);
-  
-  SIGN(key, md5, "The magic words are squeamish ossifrage", signature);
-
-  if (verbose)
-    {
-      fprintf(stderr, "rsa-md5 signature: ");
-      mpz_out_str(stderr, 16, signature);
-      fprintf(stderr, "\n");
-    }
-
-  if (mpz_cmp(signature, expected))
-    FAIL();
-  
-  /* Try bad data */
-  if (VERIFY(pub, md5,
-	     "The magick words are squeamish ossifrage", signature))
-    FAIL();
-
-  /* Try correct data */
-  if (!VERIFY(pub, md5,
-	      "The magic words are squeamish ossifrage", signature))
-    FAIL();
-
-  /* Try bad signature */
-  mpz_togglebit(signature, 17);
-
-  if (VERIFY(pub, md5,
-	     "The magic words are squeamish ossifrage", signature))
-    FAIL();
-
-  mpz_clear(signature);
-}
-
-static void
-test_rsa_sha1(struct rsa_public_key *pub,
-	     struct rsa_private_key *key,
-	     mpz_t expected)
-{
-  struct sha1_ctx sha1;
-  mpz_t signature;
-
-  sha1_init(&sha1);
-  mpz_init(signature);
-
-  SIGN(key, sha1, "The magic words are squeamish ossifrage", signature);
-
-  if (verbose)
-    {
-      fprintf(stderr, "rsa-sha1 signature: ");
-      mpz_out_str(stderr, 16, signature);
-      fprintf(stderr, "\n");
-    }
-
-  if (mpz_cmp(signature, expected))
-    FAIL();
-  
-  /* Try bad data */
-  if (VERIFY(pub, sha1,
-	     "The magick words are squeamish ossifrage", signature))
-    FAIL();
-
-  /* Try correct data */
-  if (!VERIFY(pub, sha1,
-	      "The magic words are squeamish ossifrage", signature))
-    FAIL();
-
-  /* Try bad signature */
-  mpz_togglebit(signature, 17);
-
-  if (VERIFY(pub, sha1,
-	     "The magic words are squeamish ossifrage", signature))
-    FAIL();
-
-  mpz_clear(signature);
-}
-
 int
 test_main(void)
 {
diff --git a/testsuite/testutils.c b/testsuite/testutils.c
index 41ae5771..b6e4a785 100644
--- a/testsuite/testutils.c
+++ b/testsuite/testutils.c
@@ -1,5 +1,6 @@
 /* testutils.c */
 
+
 #include "testutils.h"
 
 #include "cbc.h"
@@ -220,3 +221,112 @@ test_hash(const struct nettle_hash *hash,
   if (buffer[hash->digest_size - 1])
     FAIL();
 }
+
+#if HAVE_LIBGMP
+#define SIGN(key, hash, msg, signature) do {	\
+  hash##_update(&hash, LDATA(msg));		\
+  rsa_##hash##_sign(key, &hash, signature);	\
+} while(0)
+
+#define VERIFY(key, hash, msg, signature) (	\
+  hash##_update(&hash, LDATA(msg)),		\
+  rsa_##hash##_verify(key, &hash, signature)	\
+)
+
+
+/* Missing in current gmp */
+static void
+mpz_togglebit (mpz_t x, unsigned long int bit)
+{
+  if (mpz_tstbit(x, bit))
+    mpz_clrbit(x, bit);
+  else
+    mpz_setbit(x, bit);
+}
+
+void
+test_rsa_md5(struct rsa_public_key *pub,
+	     struct rsa_private_key *key,
+	     mpz_t expected)
+{
+  struct md5_ctx md5;
+  mpz_t signature;
+
+  md5_init(&md5);
+  mpz_init(signature);
+  
+  SIGN(key, md5, "The magic words are squeamish ossifrage", signature);
+
+  if (verbose)
+    {
+      fprintf(stderr, "rsa-md5 signature: ");
+      mpz_out_str(stderr, 16, signature);
+      fprintf(stderr, "\n");
+    }
+
+  if (mpz_cmp(signature, expected))
+    FAIL();
+  
+  /* Try bad data */
+  if (VERIFY(pub, md5,
+	     "The magick words are squeamish ossifrage", signature))
+    FAIL();
+
+  /* Try correct data */
+  if (!VERIFY(pub, md5,
+	      "The magic words are squeamish ossifrage", signature))
+    FAIL();
+
+  /* Try bad signature */
+  mpz_togglebit(signature, 17);
+
+  if (VERIFY(pub, md5,
+	     "The magic words are squeamish ossifrage", signature))
+    FAIL();
+
+  mpz_clear(signature);
+}
+
+void
+test_rsa_sha1(struct rsa_public_key *pub,
+	     struct rsa_private_key *key,
+	     mpz_t expected)
+{
+  struct sha1_ctx sha1;
+  mpz_t signature;
+
+  sha1_init(&sha1);
+  mpz_init(signature);
+
+  SIGN(key, sha1, "The magic words are squeamish ossifrage", signature);
+
+  if (verbose)
+    {
+      fprintf(stderr, "rsa-sha1 signature: ");
+      mpz_out_str(stderr, 16, signature);
+      fprintf(stderr, "\n");
+    }
+
+  if (mpz_cmp(signature, expected))
+    FAIL();
+  
+  /* Try bad data */
+  if (VERIFY(pub, sha1,
+	     "The magick words are squeamish ossifrage", signature))
+    FAIL();
+
+  /* Try correct data */
+  if (!VERIFY(pub, sha1,
+	      "The magic words are squeamish ossifrage", signature))
+    FAIL();
+
+  /* Try bad signature */
+  mpz_togglebit(signature, 17);
+
+  if (VERIFY(pub, sha1,
+	     "The magic words are squeamish ossifrage", signature))
+    FAIL();
+
+  mpz_clear(signature);
+}
+#endif /* HAVE_LIBGMP */
diff --git a/testsuite/testutils.h b/testsuite/testutils.h
index 75981152..3c2756fe 100644
--- a/testsuite/testutils.h
+++ b/testsuite/testutils.h
@@ -1,10 +1,19 @@
 #ifndef NETTLE_TESTUTILS_H_INCLUDED
 #define NETTLE_TESTUTILS_H_INCLUDED
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <inttypes.h>
 
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+
+#if HAVE_LIBGMP
+# include "rsa.h"
+#endif
 
 #include "nettle-meta.h"
 
@@ -49,6 +58,18 @@ test_hash(const struct nettle_hash *hash,
 	  const uint8_t *data,
 	  const uint8_t *digest);
 
+#if HAVE_LIBGMP
+void
+test_rsa_md5(struct rsa_public_key *pub,
+	     struct rsa_private_key *key,
+	     mpz_t expected);
+
+void
+test_rsa_sha1(struct rsa_public_key *pub,
+	      struct rsa_private_key *key,
+	      mpz_t expected);
+#endif /* HAVE_LIBGMP */
+
 #define H2(d, s) decode_hex((d), (s))
 #define H(x) decode_hex_dup(x)
 #define HL(x) decode_hex_length(x), decode_hex_dup(x)
-- 
GitLab