From c251c1fc8e6b796e47eada2b835540484c2e9cab 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:06:43 +0100
Subject: [PATCH] (RSA_MINIMUM_N_OCTETS): New constant. (RSA_MINIMUM_N_BITS):
 New constant. (nettle_random_func, nettle_progress_func): New typedefs.
 Perhaps they don't really belong in this file. (rsa_generate_keypair): Added
 progress-callback argument.

Rev: src/nettle/rsa.h:1.8
---
 rsa.h | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/rsa.h b/rsa.h
index 21f5d6d9..250fb44b 100644
--- a/rsa.h
+++ b/rsa.h
@@ -32,6 +32,16 @@
 #include "md5.h"
 #include "sha.h"
 
+/* For PKCS#1 to make sense, the size of the modulo, in octets, must
+ * be at least 11 + the length of the DER-encoded Digest Info.
+ *
+ * And a DigestInfo is 34 octets for md5, and 35 octets for sha1. 46
+ * octets is 368 bits, and as the upper 7 bits may be zero, the
+ * smallest useful size of n is 361 bits. */
+
+#define RSA_MINIMUM_N_OCTETS 46
+#define RSA_MINIMUM_N_BITS 361
+
 struct rsa_public_key
 {
   /* Size of the modulo, in octets. This is also the size of all
@@ -140,12 +150,24 @@ rsa_compute_root(struct rsa_private_key *key, mpz_t x, const mpz_t m);
 
 
 /* Key generation */
+
+/* Randomness function. This typedef doesn't really belong here, but
+ * so far it's used only by the rsa key generator. */
+typedef void (*nettle_random_func)(void *ctx,
+				   unsigned length, uint8_t *dst);
+
+/* Progress report function. */
+typedef void (*nettle_progress_func)(void *ctx,
+				     int c);
+
+/* Note that the key structs must be initialized first. */
 int
 rsa_generate_keypair(struct rsa_public_key *pub,
-		     struct rsa_public_key *key,
-		     void *random_ctx,
-		     void (*random)(void *ctx, unsigned length, uint8_t *dst),
-		     
+		     struct rsa_private_key *key,
+
+		     void *random_ctx, nettle_random_func random,
+		     void *progress_ctx, nettle_progress_func progress,
+
 		     /* Desired size of modulo, in bits */
 		     unsigned n_size,
 		     
@@ -153,6 +175,7 @@ rsa_generate_keypair(struct rsa_public_key *pub,
 		      * zero, the passed in value pub->e is used. */
 		     unsigned e_size);
 
+
 #define RSA_SIGN(key, algorithm, ctx, length, data, signature) ( \
   algorithm##_update(ctx, length, data), \
   rsa_##algorithm##_sign(key, ctx, signature) \
-- 
GitLab