1ebfedea0SLionel Sambuc /* apps/dsa.c */
2ebfedea0SLionel Sambuc /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3ebfedea0SLionel Sambuc * All rights reserved.
4ebfedea0SLionel Sambuc *
5ebfedea0SLionel Sambuc * This package is an SSL implementation written
6ebfedea0SLionel Sambuc * by Eric Young (eay@cryptsoft.com).
7ebfedea0SLionel Sambuc * The implementation was written so as to conform with Netscapes SSL.
8ebfedea0SLionel Sambuc *
9ebfedea0SLionel Sambuc * This library is free for commercial and non-commercial use as long as
10ebfedea0SLionel Sambuc * the following conditions are aheared to. The following conditions
11ebfedea0SLionel Sambuc * apply to all code found in this distribution, be it the RC4, RSA,
12ebfedea0SLionel Sambuc * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13ebfedea0SLionel Sambuc * included with this distribution is covered by the same copyright terms
14ebfedea0SLionel Sambuc * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15ebfedea0SLionel Sambuc *
16ebfedea0SLionel Sambuc * Copyright remains Eric Young's, and as such any Copyright notices in
17ebfedea0SLionel Sambuc * the code are not to be removed.
18ebfedea0SLionel Sambuc * If this package is used in a product, Eric Young should be given attribution
19ebfedea0SLionel Sambuc * as the author of the parts of the library used.
20ebfedea0SLionel Sambuc * This can be in the form of a textual message at program startup or
21ebfedea0SLionel Sambuc * in documentation (online or textual) provided with the package.
22ebfedea0SLionel Sambuc *
23ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without
24ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions
25ebfedea0SLionel Sambuc * are met:
26ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the copyright
27ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer.
28ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
29ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
30ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution.
31ebfedea0SLionel Sambuc * 3. All advertising materials mentioning features or use of this software
32ebfedea0SLionel Sambuc * must display the following acknowledgement:
33ebfedea0SLionel Sambuc * "This product includes cryptographic software written by
34ebfedea0SLionel Sambuc * Eric Young (eay@cryptsoft.com)"
35ebfedea0SLionel Sambuc * The word 'cryptographic' can be left out if the rouines from the library
36ebfedea0SLionel Sambuc * being used are not cryptographic related :-).
37ebfedea0SLionel Sambuc * 4. If you include any Windows specific code (or a derivative thereof) from
38ebfedea0SLionel Sambuc * the apps directory (application code) you must include an acknowledgement:
39ebfedea0SLionel Sambuc * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40ebfedea0SLionel Sambuc *
41ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42ebfedea0SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44ebfedea0SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45ebfedea0SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46ebfedea0SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47ebfedea0SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48ebfedea0SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49ebfedea0SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50ebfedea0SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51ebfedea0SLionel Sambuc * SUCH DAMAGE.
52ebfedea0SLionel Sambuc *
53ebfedea0SLionel Sambuc * The licence and distribution terms for any publically available version or
54ebfedea0SLionel Sambuc * derivative of this code cannot be changed. i.e. this code cannot simply be
55ebfedea0SLionel Sambuc * copied and put under another distribution licence
56ebfedea0SLionel Sambuc * [including the GNU Public Licence.]
57ebfedea0SLionel Sambuc */
58ebfedea0SLionel Sambuc
59ebfedea0SLionel Sambuc #include <openssl/opensslconf.h> /* for OPENSSL_NO_DSA */
60ebfedea0SLionel Sambuc #ifndef OPENSSL_NO_DSA
61ebfedea0SLionel Sambuc # include <stdio.h>
62ebfedea0SLionel Sambuc # include <stdlib.h>
63ebfedea0SLionel Sambuc # include <string.h>
64ebfedea0SLionel Sambuc # include <time.h>
65ebfedea0SLionel Sambuc # include "apps.h"
66ebfedea0SLionel Sambuc # include <openssl/bio.h>
67ebfedea0SLionel Sambuc # include <openssl/err.h>
68ebfedea0SLionel Sambuc # include <openssl/dsa.h>
69ebfedea0SLionel Sambuc # include <openssl/evp.h>
70ebfedea0SLionel Sambuc # include <openssl/x509.h>
71ebfedea0SLionel Sambuc # include <openssl/pem.h>
72ebfedea0SLionel Sambuc # include <openssl/bn.h>
73ebfedea0SLionel Sambuc
74ebfedea0SLionel Sambuc # undef PROG
75ebfedea0SLionel Sambuc # define PROG dsa_main
76ebfedea0SLionel Sambuc
77*0a6a1f1dSLionel Sambuc /*-
78*0a6a1f1dSLionel Sambuc * -inform arg - input format - default PEM (one of DER, NET or PEM)
79ebfedea0SLionel Sambuc * -outform arg - output format - default PEM
80ebfedea0SLionel Sambuc * -in arg - input file - default stdin
81ebfedea0SLionel Sambuc * -out arg - output file - default stdout
82ebfedea0SLionel Sambuc * -des - encrypt output if PEM format with DES in cbc mode
83ebfedea0SLionel Sambuc * -des3 - encrypt output if PEM format
84ebfedea0SLionel Sambuc * -idea - encrypt output if PEM format
85ebfedea0SLionel Sambuc * -aes128 - encrypt output if PEM format
86ebfedea0SLionel Sambuc * -aes192 - encrypt output if PEM format
87ebfedea0SLionel Sambuc * -aes256 - encrypt output if PEM format
88ebfedea0SLionel Sambuc * -camellia128 - encrypt output if PEM format
89ebfedea0SLionel Sambuc * -camellia192 - encrypt output if PEM format
90ebfedea0SLionel Sambuc * -camellia256 - encrypt output if PEM format
91ebfedea0SLionel Sambuc * -seed - encrypt output if PEM format
92ebfedea0SLionel Sambuc * -text - print a text version
93ebfedea0SLionel Sambuc * -modulus - print the DSA public key
94ebfedea0SLionel Sambuc */
95ebfedea0SLionel Sambuc
96ebfedea0SLionel Sambuc int MAIN(int, char **);
97ebfedea0SLionel Sambuc
MAIN(int argc,char ** argv)98ebfedea0SLionel Sambuc int MAIN(int argc, char **argv)
99ebfedea0SLionel Sambuc {
100ebfedea0SLionel Sambuc ENGINE *e = NULL;
101ebfedea0SLionel Sambuc int ret = 1;
102ebfedea0SLionel Sambuc DSA *dsa = NULL;
103ebfedea0SLionel Sambuc int i, badops = 0;
104ebfedea0SLionel Sambuc const EVP_CIPHER *enc = NULL;
105ebfedea0SLionel Sambuc BIO *in = NULL, *out = NULL;
106ebfedea0SLionel Sambuc int informat, outformat, text = 0, noout = 0;
107ebfedea0SLionel Sambuc int pubin = 0, pubout = 0;
108ebfedea0SLionel Sambuc char *infile, *outfile, *prog;
109ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_ENGINE
110ebfedea0SLionel Sambuc char *engine;
111ebfedea0SLionel Sambuc # endif
112ebfedea0SLionel Sambuc char *passargin = NULL, *passargout = NULL;
113ebfedea0SLionel Sambuc char *passin = NULL, *passout = NULL;
114ebfedea0SLionel Sambuc int modulus = 0;
115ebfedea0SLionel Sambuc
116ebfedea0SLionel Sambuc int pvk_encr = 2;
117ebfedea0SLionel Sambuc
118ebfedea0SLionel Sambuc apps_startup();
119ebfedea0SLionel Sambuc
120ebfedea0SLionel Sambuc if (bio_err == NULL)
121ebfedea0SLionel Sambuc if ((bio_err = BIO_new(BIO_s_file())) != NULL)
122ebfedea0SLionel Sambuc BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
123ebfedea0SLionel Sambuc
124ebfedea0SLionel Sambuc if (!load_config(bio_err, NULL))
125ebfedea0SLionel Sambuc goto end;
126ebfedea0SLionel Sambuc
127ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_ENGINE
128ebfedea0SLionel Sambuc engine = NULL;
129ebfedea0SLionel Sambuc # endif
130ebfedea0SLionel Sambuc infile = NULL;
131ebfedea0SLionel Sambuc outfile = NULL;
132ebfedea0SLionel Sambuc informat = FORMAT_PEM;
133ebfedea0SLionel Sambuc outformat = FORMAT_PEM;
134ebfedea0SLionel Sambuc
135ebfedea0SLionel Sambuc prog = argv[0];
136ebfedea0SLionel Sambuc argc--;
137ebfedea0SLionel Sambuc argv++;
138*0a6a1f1dSLionel Sambuc while (argc >= 1) {
139*0a6a1f1dSLionel Sambuc if (strcmp(*argv, "-inform") == 0) {
140*0a6a1f1dSLionel Sambuc if (--argc < 1)
141*0a6a1f1dSLionel Sambuc goto bad;
142ebfedea0SLionel Sambuc informat = str2fmt(*(++argv));
143*0a6a1f1dSLionel Sambuc } else if (strcmp(*argv, "-outform") == 0) {
144*0a6a1f1dSLionel Sambuc if (--argc < 1)
145*0a6a1f1dSLionel Sambuc goto bad;
146ebfedea0SLionel Sambuc outformat = str2fmt(*(++argv));
147*0a6a1f1dSLionel Sambuc } else if (strcmp(*argv, "-in") == 0) {
148*0a6a1f1dSLionel Sambuc if (--argc < 1)
149*0a6a1f1dSLionel Sambuc goto bad;
150ebfedea0SLionel Sambuc infile = *(++argv);
151*0a6a1f1dSLionel Sambuc } else if (strcmp(*argv, "-out") == 0) {
152*0a6a1f1dSLionel Sambuc if (--argc < 1)
153*0a6a1f1dSLionel Sambuc goto bad;
154ebfedea0SLionel Sambuc outfile = *(++argv);
155*0a6a1f1dSLionel Sambuc } else if (strcmp(*argv, "-passin") == 0) {
156*0a6a1f1dSLionel Sambuc if (--argc < 1)
157*0a6a1f1dSLionel Sambuc goto bad;
158ebfedea0SLionel Sambuc passargin = *(++argv);
159*0a6a1f1dSLionel Sambuc } else if (strcmp(*argv, "-passout") == 0) {
160*0a6a1f1dSLionel Sambuc if (--argc < 1)
161*0a6a1f1dSLionel Sambuc goto bad;
162ebfedea0SLionel Sambuc passargout = *(++argv);
163ebfedea0SLionel Sambuc }
164ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_ENGINE
165*0a6a1f1dSLionel Sambuc else if (strcmp(*argv, "-engine") == 0) {
166*0a6a1f1dSLionel Sambuc if (--argc < 1)
167*0a6a1f1dSLionel Sambuc goto bad;
168ebfedea0SLionel Sambuc engine = *(++argv);
169ebfedea0SLionel Sambuc }
170ebfedea0SLionel Sambuc # endif
171ebfedea0SLionel Sambuc else if (strcmp(*argv, "-pvk-strong") == 0)
172ebfedea0SLionel Sambuc pvk_encr = 2;
173ebfedea0SLionel Sambuc else if (strcmp(*argv, "-pvk-weak") == 0)
174ebfedea0SLionel Sambuc pvk_encr = 1;
175ebfedea0SLionel Sambuc else if (strcmp(*argv, "-pvk-none") == 0)
176ebfedea0SLionel Sambuc pvk_encr = 0;
177ebfedea0SLionel Sambuc else if (strcmp(*argv, "-noout") == 0)
178ebfedea0SLionel Sambuc noout = 1;
179ebfedea0SLionel Sambuc else if (strcmp(*argv, "-text") == 0)
180ebfedea0SLionel Sambuc text = 1;
181ebfedea0SLionel Sambuc else if (strcmp(*argv, "-modulus") == 0)
182ebfedea0SLionel Sambuc modulus = 1;
183ebfedea0SLionel Sambuc else if (strcmp(*argv, "-pubin") == 0)
184ebfedea0SLionel Sambuc pubin = 1;
185ebfedea0SLionel Sambuc else if (strcmp(*argv, "-pubout") == 0)
186ebfedea0SLionel Sambuc pubout = 1;
187*0a6a1f1dSLionel Sambuc else if ((enc = EVP_get_cipherbyname(&(argv[0][1]))) == NULL) {
188ebfedea0SLionel Sambuc BIO_printf(bio_err, "unknown option %s\n", *argv);
189ebfedea0SLionel Sambuc badops = 1;
190ebfedea0SLionel Sambuc break;
191ebfedea0SLionel Sambuc }
192ebfedea0SLionel Sambuc argc--;
193ebfedea0SLionel Sambuc argv++;
194ebfedea0SLionel Sambuc }
195ebfedea0SLionel Sambuc
196*0a6a1f1dSLionel Sambuc if (badops) {
197ebfedea0SLionel Sambuc bad:
198ebfedea0SLionel Sambuc BIO_printf(bio_err, "%s [options] <infile >outfile\n", prog);
199ebfedea0SLionel Sambuc BIO_printf(bio_err, "where options are\n");
200ebfedea0SLionel Sambuc BIO_printf(bio_err, " -inform arg input format - DER or PEM\n");
201ebfedea0SLionel Sambuc BIO_printf(bio_err, " -outform arg output format - DER or PEM\n");
202ebfedea0SLionel Sambuc BIO_printf(bio_err, " -in arg input file\n");
203*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
204*0a6a1f1dSLionel Sambuc " -passin arg input file pass phrase source\n");
205ebfedea0SLionel Sambuc BIO_printf(bio_err, " -out arg output file\n");
206*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
207*0a6a1f1dSLionel Sambuc " -passout arg output file pass phrase source\n");
208ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_ENGINE
209*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
210*0a6a1f1dSLionel Sambuc " -engine e use engine e, possibly a hardware device.\n");
211ebfedea0SLionel Sambuc # endif
212*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
213*0a6a1f1dSLionel Sambuc " -des encrypt PEM output with cbc des\n");
214*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
215*0a6a1f1dSLionel Sambuc " -des3 encrypt PEM output with ede cbc des using 168 bit key\n");
216ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_IDEA
217*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
218*0a6a1f1dSLionel Sambuc " -idea encrypt PEM output with cbc idea\n");
219ebfedea0SLionel Sambuc # endif
220ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_AES
221ebfedea0SLionel Sambuc BIO_printf(bio_err, " -aes128, -aes192, -aes256\n");
222*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
223*0a6a1f1dSLionel Sambuc " encrypt PEM output with cbc aes\n");
224ebfedea0SLionel Sambuc # endif
225ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_CAMELLIA
226ebfedea0SLionel Sambuc BIO_printf(bio_err, " -camellia128, -camellia192, -camellia256\n");
227*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
228*0a6a1f1dSLionel Sambuc " encrypt PEM output with cbc camellia\n");
229ebfedea0SLionel Sambuc # endif
230ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_SEED
231*0a6a1f1dSLionel Sambuc BIO_printf(bio_err,
232*0a6a1f1dSLionel Sambuc " -seed encrypt PEM output with cbc seed\n");
233ebfedea0SLionel Sambuc # endif
234ebfedea0SLionel Sambuc BIO_printf(bio_err, " -text print the key in text\n");
235ebfedea0SLionel Sambuc BIO_printf(bio_err, " -noout don't print key out\n");
236ebfedea0SLionel Sambuc BIO_printf(bio_err, " -modulus print the DSA public value\n");
237ebfedea0SLionel Sambuc goto end;
238ebfedea0SLionel Sambuc }
239ebfedea0SLionel Sambuc
240ebfedea0SLionel Sambuc ERR_load_crypto_strings();
241ebfedea0SLionel Sambuc
242ebfedea0SLionel Sambuc # ifndef OPENSSL_NO_ENGINE
243ebfedea0SLionel Sambuc e = setup_engine(bio_err, engine, 0);
244ebfedea0SLionel Sambuc # endif
245ebfedea0SLionel Sambuc
246ebfedea0SLionel Sambuc if (!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
247ebfedea0SLionel Sambuc BIO_printf(bio_err, "Error getting passwords\n");
248ebfedea0SLionel Sambuc goto end;
249ebfedea0SLionel Sambuc }
250ebfedea0SLionel Sambuc
251ebfedea0SLionel Sambuc in = BIO_new(BIO_s_file());
252ebfedea0SLionel Sambuc out = BIO_new(BIO_s_file());
253*0a6a1f1dSLionel Sambuc if ((in == NULL) || (out == NULL)) {
254ebfedea0SLionel Sambuc ERR_print_errors(bio_err);
255ebfedea0SLionel Sambuc goto end;
256ebfedea0SLionel Sambuc }
257ebfedea0SLionel Sambuc
258ebfedea0SLionel Sambuc if (infile == NULL)
259ebfedea0SLionel Sambuc BIO_set_fp(in, stdin, BIO_NOCLOSE);
260*0a6a1f1dSLionel Sambuc else {
261*0a6a1f1dSLionel Sambuc if (BIO_read_filename(in, infile) <= 0) {
262ebfedea0SLionel Sambuc perror(infile);
263ebfedea0SLionel Sambuc goto end;
264ebfedea0SLionel Sambuc }
265ebfedea0SLionel Sambuc }
266ebfedea0SLionel Sambuc
267ebfedea0SLionel Sambuc BIO_printf(bio_err, "read DSA key\n");
268ebfedea0SLionel Sambuc
269ebfedea0SLionel Sambuc {
270ebfedea0SLionel Sambuc EVP_PKEY *pkey;
271ebfedea0SLionel Sambuc
272ebfedea0SLionel Sambuc if (pubin)
273ebfedea0SLionel Sambuc pkey = load_pubkey(bio_err, infile, informat, 1,
274ebfedea0SLionel Sambuc passin, e, "Public Key");
275ebfedea0SLionel Sambuc else
276ebfedea0SLionel Sambuc pkey = load_key(bio_err, infile, informat, 1,
277ebfedea0SLionel Sambuc passin, e, "Private Key");
278ebfedea0SLionel Sambuc
279*0a6a1f1dSLionel Sambuc if (pkey) {
280ebfedea0SLionel Sambuc dsa = EVP_PKEY_get1_DSA(pkey);
281ebfedea0SLionel Sambuc EVP_PKEY_free(pkey);
282ebfedea0SLionel Sambuc }
283ebfedea0SLionel Sambuc }
284*0a6a1f1dSLionel Sambuc if (dsa == NULL) {
285ebfedea0SLionel Sambuc BIO_printf(bio_err, "unable to load Key\n");
286ebfedea0SLionel Sambuc ERR_print_errors(bio_err);
287ebfedea0SLionel Sambuc goto end;
288ebfedea0SLionel Sambuc }
289ebfedea0SLionel Sambuc
290*0a6a1f1dSLionel Sambuc if (outfile == NULL) {
291ebfedea0SLionel Sambuc BIO_set_fp(out, stdout, BIO_NOCLOSE);
292ebfedea0SLionel Sambuc # ifdef OPENSSL_SYS_VMS
293ebfedea0SLionel Sambuc {
294ebfedea0SLionel Sambuc BIO *tmpbio = BIO_new(BIO_f_linebuffer());
295ebfedea0SLionel Sambuc out = BIO_push(tmpbio, out);
296ebfedea0SLionel Sambuc }
297ebfedea0SLionel Sambuc # endif
298*0a6a1f1dSLionel Sambuc } else {
299*0a6a1f1dSLionel Sambuc if (BIO_write_filename(out, outfile) <= 0) {
300ebfedea0SLionel Sambuc perror(outfile);
301ebfedea0SLionel Sambuc goto end;
302ebfedea0SLionel Sambuc }
303ebfedea0SLionel Sambuc }
304ebfedea0SLionel Sambuc
305ebfedea0SLionel Sambuc if (text)
306*0a6a1f1dSLionel Sambuc if (!DSA_print(out, dsa, 0)) {
307ebfedea0SLionel Sambuc perror(outfile);
308ebfedea0SLionel Sambuc ERR_print_errors(bio_err);
309ebfedea0SLionel Sambuc goto end;
310ebfedea0SLionel Sambuc }
311ebfedea0SLionel Sambuc
312*0a6a1f1dSLionel Sambuc if (modulus) {
313ebfedea0SLionel Sambuc fprintf(stdout, "Public Key=");
314ebfedea0SLionel Sambuc BN_print(out, dsa->pub_key);
315ebfedea0SLionel Sambuc fprintf(stdout, "\n");
316ebfedea0SLionel Sambuc }
317ebfedea0SLionel Sambuc
318*0a6a1f1dSLionel Sambuc if (noout)
319*0a6a1f1dSLionel Sambuc goto end;
320ebfedea0SLionel Sambuc BIO_printf(bio_err, "writing DSA key\n");
321ebfedea0SLionel Sambuc if (outformat == FORMAT_ASN1) {
322*0a6a1f1dSLionel Sambuc if (pubin || pubout)
323*0a6a1f1dSLionel Sambuc i = i2d_DSA_PUBKEY_bio(out, dsa);
324*0a6a1f1dSLionel Sambuc else
325*0a6a1f1dSLionel Sambuc i = i2d_DSAPrivateKey_bio(out, dsa);
326ebfedea0SLionel Sambuc } else if (outformat == FORMAT_PEM) {
327ebfedea0SLionel Sambuc if (pubin || pubout)
328ebfedea0SLionel Sambuc i = PEM_write_bio_DSA_PUBKEY(out, dsa);
329*0a6a1f1dSLionel Sambuc else
330*0a6a1f1dSLionel Sambuc i = PEM_write_bio_DSAPrivateKey(out, dsa, enc,
331ebfedea0SLionel Sambuc NULL, 0, NULL, passout);
332ebfedea0SLionel Sambuc # if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_RC4)
333ebfedea0SLionel Sambuc } else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) {
334ebfedea0SLionel Sambuc EVP_PKEY *pk;
335ebfedea0SLionel Sambuc pk = EVP_PKEY_new();
336ebfedea0SLionel Sambuc EVP_PKEY_set1_DSA(pk, dsa);
337ebfedea0SLionel Sambuc if (outformat == FORMAT_PVK)
338ebfedea0SLionel Sambuc i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);
339ebfedea0SLionel Sambuc else if (pubin || pubout)
340ebfedea0SLionel Sambuc i = i2b_PublicKey_bio(out, pk);
341ebfedea0SLionel Sambuc else
342ebfedea0SLionel Sambuc i = i2b_PrivateKey_bio(out, pk);
343ebfedea0SLionel Sambuc EVP_PKEY_free(pk);
344ebfedea0SLionel Sambuc # endif
345ebfedea0SLionel Sambuc } else {
346ebfedea0SLionel Sambuc BIO_printf(bio_err, "bad output format specified for outfile\n");
347ebfedea0SLionel Sambuc goto end;
348ebfedea0SLionel Sambuc }
349*0a6a1f1dSLionel Sambuc if (i <= 0) {
350ebfedea0SLionel Sambuc BIO_printf(bio_err, "unable to write private key\n");
351ebfedea0SLionel Sambuc ERR_print_errors(bio_err);
352*0a6a1f1dSLionel Sambuc } else
353ebfedea0SLionel Sambuc ret = 0;
354ebfedea0SLionel Sambuc end:
355*0a6a1f1dSLionel Sambuc if (in != NULL)
356*0a6a1f1dSLionel Sambuc BIO_free(in);
357*0a6a1f1dSLionel Sambuc if (out != NULL)
358*0a6a1f1dSLionel Sambuc BIO_free_all(out);
359*0a6a1f1dSLionel Sambuc if (dsa != NULL)
360*0a6a1f1dSLionel Sambuc DSA_free(dsa);
361*0a6a1f1dSLionel Sambuc if (passin)
362*0a6a1f1dSLionel Sambuc OPENSSL_free(passin);
363*0a6a1f1dSLionel Sambuc if (passout)
364*0a6a1f1dSLionel Sambuc OPENSSL_free(passout);
365ebfedea0SLionel Sambuc apps_shutdown();
366ebfedea0SLionel Sambuc OPENSSL_EXIT(ret);
367ebfedea0SLionel Sambuc }
368ebfedea0SLionel Sambuc #else /* !OPENSSL_NO_DSA */
369ebfedea0SLionel Sambuc
370ebfedea0SLionel Sambuc # if PEDANTIC
371ebfedea0SLionel Sambuc static void *dummy = &dummy;
372ebfedea0SLionel Sambuc # endif
373ebfedea0SLionel Sambuc
374ebfedea0SLionel Sambuc #endif
375