summaryrefslogtreecommitdiff
path: root/rsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'rsa.c')
-rw-r--r--rsa.c79
1 files changed, 1 insertions, 78 deletions
diff --git a/rsa.c b/rsa.c
index 0c9aef791..7cfcc80db 100644
--- a/rsa.c
+++ b/rsa.c
@@ -60,82 +60,13 @@
60 */ 60 */
61 61
62#include "includes.h" 62#include "includes.h"
63RCSID("$OpenBSD: rsa.c,v 1.16 2000/09/07 20:27:53 deraadt Exp $"); 63RCSID("$OpenBSD: rsa.c,v 1.17 2000/11/12 19:50:37 markus Exp $");
64 64
65#include "rsa.h" 65#include "rsa.h"
66#include "ssh.h" 66#include "ssh.h"
67#include "xmalloc.h" 67#include "xmalloc.h"
68#include "entropy.h" 68#include "entropy.h"
69 69
70int rsa_verbose = 1;
71
72int
73rsa_alive()
74{
75 RSA *key;
76
77 seed_rng();
78 key = RSA_generate_key(32, 3, NULL, NULL);
79 if (key == NULL)
80 return (0);
81 RSA_free(key);
82 return (1);
83}
84
85/*
86 * Generates RSA public and private keys. This initializes the data
87 * structures; they should be freed with rsa_clear_private_key and
88 * rsa_clear_public_key.
89 */
90
91void
92rsa_generate_key(RSA *prv, RSA *pub, unsigned int bits)
93{
94 RSA *key;
95
96 seed_rng();
97
98 if (rsa_verbose) {
99 printf("Generating RSA keys: ");
100 fflush(stdout);
101 }
102 key = RSA_generate_key(bits, 35, NULL, NULL);
103 if (key == NULL)
104 fatal("rsa_generate_key: key generation failed.");
105
106 /* Copy public key parameters */
107 pub->n = BN_new();
108 BN_copy(pub->n, key->n);
109 pub->e = BN_new();
110 BN_copy(pub->e, key->e);
111
112 /* Copy private key parameters */
113 prv->n = BN_new();
114 BN_copy(prv->n, key->n);
115 prv->e = BN_new();
116 BN_copy(prv->e, key->e);
117 prv->d = BN_new();
118 BN_copy(prv->d, key->d);
119 prv->p = BN_new();
120 BN_copy(prv->p, key->p);
121 prv->q = BN_new();
122 BN_copy(prv->q, key->q);
123
124 prv->dmp1 = BN_new();
125 BN_copy(prv->dmp1, key->dmp1);
126
127 prv->dmq1 = BN_new();
128 BN_copy(prv->dmq1, key->dmq1);
129
130 prv->iqmp = BN_new();
131 BN_copy(prv->iqmp, key->iqmp);
132
133 RSA_free(key);
134
135 if (rsa_verbose)
136 printf("Key generation complete.\n");
137}
138
139void 70void
140rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key) 71rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key)
141{ 72{
@@ -188,11 +119,3 @@ rsa_private_decrypt(BIGNUM *out, BIGNUM *in, RSA *key)
188 xfree(outbuf); 119 xfree(outbuf);
189 xfree(inbuf); 120 xfree(inbuf);
190} 121}
191
192/* Set whether to output verbose messages during key generation. */
193
194void
195rsa_set_verbose(int verbose)
196{
197 rsa_verbose = verbose;
198}