Preliminary support for RSA user authentication in SSH2! Most of the
[u/mdw/putty] / sshrsag.c
index 7b1883a..88a3d83 100644 (file)
--- a/sshrsag.c
+++ b/sshrsag.c
@@ -6,6 +6,7 @@
 
 #define RSA_EXPONENT 37                /* we like this prime */
 
+#if 0                                  /* bignum diagnostic function */
 static void diagbn(char *prefix, Bignum md) {
     int i, nibbles, morenibbles;
     static const char hex[] = "0123456789ABCDEF";
@@ -20,9 +21,9 @@ static void diagbn(char *prefix, Bignum md) {
 
     if (prefix) putchar('\n');
 }
+#endif
 
-int rsa_generate(struct RSAKey *key, struct RSAAux *aux, int bits,
-                 progfn_t pfn, void *pfnparam) {
+int rsa_generate(struct RSAKey *key, int bits, progfn_t pfn, void *pfnparam) {
     Bignum pm1, qm1, phi_n;
 
     /*
@@ -61,7 +62,6 @@ int rsa_generate(struct RSAKey *key, struct RSAAux *aux, int bits,
      * We don't generate e; we just use a standard one always.
      */
     key->exponent = bignum_from_short(RSA_EXPONENT);
-    diagbn("e = ",key->exponent);
 
     /*
      * Generate p and q: primes with combined length `bits', not
@@ -70,16 +70,16 @@ int rsa_generate(struct RSAKey *key, struct RSAAux *aux, int bits,
      * general that's slightly more fiddly to arrange. By choosing
      * a prime e, we can simplify the criterion.)
      */
-    aux->p = primegen(bits/2, RSA_EXPONENT, 1, 1, pfn, pfnparam);
-    aux->q = primegen(bits - bits/2, RSA_EXPONENT, 1, 2, pfn, pfnparam);
+    key->p = primegen(bits/2, RSA_EXPONENT, 1, 1, pfn, pfnparam);
+    key->q = primegen(bits - bits/2, RSA_EXPONENT, 1, 2, pfn, pfnparam);
 
     /*
      * Ensure p > q, by swapping them if not.
      */
-    if (bignum_cmp(aux->p, aux->q) < 0) {
-        Bignum t = aux->p;
-        aux->p = aux->q;
-        aux->q = t;
+    if (bignum_cmp(key->p, key->q) < 0) {
+        Bignum t = key->p;
+        key->p = key->q;
+        key->q = t;
     }
 
     /*
@@ -88,27 +88,20 @@ int rsa_generate(struct RSAKey *key, struct RSAAux *aux, int bits,
      * and (q^-1 mod p).
      */
     pfn(pfnparam, 3, 1);
-    key->modulus = bigmul(aux->p, aux->q);
+    key->modulus = bigmul(key->p, key->q);
     pfn(pfnparam, 3, 2);
-    pm1 = copybn(aux->p);
+    pm1 = copybn(key->p);
     decbn(pm1);
-    qm1 = copybn(aux->q);
+    qm1 = copybn(key->q);
     decbn(qm1);
     phi_n = bigmul(pm1, qm1);
     pfn(pfnparam, 3, 3);
     freebn(pm1);
     freebn(qm1);
-    diagbn("p = ", aux->p);
-    diagbn("q = ", aux->q);
-    diagbn("e = ", key->exponent);
-    diagbn("n = ", key->modulus);
-    diagbn("phi(n) = ", phi_n);
     key->private_exponent = modinv(key->exponent, phi_n);
     pfn(pfnparam, 3, 4);
-    diagbn("d = ", key->private_exponent);
-    aux->iqmp = modinv(aux->q, aux->p);
+    key->iqmp = modinv(key->q, key->p);
     pfn(pfnparam, 3, 5);
-    diagbn("iqmp = ", aux->iqmp);
 
     /*
      * Clean up temporary numbers.