From 336fc90c19039f5ccd818fc9fccd5b1163a2e45a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Tue, 30 Oct 2001 16:36:25 +0100
Subject: [PATCH] *** empty log message ***

Rev: src/nettle/ChangeLog:1.43
Rev: src/nettle/rsa.h:1.2
Rev: src/nettle/testsuite/.cvsignore:1.11
---
 ChangeLog            | 25 ++++++++++++++
 rsa.h                | 80 ++++++++++++++++++++++++++++++++++++++++++--
 testsuite/.cvsignore |  2 ++
 testsuite/.gitignore |  2 ++
 4 files changed, 107 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 856bd8f2..b772d2de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2001-10-30  Niels M�ller  <nisse@ehand.com>
+
+	* configure.in: Check for libgmp. Deleted tests for SIZEOF_INT and
+	friends. 
+
+	* rsa_sha1.c: New file, PKCS#1 rsa-sha1 signatures. 
+	* rsa_md5.c: New file, PKCS#1 rsa-md5 signatures.
+
+	* rsa.c: New file with general rsa functions.
+
+	* Makefile.am (libnettle_a_SOURCES): Added rsa and bignum files.
+
+	* bignum.c, bignum.h: New file, with base256 functions missing in
+	gmp. 
+
+	* testsuite/Makefile.am: Added bignum-test.
+
+	* testsuite/run-tests (test_program): Check the xit code more
+	carefully, and treat 77 as skip. This convention was borrowed from
+	autotest. 
+
+	* testsuite/macros.m4: New macro SKIP which exits with code 77.
+
+	* testsuite/bignum-test.m4: New file.
+
 2001-10-15  Niels M�ller  <nisse@ehand.com>
 
 	* testsuite/Makefile.am (EXTRA_DIST): Include rfc1750.txt in the
diff --git a/rsa.h b/rsa.h
index 105970ef..52c6d94c 100644
--- a/rsa.h
+++ b/rsa.h
@@ -27,19 +27,95 @@
 #define NETTLE_RSA_H_INCLUDED
 
 #include <inttypes.h>
-
 #include <gmp.h>
 
+#include "md5.h"
+#include "sha.h"
+
 struct rsa_public_key
 {
+  /* Size of the modulo, in octets. This is also the size of all
+   * signatures that are created or verified with this key. */
+  unsigned size;
+  
+  /* Modulo */
   mpz_t n;
+
+  /* Public exponent */
   mpz_t e;
 };
 
 struct rsa_private_key
 {
+  struct rsa_public_key pub;
   
+  /* Secret exponent */
+  mpz_t d;
+
+  /* The two factors */
+  mpz_t p; mpz_t q;
+
+  /* d % (p-1), i.e. a e = 1 (mod (p-1)) */
+  mpz_t a;
+
+  /* d % (q-1), i.e. b e = 1 (mod (q-1)) */
+  mpz_t b;
+
+  /* modular inverse of q , i.e. c q = 1 (mod p) */
+  mpz_t c;
 };
 
+/* Signing a message works as follows:
+ *
+ * Store the private key in a rsa_private_key struct.
+ *
+ * Call rsa_init_private_key. This initializes the size attribute
+ * to the length of a signature.
+ *
+ * Initialize a hashing context, by callling
+ *   md5_init
+ *
+ * Hash the message by calling
+ *   md5_update
+ *
+ * Finally, call
+ *   rsa_md5_sign
+ *
+ * The final call stores the signature, of length size, in the supplied buffer,
+ * and resets the hashing context.
+ */
+
+int
+rsa_init_public_key(struct rsa_public_key *key);
+
+int
+rsa_init_private_key(struct rsa_private_key *key);
+
+/* PKCS#1 style signatures */
+void
+rsa_md5_sign(struct rsa_private_key *key,
+             struct md5_ctx *hash,
+             uint8_t *signature);
+
+
+int
+rsa_md5_verify(struct rsa_public_key *key,
+               struct md5_ctx *hash,
+               const uint8_t *signature);
+
+void
+rsa_sha1_sign(struct rsa_private_key *key,
+              struct sha1_ctx *hash,
+              uint8_t *signature);
+
+int
+rsa_sha1_verify(struct rsa_public_key *key,
+                struct sha1_ctx *hash,
+                const uint8_t *signature);
+
+/* Compute x, the d:th root of m. Calling it with x == m is allowed. */
+void
+rsa_compute_root(struct rsa_private_key *key, mpz_t x, mpz_t m);
+
 
-#endif NETTLE_RSA_H_INCLUDED
+#endif /* NETTLE_RSA_H_INCLUDED */
diff --git a/testsuite/.cvsignore b/testsuite/.cvsignore
index 3c17f387..64c77d5f 100644
--- a/testsuite/.cvsignore
+++ b/testsuite/.cvsignore
@@ -5,6 +5,8 @@ aes-test
 aes-test.c
 arcfour-test
 arcfour-test.c
+bignum-test
+bignum-test.c
 blowfish-test
 blowfish-test.c
 cast128-test
diff --git a/testsuite/.gitignore b/testsuite/.gitignore
index 29d40cb4..e5c287dd 100644
--- a/testsuite/.gitignore
+++ b/testsuite/.gitignore
@@ -5,6 +5,8 @@
 /aes-test.c
 /arcfour-test
 /arcfour-test.c
+/bignum-test
+/bignum-test.c
 /blowfish-test
 /blowfish-test.c
 /cast128-test
-- 
GitLab