blob: 392e6a2ef64891bdfc3b79f43e016a8fc8e8d29c [file] [log] [blame]
Bodo Möllerd4a8f902002-08-26 11:20:50 +00001/* apps/ec.c */
2/*
3 * Written by Nils Larsch for the OpenSSL project.
4 */
Bodo Möller4d94ae02002-02-13 18:21:51 +00005/* ====================================================================
6 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
Bodo Möller4d94ae02002-02-13 18:21:51 +000058
Bodo Möllerd4a8f902002-08-26 11:20:50 +000059#ifndef OPENSSL_NO_EC
Bodo Möller4d94ae02002-02-13 18:21:51 +000060#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
Bodo Möller4d94ae02002-02-13 18:21:51 +000063#include "apps.h"
64#include <openssl/bio.h>
65#include <openssl/err.h>
Bodo Möller4d94ae02002-02-13 18:21:51 +000066#include <openssl/evp.h>
Bodo Möller4d94ae02002-02-13 18:21:51 +000067#include <openssl/pem.h>
68
69#undef PROG
Bodo Möllerd4a8f902002-08-26 11:20:50 +000070#define PROG ec_main
Bodo Möller4d94ae02002-02-13 18:21:51 +000071
Bodo Möllereefa6e42002-07-23 09:51:57 +000072/* -inform arg - input format - default PEM (one of DER, NET or PEM)
73 * -outform arg - output format - default PEM
74 * -in arg - input file - default stdin
75 * -out arg - output file - default stdout
76 * -des - encrypt output if PEM format with DES in cbc mode
77 * -text - print a text version
78 * -param_out - print the elliptic curve parameters
79 * -conv_form arg - specifies the point encoding form
80 * -param_enc arg - specifies the parameter encoding
Bodo Möller4d94ae02002-02-13 18:21:51 +000081 */
82
83int MAIN(int, char **);
84
85int MAIN(int argc, char **argv)
86{
Geoff Thorpe58ae65c2004-10-21 00:06:14 +000087#ifndef OPENSSL_NO_ENGINE
Bodo Möller4d94ae02002-02-13 18:21:51 +000088 ENGINE *e = NULL;
Geoff Thorpe58ae65c2004-10-21 00:06:14 +000089#endif
Bodo Möller4d94ae02002-02-13 18:21:51 +000090 int ret = 1;
Bodo Möller14a7cfb2002-08-07 10:49:54 +000091 EC_KEY *eckey = NULL;
Bodo Möller4d94ae02002-02-13 18:21:51 +000092 int i, badops = 0;
93 const EVP_CIPHER *enc = NULL;
94 BIO *in = NULL, *out = NULL;
95 int informat, outformat, text=0, noout=0;
Bodo Möllereefa6e42002-07-23 09:51:57 +000096 int pubin = 0, pubout = 0, param_out = 0;
Bodo Möller4d94ae02002-02-13 18:21:51 +000097 char *infile, *outfile, *prog, *engine;
98 char *passargin = NULL, *passargout = NULL;
99 char *passin = NULL, *passout = NULL;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000100 point_conversion_form_t form = POINT_CONVERSION_UNCOMPRESSED;
101 int new_form = 0;
102 int asn1_flag = OPENSSL_EC_NAMED_CURVE;
103 int new_asn1_flag = 0;
Bodo Möller4d94ae02002-02-13 18:21:51 +0000104
105 apps_startup();
106
107 if (bio_err == NULL)
108 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
109 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT);
110
Dr. Stephen Henson3647bee2002-02-22 14:01:21 +0000111 if (!load_config(bio_err, NULL))
112 goto end;
113
Bodo Möller4d94ae02002-02-13 18:21:51 +0000114 engine = NULL;
115 infile = NULL;
116 outfile = NULL;
117 informat = FORMAT_PEM;
118 outformat = FORMAT_PEM;
119
120 prog = argv[0];
121 argc--;
122 argv++;
123 while (argc >= 1)
Bodo Möller4d94ae02002-02-13 18:21:51 +0000124 {
Bodo Möllereefa6e42002-07-23 09:51:57 +0000125 if (strcmp(*argv,"-inform") == 0)
126 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000127 if (--argc < 1) goto bad;
128 informat=str2fmt(*(++argv));
Bodo Möllereefa6e42002-07-23 09:51:57 +0000129 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000130 else if (strcmp(*argv,"-outform") == 0)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000131 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000132 if (--argc < 1) goto bad;
133 outformat=str2fmt(*(++argv));
Bodo Möllereefa6e42002-07-23 09:51:57 +0000134 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000135 else if (strcmp(*argv,"-in") == 0)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000136 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000137 if (--argc < 1) goto bad;
138 infile= *(++argv);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000139 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000140 else if (strcmp(*argv,"-out") == 0)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000141 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000142 if (--argc < 1) goto bad;
143 outfile= *(++argv);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000144 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000145 else if (strcmp(*argv,"-passin") == 0)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000146 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000147 if (--argc < 1) goto bad;
148 passargin= *(++argv);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000149 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000150 else if (strcmp(*argv,"-passout") == 0)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000151 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000152 if (--argc < 1) goto bad;
153 passargout= *(++argv);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000154 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000155 else if (strcmp(*argv, "-engine") == 0)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000156 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000157 if (--argc < 1) goto bad;
158 engine= *(++argv);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000159 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000160 else if (strcmp(*argv, "-noout") == 0)
161 noout = 1;
162 else if (strcmp(*argv, "-text") == 0)
163 text = 1;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000164 else if (strcmp(*argv, "-conv_form") == 0)
Bodo Möller4d94ae02002-02-13 18:21:51 +0000165 {
Bodo Möllereefa6e42002-07-23 09:51:57 +0000166 if (--argc < 1)
167 goto bad;
168 ++argv;
169 new_form = 1;
170 if (strcmp(*argv, "compressed") == 0)
171 form = POINT_CONVERSION_COMPRESSED;
172 else if (strcmp(*argv, "uncompressed") == 0)
173 form = POINT_CONVERSION_UNCOMPRESSED;
174 else if (strcmp(*argv, "hybrid") == 0)
175 form = POINT_CONVERSION_HYBRID;
176 else
177 goto bad;
Bodo Möller4d94ae02002-02-13 18:21:51 +0000178 }
Bodo Möllereefa6e42002-07-23 09:51:57 +0000179 else if (strcmp(*argv, "-param_enc") == 0)
180 {
181 if (--argc < 1)
182 goto bad;
183 ++argv;
184 new_asn1_flag = 1;
185 if (strcmp(*argv, "named_curve") == 0)
186 asn1_flag = OPENSSL_EC_NAMED_CURVE;
187 else if (strcmp(*argv, "explicit") == 0)
188 asn1_flag = 0;
189 else
190 goto bad;
191 }
192 else if (strcmp(*argv, "-param_out") == 0)
193 param_out = 1;
Bodo Möller4d94ae02002-02-13 18:21:51 +0000194 else if (strcmp(*argv, "-pubin") == 0)
195 pubin=1;
196 else if (strcmp(*argv, "-pubout") == 0)
197 pubout=1;
198 else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000199 {
200 BIO_printf(bio_err, "unknown option %s\n", *argv);
Bodo Möller4d94ae02002-02-13 18:21:51 +0000201 badops=1;
202 break;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000203 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000204 argc--;
205 argv++;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000206 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000207
208 if (badops)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000209 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000210bad:
Bodo Möllereefa6e42002-07-23 09:51:57 +0000211 BIO_printf(bio_err, "%s [options] <infile >outfile\n", prog);
Bodo Möller4d94ae02002-02-13 18:21:51 +0000212 BIO_printf(bio_err, "where options are\n");
Bodo Möllereefa6e42002-07-23 09:51:57 +0000213 BIO_printf(bio_err, " -inform arg input format - "
214 "DER or PEM\n");
215 BIO_printf(bio_err, " -outform arg output format - "
216 "DER or PEM\n");
Bodo Möller4d94ae02002-02-13 18:21:51 +0000217 BIO_printf(bio_err, " -in arg input file\n");
Bodo Möllereefa6e42002-07-23 09:51:57 +0000218 BIO_printf(bio_err, " -passin arg input file pass "
219 "phrase source\n");
Bodo Möller4d94ae02002-02-13 18:21:51 +0000220 BIO_printf(bio_err, " -out arg output file\n");
Bodo Möllereefa6e42002-07-23 09:51:57 +0000221 BIO_printf(bio_err, " -passout arg output file pass "
222 "phrase source\n");
223 BIO_printf(bio_err, " -engine e use engine e, "
224 "possibly a hardware device.\n");
225 BIO_printf(bio_err, " -des encrypt PEM output, "
226 "instead of 'des' every other \n"
227 " cipher "
228 "supported by OpenSSL can be used\n");
229 BIO_printf(bio_err, " -text print the key\n");
Bodo Möller4d94ae02002-02-13 18:21:51 +0000230 BIO_printf(bio_err, " -noout don't print key out\n");
Bodo Möllereefa6e42002-07-23 09:51:57 +0000231 BIO_printf(bio_err, " -param_out print the elliptic "
232 "curve parameters\n");
233 BIO_printf(bio_err, " -conv_form arg specifies the "
234 "point conversion form \n");
Bodo Möllerc96f0fd2002-08-26 14:50:52 +0000235 BIO_printf(bio_err, " possible values:"
Bodo Möllereefa6e42002-07-23 09:51:57 +0000236 " compressed\n");
Bodo Möllerc96f0fd2002-08-26 14:50:52 +0000237 BIO_printf(bio_err, " "
Bodo Möllereefa6e42002-07-23 09:51:57 +0000238 " uncompressed (default)\n");
239 BIO_printf(bio_err, " "
240 " hybrid\n");
241 BIO_printf(bio_err, " -param_enc arg specifies the way"
242 " the ec parameters are encoded\n");
243 BIO_printf(bio_err, " in the asn1 der "
244 "encoding\n");
Bodo Möllerc96f0fd2002-08-26 14:50:52 +0000245 BIO_printf(bio_err, " possilbe values:"
Bodo Möllereefa6e42002-07-23 09:51:57 +0000246 " named_curve (default)\n");
Bodo Möllerc96f0fd2002-08-26 14:50:52 +0000247 BIO_printf(bio_err," "
Bodo Möllereefa6e42002-07-23 09:51:57 +0000248 "explicit\n");
Bodo Möller4d94ae02002-02-13 18:21:51 +0000249 goto end;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000250 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000251
252 ERR_load_crypto_strings();
253
Geoff Thorpe58ae65c2004-10-21 00:06:14 +0000254#ifndef OPENSSL_NO_ENGINE
Bodo Möller4d94ae02002-02-13 18:21:51 +0000255 e = setup_engine(bio_err, engine, 0);
Geoff Thorpe58ae65c2004-10-21 00:06:14 +0000256#endif
Bodo Möller4d94ae02002-02-13 18:21:51 +0000257
258 if(!app_passwd(bio_err, passargin, passargout, &passin, &passout))
Bodo Möllereefa6e42002-07-23 09:51:57 +0000259 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000260 BIO_printf(bio_err, "Error getting passwords\n");
261 goto end;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000262 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000263
264 in = BIO_new(BIO_s_file());
265 out = BIO_new(BIO_s_file());
266 if ((in == NULL) || (out == NULL))
Bodo Möllereefa6e42002-07-23 09:51:57 +0000267 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000268 ERR_print_errors(bio_err);
269 goto end;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000270 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000271
272 if (infile == NULL)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000273 BIO_set_fp(in, stdin, BIO_NOCLOSE);
Bodo Möller4d94ae02002-02-13 18:21:51 +0000274 else
Bodo Möller4d94ae02002-02-13 18:21:51 +0000275 {
Bodo Möllereefa6e42002-07-23 09:51:57 +0000276 if (BIO_read_filename(in, infile) <= 0)
277 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000278 perror(infile);
279 goto end;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000280 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000281 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000282
Bodo Möllerd4a8f902002-08-26 11:20:50 +0000283 BIO_printf(bio_err, "read EC key\n");
Bodo Möller4d94ae02002-02-13 18:21:51 +0000284 if (informat == FORMAT_ASN1)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000285 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000286 if (pubin)
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000287 eckey = d2i_EC_PUBKEY_bio(in, NULL);
Bodo Möller4d94ae02002-02-13 18:21:51 +0000288 else
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000289 eckey = d2i_ECPrivateKey_bio(in, NULL);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000290 }
291 else if (informat == FORMAT_PEM)
292 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000293 if (pubin)
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000294 eckey = PEM_read_bio_EC_PUBKEY(in, NULL, NULL,
Bodo Möllereefa6e42002-07-23 09:51:57 +0000295 NULL);
Bodo Möller4d94ae02002-02-13 18:21:51 +0000296 else
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000297 eckey = PEM_read_bio_ECPrivateKey(in, NULL, NULL,
Bodo Möllereefa6e42002-07-23 09:51:57 +0000298 passin);
299 }
300 else
301 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000302 BIO_printf(bio_err, "bad input format specified for key\n");
303 goto end;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000304 }
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000305 if (eckey == NULL)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000306 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000307 BIO_printf(bio_err,"unable to load Key\n");
308 ERR_print_errors(bio_err);
309 goto end;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000310 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000311
312 if (outfile == NULL)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000313 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000314 BIO_set_fp(out, stdout, BIO_NOCLOSE);
315#ifdef OPENSSL_SYS_VMS
Bodo Möllereefa6e42002-07-23 09:51:57 +0000316 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000317 BIO *tmpbio = BIO_new(BIO_f_linebuffer());
318 out = BIO_push(tmpbio, out);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000319 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000320#endif
Bodo Möllereefa6e42002-07-23 09:51:57 +0000321 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000322 else
Bodo Möller4d94ae02002-02-13 18:21:51 +0000323 {
Bodo Möllereefa6e42002-07-23 09:51:57 +0000324 if (BIO_write_filename(out, outfile) <= 0)
325 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000326 perror(outfile);
327 goto end;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000328 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000329 }
Bodo Möllereefa6e42002-07-23 09:51:57 +0000330
331 if (new_form)
332 {
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000333 EC_GROUP_set_point_conversion_form(eckey->group, form);
334 eckey->conv_form = form;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000335 }
336
337 if (new_asn1_flag)
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000338 EC_GROUP_set_asn1_flag(eckey->group, asn1_flag);
Bodo Möller4d94ae02002-02-13 18:21:51 +0000339
340 if (text)
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000341 if (!EC_KEY_print(out, eckey, 0))
Bodo Möllereefa6e42002-07-23 09:51:57 +0000342 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000343 perror(outfile);
344 ERR_print_errors(bio_err);
345 goto end;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000346 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000347
348 if (noout)
349 goto end;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000350
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000351 BIO_printf(bio_err, "writing EC key\n");
Bodo Möller4d94ae02002-02-13 18:21:51 +0000352 if (outformat == FORMAT_ASN1)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000353 {
354 if (param_out)
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000355 i = i2d_ECPKParameters_bio(out, eckey->group);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000356 else if (pubin || pubout)
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000357 i = i2d_EC_PUBKEY_bio(out, eckey);
Bodo Möller4d94ae02002-02-13 18:21:51 +0000358 else
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000359 i = i2d_ECPrivateKey_bio(out, eckey);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000360 }
361 else if (outformat == FORMAT_PEM)
362 {
363 if (param_out)
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000364 i = PEM_write_bio_ECPKParameters(out, eckey->group);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000365 else if (pubin || pubout)
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000366 i = PEM_write_bio_EC_PUBKEY(out, eckey);
Bodo Möller4d94ae02002-02-13 18:21:51 +0000367 else
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000368 i = PEM_write_bio_ECPrivateKey(out, eckey, enc,
Bodo Möllereefa6e42002-07-23 09:51:57 +0000369 NULL, 0, NULL, passout);
370 }
371 else
372 {
373 BIO_printf(bio_err, "bad output format specified for "
374 "outfile\n");
Bodo Möller4d94ae02002-02-13 18:21:51 +0000375 goto end;
Bodo Möllereefa6e42002-07-23 09:51:57 +0000376 }
377
Bodo Möller4d94ae02002-02-13 18:21:51 +0000378 if (!i)
Bodo Möllereefa6e42002-07-23 09:51:57 +0000379 {
Bodo Möller4d94ae02002-02-13 18:21:51 +0000380 BIO_printf(bio_err, "unable to write private key\n");
381 ERR_print_errors(bio_err);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000382 }
Bodo Möller4d94ae02002-02-13 18:21:51 +0000383 else
384 ret=0;
385end:
Bodo Möllereefa6e42002-07-23 09:51:57 +0000386 if (in)
387 BIO_free(in);
388 if (out)
389 BIO_free_all(out);
Bodo Möller14a7cfb2002-08-07 10:49:54 +0000390 if (eckey)
391 EC_KEY_free(eckey);
Bodo Möllereefa6e42002-07-23 09:51:57 +0000392 if (passin)
393 OPENSSL_free(passin);
394 if (passout)
395 OPENSSL_free(passout);
Bodo Möller4d94ae02002-02-13 18:21:51 +0000396 apps_shutdown();
Richard Levitte1c3e4a32002-12-03 16:33:03 +0000397 OPENSSL_EXIT(ret);
Bodo Möller4d94ae02002-02-13 18:21:51 +0000398}
399#endif