From 38f04a786b0885e1d86705793555c3839f88b406 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Tue, 1 Oct 2002 15:46:38 +0200
Subject: [PATCH] New define WITH_PUBLIC_KEY, and new configure flag
 --disable-public-key. Updated rsa-files to check for that, rather than for
 HAVE_LIBGMP.

Rev: src/nettle/rsa-keygen.c:1.3
Rev: src/nettle/rsa.c:1.8
Rev: src/nettle/rsa2sexp.c:1.2
Rev: src/nettle/rsa_md5.c:1.5
Rev: src/nettle/rsa_sha1.c:1.5
Rev: src/nettle/sexp2rsa.c:1.3
Rev: src/nettle/testsuite/rsa-keygen-test.c:1.4
Rev: src/nettle/testsuite/rsa-test.c:1.5
Rev: src/nettle/testsuite/rsa2sexp-test.c:1.2
Rev: src/nettle/testsuite/sexp2rsa-test.c:1.2
Rev: src/nettle/testsuite/testutils.c:1.13
Rev: src/nettle/testsuite/testutils.h:1.11
---
 rsa-keygen.c                |  4 ++--
 rsa.c                       |  4 ++--
 rsa2sexp.c                  |  4 ++--
 rsa_md5.c                   |  4 ++--
 rsa_sha1.c                  |  4 ++--
 sexp2rsa.c                  |  4 ++--
 testsuite/rsa-keygen-test.c |  6 +++---
 testsuite/rsa-test.c        |  6 +++---
 testsuite/rsa2sexp-test.c   |  6 +++---
 testsuite/sexp2rsa-test.c   |  6 +++---
 testsuite/testutils.c       | 28 +++++++++++++---------------
 testsuite/testutils.h       |  8 ++++++--
 12 files changed, 43 insertions(+), 41 deletions(-)

diff --git a/rsa-keygen.c b/rsa-keygen.c
index 4305c0a8..a6434223 100644
--- a/rsa-keygen.c
+++ b/rsa-keygen.c
@@ -27,7 +27,7 @@
 #include "config.h"
 #endif
 
-#if HAVE_LIBGMP
+#if WITH_PUBLIC_KEY
 
 #include "rsa.h"
 #include "bignum.h"
@@ -350,4 +350,4 @@ rsa_generate_keypair(struct rsa_public_key *pub,
   return 1;
 }
 
-#endif /* HAVE_LIBGMP */
+#endif /* WITH_PUBLIC_KEY */
diff --git a/rsa.c b/rsa.c
index d64cb061..ab465056 100644
--- a/rsa.c
+++ b/rsa.c
@@ -27,7 +27,7 @@
 #include "config.h"
 #endif
 
-#if HAVE_LIBGMP
+#if WITH_PUBLIC_KEY
 
 #include "rsa.h"
 
@@ -190,4 +190,4 @@ rsa_compute_root(struct rsa_private_key *key, mpz_t x, const mpz_t m)
   mpz_clear(xp); mpz_clear(xq);
 }
 
-#endif /* HAVE_LIBGMP */
+#endif /* WITH_PUBLIC_KEY */
diff --git a/rsa2sexp.c b/rsa2sexp.c
index 9a087cae..eb6f7e89 100644
--- a/rsa2sexp.c
+++ b/rsa2sexp.c
@@ -26,7 +26,7 @@
 #include "config.h"
 #endif
 
-#if HAVE_LIBGMP
+#if WITH_PUBLIC_KEY
 
 #include "rsa.h"
 
@@ -49,4 +49,4 @@ rsa_keypair_to_sexp(struct nettle_buffer *buffer,
 		       "public-key", "rsa", "n", pub->n, "e", pub->e);
 }
 
-#endif /* HAVE_LIBGMP */
+#endif /* WITH_PUBLIC_KEY */
diff --git a/rsa_md5.c b/rsa_md5.c
index cd72ad27..05487ef6 100644
--- a/rsa_md5.c
+++ b/rsa_md5.c
@@ -27,7 +27,7 @@
 #include "config.h"
 #endif
 
-#if HAVE_LIBGMP
+#if WITH_PUBLIC_KEY
 
 #include "rsa.h"
 
@@ -131,4 +131,4 @@ pkcs1_encode_md5(mpz_t m, unsigned length, struct md5_ctx *hash)
   nettle_mpz_set_str_256(m, length, em);
 }
 
-#endif /* HAVE_LIBGMP */
+#endif /* WITH_PUBLIC_KEY */
diff --git a/rsa_sha1.c b/rsa_sha1.c
index 5bf5613f..ecc697c4 100644
--- a/rsa_sha1.c
+++ b/rsa_sha1.c
@@ -27,7 +27,7 @@
 #include "config.h"
 #endif
 
-#if HAVE_LIBGMP
+#if WITH_PUBLIC_KEY
 
 #include "rsa.h"
 
@@ -131,4 +131,4 @@ pkcs1_encode_sha1(mpz_t m, unsigned length, struct sha1_ctx *hash)
   nettle_mpz_set_str_256(m, length, em);
 }
 
-#endif /* HAVE_LIBGMP */
+#endif /* WITH_PUBLIC_KEY */
diff --git a/sexp2rsa.c b/sexp2rsa.c
index 940296c2..2c0006ed 100644
--- a/sexp2rsa.c
+++ b/sexp2rsa.c
@@ -26,7 +26,7 @@
 #include "config.h"
 #endif
 
-#if HAVE_LIBGMP
+#if WITH_PUBLIC_KEY
 
 #include "rsa.h"
 
@@ -119,4 +119,4 @@ rsa_keypair_from_sexp(struct rsa_public_key *pub,
   return 1;
 }
 
-#endif /* HAVE_LIBGMP */
+#endif /* WITH_PUBLIC_KEY */
diff --git a/testsuite/rsa-keygen-test.c b/testsuite/rsa-keygen-test.c
index 8a2498da..438a6298 100644
--- a/testsuite/rsa-keygen-test.c
+++ b/testsuite/rsa-keygen-test.c
@@ -17,7 +17,7 @@ progress(void *ctx UNUSED, int c)
 int
 test_main(void)
 {
-#if HAVE_LIBGMP
+#if WITH_PUBLIC_KEY
 
   struct rsa_public_key pub;
   struct rsa_private_key key;
@@ -85,7 +85,7 @@ test_main(void)
 
   SUCCESS();
   
-#else /* !HAVE_LIBGMP */
+#else /* !WITH_PUBLIC_KEY */
   SKIP();
-#endif /* !HAVE_LIBGMP */
+#endif /* !WITH_PUBLIC_KEY */
 }
diff --git a/testsuite/rsa-test.c b/testsuite/rsa-test.c
index 40161738..a43c43d8 100644
--- a/testsuite/rsa-test.c
+++ b/testsuite/rsa-test.c
@@ -3,7 +3,7 @@
 int
 test_main(void)
 {
-#if HAVE_LIBGMP
+#if WITH_PUBLIC_KEY
 
   struct rsa_public_key pub;
   struct rsa_private_key key;
@@ -240,7 +240,7 @@ test_main(void)
 
   SUCCESS();
   
-#else /* !HAVE_LIBGMP */
+#else /* !WITH_PUBLIC_KEY */
   SKIP();
-#endif /* !HAVE_LIBGMP */
+#endif /* !WITH_PUBLIC_KEY */
 }
diff --git a/testsuite/rsa2sexp-test.c b/testsuite/rsa2sexp-test.c
index 7ff85dab..f4ddcf85 100644
--- a/testsuite/rsa2sexp-test.c
+++ b/testsuite/rsa2sexp-test.c
@@ -6,7 +6,7 @@
 int
 test_main(void)
 {
-#if HAVE_LIBGMP
+#if WITH_PUBLIC_KEY
   struct rsa_public_key pub;
   struct rsa_private_key priv;
 
@@ -87,7 +87,7 @@ test_main(void)
   
   SUCCESS();
   
-#else /* !HAVE_LIBGMP */
+#else /* !WITH_PUBLIC_KEY */
   SKIP();
-#endif /* !HAVE_LIBGMP */
+#endif /* !WITH_PUBLIC_KEY */
 }
diff --git a/testsuite/sexp2rsa-test.c b/testsuite/sexp2rsa-test.c
index 3296644e..e19d50cd 100644
--- a/testsuite/sexp2rsa-test.c
+++ b/testsuite/sexp2rsa-test.c
@@ -5,7 +5,7 @@
 int
 test_main(void)
 {
-#if HAVE_LIBGMP
+#if WITH_PUBLIC_KEY
   struct rsa_public_key pub;
   struct rsa_private_key priv;
   
@@ -43,8 +43,8 @@ test_main(void)
   
   SUCCESS();
   
-#else /* !HAVE_LIBGMP */
+#else /* !WITH_PUBLIC_KEY */
   SKIP();
-#endif /* !HAVE_LIBGMP */
+#endif /* !WITH_PUBLIC_KEY */
 }
 
diff --git a/testsuite/testutils.c b/testsuite/testutils.c
index 203f8271..a954a374 100644
--- a/testsuite/testutils.c
+++ b/testsuite/testutils.c
@@ -1,6 +1,5 @@
 /* testutils.c */
 
-
 #include "testutils.h"
 
 #include "cbc.h"
@@ -269,17 +268,6 @@ test_armor(const struct nettle_armor *armor,
 }
 
 #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)
@@ -289,6 +277,18 @@ mpz_togglebit (mpz_t x, unsigned long int bit)
   else
     mpz_setbit(x, bit);
 }
+#endif /* HAVE_LIBGMP */
+
+#if WITH_PUBLIC_KEY
+#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)	\
+)
 
 void
 test_rsa_md5(struct rsa_public_key *pub,
@@ -376,7 +376,6 @@ test_rsa_sha1(struct rsa_public_key *pub,
   mpz_clear(signature);
 }
 
-#if HAVE_LIBGMP
 void
 test_rsa_key(struct rsa_public_key *pub,
 	     struct rsa_private_key *key)
@@ -447,6 +446,5 @@ test_rsa_key(struct rsa_public_key *pub,
   
   mpz_clear(tmp); mpz_clear(phi);
 }
-#endif /* HAVE_LIBGMP */
+#endif /* WITH_PUBLIC_KEY */
 
-#endif /* HAVE_LIBGMP */
diff --git a/testsuite/testutils.h b/testsuite/testutils.h
index d82aa51a..d1f9f764 100644
--- a/testsuite/testutils.h
+++ b/testsuite/testutils.h
@@ -12,6 +12,10 @@
 #include <stdio.h>
 
 #if HAVE_LIBGMP
+# include "bignum.h"
+#endif
+
+#if WITH_PUBLIC_KEY
 # include "rsa.h"
 #endif
 
@@ -67,7 +71,7 @@ test_armor(const struct nettle_armor *armor,
            const uint8_t *data,
            const uint8_t *ascii);
 
-#if HAVE_LIBGMP
+#if WITH_PUBLIC_KEY
 void
 test_rsa_md5(struct rsa_public_key *pub,
 	     struct rsa_private_key *key,
@@ -82,7 +86,7 @@ void
 test_rsa_key(struct rsa_public_key *pub,
 	     struct rsa_private_key *key);
 
-#endif /* HAVE_LIBGMP */
+#endif /* WITH_PUBLIC_KEY */
 
 #define H2(d, s) decode_hex((d), (s))
 #define H(x) decode_hex_dup(x)
-- 
GitLab