diff options
Diffstat (limited to 'src/lib/libssl/src/apps/gendsa.c')
-rw-r--r-- | src/lib/libssl/src/apps/gendsa.c | 65 |
1 files changed, 25 insertions, 40 deletions
diff --git a/src/lib/libssl/src/apps/gendsa.c b/src/lib/libssl/src/apps/gendsa.c index 5f00b89bb0..d69a93da45 100644 --- a/src/lib/libssl/src/apps/gendsa.c +++ b/src/lib/libssl/src/apps/gendsa.c | |||
@@ -63,7 +63,6 @@ | |||
63 | #include <sys/stat.h> | 63 | #include <sys/stat.h> |
64 | #include "apps.h" | 64 | #include "apps.h" |
65 | #include <openssl/bio.h> | 65 | #include <openssl/bio.h> |
66 | #include <openssl/rand.h> | ||
67 | #include <openssl/err.h> | 66 | #include <openssl/err.h> |
68 | #include <openssl/bn.h> | 67 | #include <openssl/bn.h> |
69 | #include <openssl/dsa.h> | 68 | #include <openssl/dsa.h> |
@@ -74,14 +73,15 @@ | |||
74 | #undef PROG | 73 | #undef PROG |
75 | #define PROG gendsa_main | 74 | #define PROG gendsa_main |
76 | 75 | ||
77 | static long dsa_load_rand(char *names); | 76 | int MAIN(int, char **); |
77 | |||
78 | int MAIN(int argc, char **argv) | 78 | int MAIN(int argc, char **argv) |
79 | { | 79 | { |
80 | char buffer[200]; | ||
81 | DSA *dsa=NULL; | 80 | DSA *dsa=NULL; |
82 | int ret=1; | 81 | int ret=1; |
83 | char *outfile=NULL; | 82 | char *outfile=NULL; |
84 | char *inrand=NULL,*randfile,*dsaparams=NULL; | 83 | char *inrand=NULL,*dsaparams=NULL; |
84 | char *passargout = NULL, *passout = NULL; | ||
85 | BIO *out=NULL,*in=NULL; | 85 | BIO *out=NULL,*in=NULL; |
86 | EVP_CIPHER *enc=NULL; | 86 | EVP_CIPHER *enc=NULL; |
87 | 87 | ||
@@ -101,6 +101,11 @@ int MAIN(int argc, char **argv) | |||
101 | if (--argc < 1) goto bad; | 101 | if (--argc < 1) goto bad; |
102 | outfile= *(++argv); | 102 | outfile= *(++argv); |
103 | } | 103 | } |
104 | else if (strcmp(*argv,"-passout") == 0) | ||
105 | { | ||
106 | if (--argc < 1) goto bad; | ||
107 | passargout= *(++argv); | ||
108 | } | ||
104 | else if (strcmp(*argv,"-rand") == 0) | 109 | else if (strcmp(*argv,"-rand") == 0) |
105 | { | 110 | { |
106 | if (--argc < 1) goto bad; | 111 | if (--argc < 1) goto bad; |
@@ -148,6 +153,12 @@ bad: | |||
148 | goto end; | 153 | goto end; |
149 | } | 154 | } |
150 | 155 | ||
156 | if(!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { | ||
157 | BIO_printf(bio_err, "Error getting password\n"); | ||
158 | goto end; | ||
159 | } | ||
160 | |||
161 | |||
151 | in=BIO_new(BIO_s_file()); | 162 | in=BIO_new(BIO_s_file()); |
152 | if (!(BIO_read_filename(in,dsaparams))) | 163 | if (!(BIO_read_filename(in,dsaparams))) |
153 | { | 164 | { |
@@ -161,6 +172,7 @@ bad: | |||
161 | goto end; | 172 | goto end; |
162 | } | 173 | } |
163 | BIO_free(in); | 174 | BIO_free(in); |
175 | in = NULL; | ||
164 | 176 | ||
165 | out=BIO_new(BIO_s_file()); | 177 | out=BIO_new(BIO_s_file()); |
166 | if (out == NULL) goto end; | 178 | if (out == NULL) goto end; |
@@ -176,57 +188,30 @@ bad: | |||
176 | } | 188 | } |
177 | } | 189 | } |
178 | 190 | ||
179 | randfile=RAND_file_name(buffer,200); | 191 | if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) |
180 | if ((randfile == NULL)|| !RAND_load_file(randfile,1024L*1024L)) | ||
181 | BIO_printf(bio_err,"unable to load 'random state'\n"); | ||
182 | |||
183 | if (inrand == NULL) | ||
184 | BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); | ||
185 | else | ||
186 | { | 192 | { |
187 | BIO_printf(bio_err,"%ld semi-random bytes loaded\n", | 193 | BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); |
188 | dsa_load_rand(inrand)); | ||
189 | } | 194 | } |
195 | if (inrand != NULL) | ||
196 | BIO_printf(bio_err,"%ld semi-random bytes loaded\n", | ||
197 | app_RAND_load_files(inrand)); | ||
190 | 198 | ||
191 | BIO_printf(bio_err,"Generating DSA key, %d bits\n", | 199 | BIO_printf(bio_err,"Generating DSA key, %d bits\n", |
192 | BN_num_bits(dsa->p)); | 200 | BN_num_bits(dsa->p)); |
193 | if (!DSA_generate_key(dsa)) goto end; | 201 | if (!DSA_generate_key(dsa)) goto end; |
194 | 202 | ||
195 | if (randfile == NULL) | 203 | app_RAND_write_file(NULL, bio_err); |
196 | BIO_printf(bio_err,"unable to write 'random state'\n"); | ||
197 | else | ||
198 | RAND_write_file(randfile); | ||
199 | 204 | ||
200 | if (!PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL,NULL)) | 205 | if (!PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL, passout)) |
201 | goto end; | 206 | goto end; |
202 | ret=0; | 207 | ret=0; |
203 | end: | 208 | end: |
204 | if (ret != 0) | 209 | if (ret != 0) |
205 | ERR_print_errors(bio_err); | 210 | ERR_print_errors(bio_err); |
211 | if (in != NULL) BIO_free(in); | ||
206 | if (out != NULL) BIO_free(out); | 212 | if (out != NULL) BIO_free(out); |
207 | if (dsa != NULL) DSA_free(dsa); | 213 | if (dsa != NULL) DSA_free(dsa); |
214 | if(passout) Free(passout); | ||
208 | EXIT(ret); | 215 | EXIT(ret); |
209 | } | 216 | } |
210 | |||
211 | static long dsa_load_rand(char *name) | ||
212 | { | ||
213 | char *p,*n; | ||
214 | int last; | ||
215 | long tot=0; | ||
216 | |||
217 | for (;;) | ||
218 | { | ||
219 | last=0; | ||
220 | for (p=name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++); | ||
221 | if (*p == '\0') last=1; | ||
222 | *p='\0'; | ||
223 | n=name; | ||
224 | name=p+1; | ||
225 | if (*n == '\0') break; | ||
226 | |||
227 | tot+=RAND_load_file(n,1); | ||
228 | if (last) break; | ||
229 | } | ||
230 | return(tot); | ||
231 | } | ||
232 | #endif | 217 | #endif |