diff options
Diffstat (limited to 'src/lib/libssl/src/apps/gendsa.c')
-rw-r--r-- | src/lib/libssl/src/apps/gendsa.c | 70 |
1 files changed, 41 insertions, 29 deletions
diff --git a/src/lib/libssl/src/apps/gendsa.c b/src/lib/libssl/src/apps/gendsa.c index e0e5afa400..5f00b89bb0 100644 --- a/src/lib/libssl/src/apps/gendsa.c +++ b/src/lib/libssl/src/apps/gendsa.c | |||
@@ -56,39 +56,34 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #ifndef NO_DSA | ||
59 | #include <stdio.h> | 60 | #include <stdio.h> |
60 | #include <string.h> | 61 | #include <string.h> |
61 | #include <sys/types.h> | 62 | #include <sys/types.h> |
62 | #include <sys/stat.h> | 63 | #include <sys/stat.h> |
63 | #include "apps.h" | 64 | #include "apps.h" |
64 | #include "bio.h" | 65 | #include <openssl/bio.h> |
65 | #include "rand.h" | 66 | #include <openssl/rand.h> |
66 | #include "err.h" | 67 | #include <openssl/err.h> |
67 | #include "bn.h" | 68 | #include <openssl/bn.h> |
68 | #include "dsa.h" | 69 | #include <openssl/dsa.h> |
69 | #include "x509.h" | 70 | #include <openssl/x509.h> |
70 | #include "pem.h" | 71 | #include <openssl/pem.h> |
71 | 72 | ||
72 | #define DEFBITS 512 | 73 | #define DEFBITS 512 |
73 | #undef PROG | 74 | #undef PROG |
74 | #define PROG gendsa_main | 75 | #define PROG gendsa_main |
75 | 76 | ||
76 | #ifndef NOPROTO | ||
77 | static long dsa_load_rand(char *names); | 77 | static long dsa_load_rand(char *names); |
78 | #else | 78 | int MAIN(int argc, char **argv) |
79 | static long dsa_load_rand(); | ||
80 | #endif | ||
81 | |||
82 | int MAIN(argc, argv) | ||
83 | int argc; | ||
84 | char **argv; | ||
85 | { | 79 | { |
86 | char buffer[200]; | 80 | char buffer[200]; |
87 | DSA *dsa=NULL; | 81 | DSA *dsa=NULL; |
88 | int ret=1,num=DEFBITS; | 82 | int ret=1; |
89 | char *outfile=NULL; | 83 | char *outfile=NULL; |
90 | char *inrand=NULL,*randfile,*dsaparams=NULL; | 84 | char *inrand=NULL,*randfile,*dsaparams=NULL; |
91 | BIO *out=NULL,*in=NULL; | 85 | BIO *out=NULL,*in=NULL; |
86 | EVP_CIPHER *enc=NULL; | ||
92 | 87 | ||
93 | apps_startup(); | 88 | apps_startup(); |
94 | 89 | ||
@@ -113,9 +108,19 @@ char **argv; | |||
113 | } | 108 | } |
114 | else if (strcmp(*argv,"-") == 0) | 109 | else if (strcmp(*argv,"-") == 0) |
115 | goto bad; | 110 | goto bad; |
116 | else if (dsaparams == NULL) | 111 | #ifndef NO_DES |
112 | else if (strcmp(*argv,"-des") == 0) | ||
113 | enc=EVP_des_cbc(); | ||
114 | else if (strcmp(*argv,"-des3") == 0) | ||
115 | enc=EVP_des_ede3_cbc(); | ||
116 | #endif | ||
117 | #ifndef NO_IDEA | ||
118 | else if (strcmp(*argv,"-idea") == 0) | ||
119 | enc=EVP_idea_cbc(); | ||
120 | #endif | ||
121 | else if (**argv != '-' && dsaparams == NULL) | ||
117 | { | 122 | { |
118 | dsaparams= *argv; | 123 | dsaparams = *argv; |
119 | } | 124 | } |
120 | else | 125 | else |
121 | goto bad; | 126 | goto bad; |
@@ -126,22 +131,31 @@ char **argv; | |||
126 | if (dsaparams == NULL) | 131 | if (dsaparams == NULL) |
127 | { | 132 | { |
128 | bad: | 133 | bad: |
129 | BIO_printf(bio_err,"usage: gendsa [args] [numbits]\n"); | 134 | BIO_printf(bio_err,"usage: gendsa [args] dsaparam-file\n"); |
130 | BIO_printf(bio_err," -out file - output the key to 'file\n"); | 135 | BIO_printf(bio_err," -out file - output the key to 'file'\n"); |
136 | #ifndef NO_DES | ||
137 | BIO_printf(bio_err," -des - encrypt the generated key with DES in cbc mode\n"); | ||
138 | BIO_printf(bio_err," -des3 - encrypt the generated key with DES in ede cbc mode (168 bit key)\n"); | ||
139 | #endif | ||
140 | #ifndef NO_IDEA | ||
141 | BIO_printf(bio_err," -idea - encrypt the generated key with IDEA in cbc mode\n"); | ||
142 | #endif | ||
131 | BIO_printf(bio_err," -rand file:file:...\n"); | 143 | BIO_printf(bio_err," -rand file:file:...\n"); |
132 | BIO_printf(bio_err," - load the file (or the files in the directory) into\n"); | 144 | BIO_printf(bio_err," - load the file (or the files in the directory) into\n"); |
133 | BIO_printf(bio_err," the random number generator\n"); | 145 | BIO_printf(bio_err," the random number generator\n"); |
146 | BIO_printf(bio_err," dsaparam-file\n"); | ||
147 | BIO_printf(bio_err," - a DSA parameter file as generated by the dsaparam command\n"); | ||
134 | goto end; | 148 | goto end; |
135 | } | 149 | } |
136 | 150 | ||
137 | in=BIO_new(BIO_s_file()); | 151 | in=BIO_new(BIO_s_file()); |
138 | if (!(BIO_read_filename(in,"dsaparams"))) | 152 | if (!(BIO_read_filename(in,dsaparams))) |
139 | { | 153 | { |
140 | perror(dsaparams); | 154 | perror(dsaparams); |
141 | goto end; | 155 | goto end; |
142 | } | 156 | } |
143 | 157 | ||
144 | if ((dsa=PEM_read_bio_DSAparams(in,NULL,NULL)) == NULL) | 158 | if ((dsa=PEM_read_bio_DSAparams(in,NULL,NULL,NULL)) == NULL) |
145 | { | 159 | { |
146 | BIO_printf(bio_err,"unable to load DSA parameter file\n"); | 160 | BIO_printf(bio_err,"unable to load DSA parameter file\n"); |
147 | goto end; | 161 | goto end; |
@@ -174,8 +188,8 @@ bad: | |||
174 | dsa_load_rand(inrand)); | 188 | dsa_load_rand(inrand)); |
175 | } | 189 | } |
176 | 190 | ||
177 | BIO_printf(bio_err,"Generating DSA parameters, %d bit long prime\n",num); | 191 | BIO_printf(bio_err,"Generating DSA key, %d bits\n", |
178 | BIO_printf(bio_err,"This could take some time\n"); | 192 | BN_num_bits(dsa->p)); |
179 | if (!DSA_generate_key(dsa)) goto end; | 193 | if (!DSA_generate_key(dsa)) goto end; |
180 | 194 | ||
181 | if (randfile == NULL) | 195 | if (randfile == NULL) |
@@ -183,7 +197,7 @@ bad: | |||
183 | else | 197 | else |
184 | RAND_write_file(randfile); | 198 | RAND_write_file(randfile); |
185 | 199 | ||
186 | if (!PEM_write_bio_DSAPrivateKey(out,dsa,EVP_des_ede3_cbc(),NULL,0,NULL)) | 200 | if (!PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL,NULL)) |
187 | goto end; | 201 | goto end; |
188 | ret=0; | 202 | ret=0; |
189 | end: | 203 | end: |
@@ -194,8 +208,7 @@ end: | |||
194 | EXIT(ret); | 208 | EXIT(ret); |
195 | } | 209 | } |
196 | 210 | ||
197 | static long dsa_load_rand(name) | 211 | static long dsa_load_rand(char *name) |
198 | char *name; | ||
199 | { | 212 | { |
200 | char *p,*n; | 213 | char *p,*n; |
201 | int last; | 214 | int last; |
@@ -216,5 +229,4 @@ char *name; | |||
216 | } | 229 | } |
217 | return(tot); | 230 | return(tot); |
218 | } | 231 | } |
219 | 232 | #endif | |
220 | |||