/*
- *
+ *
* 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"
#include "rsa.h"
#include "ssh.h"
#include "xmalloc.h"
-#include "random.h"
+#include "entropy.h"
int rsa_verbose = 1;
{
RSA *key;
+ seed_rng();
key = RSA_generate_key(32, 3, NULL, NULL);
if (key == NULL)
return (0);
fflush(stdout);
}
-/*
- * Seed OpenSSL's random number generator
- */
-void
-seed_rng()
-{
- char buf[32];
-
- get_random_bytes(buf, sizeof(buf));
- RAND_seed(buf, sizeof(buf));
- memset(buf, 0, sizeof(buf));
-}
-
/*
* Generates RSA public and private keys. This initializes the data
* structures; they should be freed with rsa_clear_private_key and
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))
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);
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);
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);