]> andersk Git - openssh.git/blobdiff - rsa.c
[scp.c]
[openssh.git] / rsa.c
diff --git a/rsa.c b/rsa.c
index a802e593fab7af9da46790823c1c44ba3bbfa73e..1a509de30427cabc83437b8f4c146e4f98332be4 100644 (file)
--- a/rsa.c
+++ b/rsa.c
@@ -1,37 +1,37 @@
 /*
- * 
+ *
  * rsa.c
- * 
+ *
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
- * 
+ *
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  *                    All rights reserved
- * 
+ *
  * Created: Fri Mar  3 22:07:06 1995 ylo
- * 
+ *
  * Description of the RSA algorithm can be found e.g. from the following sources:
- * 
+ *
  *   Bruce Schneier: Applied Cryptography.  John Wiley & Sons, 1994.
- * 
+ *
  *   Jennifer Seberry and Josed Pieprzyk: Cryptography: An Introduction to
  *   Computer Security.  Prentice-Hall, 1989.
- * 
+ *
  *   Man Young Rhee: Cryptography and Secure Data Communications.  McGraw-Hill,
  *   1994.
- * 
+ *
  *   R. Rivest, A. Shamir, and L. M. Adleman: Cryptographic Communications
  *   System and Method.  US Patent 4,405,829, 1983.
- * 
+ *
  *   Hans Riesel: Prime Numbers and Computer Methods for Factorization.
  *   Birkhauser, 1994.
- * 
+ *
  *   The RSA Frequently Asked Questions document by RSA Data Security, Inc., 1995.
- * 
+ *
  *   RSA in 3 lines of perl by Adam Back <aba@atlax.ex.ac.uk>, 1995, as included
  *   below:
- * 
+ *
  *     [gone - had to be deleted - what a pity]
- * 
+ *
 */
 
 #include "includes.h"
@@ -40,6 +40,7 @@ RCSID("$Id$");
 #include "rsa.h"
 #include "ssh.h"
 #include "xmalloc.h"
+#include "entropy.h"
 
 int rsa_verbose = 1;
 
@@ -48,6 +49,7 @@ rsa_alive()
 {
        RSA *key;
 
+       seed_rng();
        key = RSA_generate_key(32, 3, NULL, NULL);
        if (key == NULL)
                return (0);
@@ -55,20 +57,42 @@ rsa_alive()
        return (1);
 }
 
-/* Generates RSA public and private keys.  This initializes the data
-   structures; they should be freed with rsa_clear_private_key and
-   rsa_clear_public_key. */
+/*
+ * Key generation progress meter callback
+ */
+void
+keygen_progress(int p, int n, void *arg)
+{
+       const char progress_chars[] = ".o+O?";
+
+       if ((p < 0) || (p > (sizeof(progress_chars) - 2)))
+               p = sizeof(progress_chars) - 2;
+
+       putchar(progress_chars[p]);
+       fflush(stdout);
+}
+
+/*
+ * Generates RSA public and private keys.  This initializes the data
+ * structures; they should be freed with rsa_clear_private_key and
+ * rsa_clear_public_key.
+ */
 
 void
 rsa_generate_key(RSA *prv, RSA *pub, unsigned int bits)
 {
        RSA *key;
 
+       seed_rng();
+       
        if (rsa_verbose) {
                printf("Generating RSA keys:  ");
                fflush(stdout);
+               key = RSA_generate_key(bits, 35, keygen_progress, NULL);
+               printf("\n");
+       } else {
+               key = RSA_generate_key(bits, 35, NULL, NULL);
        }
-       key = RSA_generate_key(bits, 35, NULL, NULL);
        if (key == NULL)
                fatal("rsa_generate_key: key generation failed.");
 
@@ -108,7 +132,7 @@ rsa_generate_key(RSA *prv, RSA *pub, unsigned int bits)
 void
 rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key)
 {
-       char *inbuf, *outbuf;
+       unsigned char *inbuf, *outbuf;
        int len, ilen, olen;
 
        if (BN_num_bits(key->e) < 2 || !BN_is_odd(key->e))
@@ -122,7 +146,7 @@ rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key)
        BN_bn2bin(in, inbuf);
 
        if ((len = RSA_public_encrypt(ilen, inbuf, outbuf, key,
-                                     RSA_PKCS1_PADDING)) <= 0)
+           RSA_PKCS1_PADDING)) <= 0)
                fatal("rsa_public_encrypt() failed");
 
        BN_bin2bn(outbuf, len, out);
@@ -136,7 +160,7 @@ rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key)
 void
 rsa_private_decrypt(BIGNUM *out, BIGNUM *in, RSA *key)
 {
-       char *inbuf, *outbuf;
+       unsigned char *inbuf, *outbuf;
        int len, ilen, olen;
 
        olen = BN_num_bytes(key->n);
@@ -147,7 +171,7 @@ rsa_private_decrypt(BIGNUM *out, BIGNUM *in, RSA *key)
        BN_bn2bin(in, inbuf);
 
        if ((len = RSA_private_decrypt(ilen, inbuf, outbuf, key,
-                                      RSA_SSLV23_PADDING)) <= 0)
+           RSA_PKCS1_PADDING)) <= 0)
                fatal("rsa_private_decrypt() failed");
 
        BN_bin2bn(outbuf, len, out);
This page took 0.076953 seconds and 4 git commands to generate.