2 /* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
31 * 6. Redistributions of any form whatsoever must retain the following
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
55 /* ====================================================================
56 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
58 * Portions of the attached software ("Contribution") are developed by
59 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
61 * The Contribution is licensed pursuant to the OpenSSL open source
62 * license provided above.
64 * In addition, Sun covenants to all licensees who provide a reciprocal
65 * covenant with respect to their own patents if any, not to sue under
66 * current and future patent claims necessarily infringed by the making,
67 * using, practicing, selling, offering for sale and/or otherwise
68 * disposing of the Contribution as delivered hereunder
69 * (or portions thereof), provided that such covenant shall not apply:
70 * 1) for code that a licensee deletes from the Contribution;
71 * 2) separates from the Contribution; or
72 * 3) for infringements caused by:
73 * i) the modification of the Contribution or
74 * ii) the combination of the Contribution with other software or
75 * devices where such combination causes the infringement.
77 * The elliptic curve binary polynomial software is originally written by
78 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
81 #ifndef OPENSSL_NO_ECDSA
88 #include <openssl/bio.h>
89 #include <openssl/err.h>
90 #include <openssl/bn.h>
91 #include <openssl/ec.h>
92 #include <openssl/ecdsa.h>
93 #include <openssl/x509.h>
94 #include <openssl/pem.h>
97 #define PROG ecparam_main
99 /* -inform arg - input format - default PEM (DER or PEM)
100 * -outform arg - output format - default PEM
101 * -in arg - input file - default stdin
102 * -out arg - output file - default stdout
105 * -check - validate the ec parameters
108 * -name file - use the ecparameters with 'short name' name
109 * -list_curves - prints a list of all currently available curve
110 * 'short names' and exits
111 * -conv_form - specifies the point conversion form
112 * possible values : compressed
113 * uncompressed (default)
115 * -param_enc - specifies the way the ec parameters are encoded
116 * in the asn1 der encoding
117 * possilbe values : named_curve (default)
119 * -no_seed - if 'explicit' parameters are choosen do not
121 * -genkey - generates a ecdsa private key
123 * -engine e - use engine e, possible a hardware device
126 static const char *curve_list[67] = {
127 "prime192v1 - 192 bit prime curve from the X9.62 draft",
128 "prime192v2 - 192 bit prime curve from the X9.62 draft",
129 "prime192v3 - 192 bit prime curve from the X9.62 draft",
130 "prime239v1 - 239 bit prime curve from the X9.62 draft",
131 "prime239v2 - 239 bit prime curve from the X9.62 draft",
132 "prime239v3 - 239 bit prime curve from the X9.62 draft",
133 "prime256v1 - 256 bit prime curve from the X9.62 draft",
134 "secp112r1 - SECG recommended curve over a 112 bit prime field",
135 "secp112r2 - SECG recommended curve over a 112 bit prime field",
136 "secp128r1 - SECG recommended curve over a 128 bit prime field",
137 "secp128r2 - SECG recommended curve over a 128 bit prime field",
138 "secp160k1 - SECG recommended curve over a 160 bit prime field",
139 "secp160r1 - SECG recommended curve over a 160 bit prime field",
140 "secp160r2 - SECG recommended curve over a 160 bit prime field",
141 "secp192k1 - SECG recommended curve over a 192 bit prime field",
142 "prime192v1 - SECG recommended curve over a 192 bit prime field (aka secp192r1)",
143 "secp224k1 - SECG recommended curve over a 224 bit prime field",
144 "secp224r1 - SECG/NIST recommended curve over a 224 bit prime field",
145 "secp256k1 - SECG recommended curve over a 256 bit prime field",
146 "prime256v1 - SECG recommended curve over a 256 bit prime field (aka secp256r1)",
147 "secp384r1 - SECG/NIST recommended curve over a 384 bit prime field",
148 "secp521r1 - SECG/NIST recommended curve over a 521 bit prime field",
149 "wap-wsg-idm-ecid-wtls6 - 112 bit prime curve from the WTLS standard",
150 "wap-wsg-idm-ecid-wtls8 - 112 bit prime curve from the WTLS standard",
151 "wap-wsg-idm-ecid-wtls7 - 160 bit prime curve from the WTLS standard",
152 "wap-wsg-idm-ecid-wtls9 - 160 bit prime curve from the WTLS standard",
153 "wap-wsg-idm-ecid-wtls12 - 224 bit prime curve from the WTLS standard",
154 "c2pnb163v1 - 163 bit binary curve from the X9.62 draft",
155 "c2pnb163v2 - 163 bit binary curve from the X9.62 draft",
156 "c2pnb163v3 - 163 bit binary curve from the X9.62 draft",
157 "c2pnb176v1 - 176 bit binary curve from the X9.62 draft",
158 "c2tnb191v1 - 191 bit binary curve from the X9.62 draft",
159 "c2tnb191v2 - 191 bit binary curve from the X9.62 draft",
160 "c2tnb191v3 - 191 bit binary curve from the X9.62 draft",
161 "c2pnb208w1 - 208 bit binary curve from the X9.62 draft",
162 "c2tnb239v1 - 239 bit binary curve from the X9.62 draft",
163 "c2tnb239v2 - 239 bit binary curve from the X9.62 draft",
164 "c2tnb239v3 - 239 bit binary curve from the X9.62 draft",
165 "c2pnb272w1 - 272 bit binary curve from the X9.62 draft",
166 "c2pnb304w1 - 304 bit binary curve from the X9.62 draft",
167 "c2tnb359v1 - 359 bit binary curve from the X9.62 draft",
168 "c2pnb368w1 - 368 bit binary curve from the X9.62 draft",
169 "c2tnb431r1 - 431 bit binary curve from the X9.62 draft",
170 "sect113r1 - SECG recommended curve over a 113 bit binary field",
171 "sect113r2 - SECG recommended curve over a 113 bit binary field",
172 "sect131r1 - SECG recommended curve over a 131 bit binary field",
173 "sect131r2 - SECG recommended curve over a 131 bit binary field",
174 "sect163k1 - SECG/NIST recommended curve over a 163 bit binary field",
175 "sect163r1 - SECG recommended curve over a 163 bit binary field",
176 "sect163r2 - SECG/NIST recommended curve over a 163 bit binary field",
177 "sect193r1 - SECG recommended curve over a 193 bit binary field",
178 "sect193r2 - SECG recommended curve over a 193 bit binary field",
179 "sect233k1 - SECG/NIST recommended curve over a 233 bit binary field",
180 "sect233r1 - SECG/NIST recommended curve over a 233 bit binary field",
181 "sect239k1 - SECG recommended curve over a 239 bit binary field",
182 "sect283k1 - SECG/NIST recommended curve over a 283 bit binary field",
183 "sect283r1 - SECG/NIST recommended curve over a 283 bit binary field",
184 "sect409k1 - SECG/NIST recommended curve over a 409 bit binary field",
185 "sect409r1 - SECG/NIST recommended curve over a 409 bit binary field",
186 "sect571k1 - SECG/NIST recommended curve over a 571 bit binary field",
187 "sect571r1 - SECG/NIST recommended curve over a 571 bit binary field",
188 "wap-wsg-idm-ecid-wtls1 - 113 bit binary curve from the WTLS standard",
189 "wap-wsg-idm-ecid-wtls4 - 113 bit binary curve from the WTLS standard",
190 "wap-wsg-idm-ecid-wtls3 - 163 bit binary curve from the WTLS standard",
191 "wap-wsg-idm-ecid-wtls5 - 163 bit binary curve from the WTLS standard",
192 "wap-wsg-idm-ecid-wtls10 - 233 bit binary curve from the WTLS standard",
193 "wap-wsg-idm-ecid-wtls11 - 233 bit binary curve from the WTLS standard"
196 static int ecparam_print_var(BIO *,BIGNUM *,const char *,int,unsigned char *);
198 int MAIN(int, char **);
200 int MAIN(int argc, char **argv)
202 EC_GROUP *group = NULL;
203 point_conversion_form_t form = POINT_CONVERSION_UNCOMPRESSED;
205 int asn1_flag = OPENSSL_EC_NAMED_CURVE;
206 int new_asn1_flag = 0;
207 char *curve_name = NULL, *inrand = NULL;
208 int list_curves = 0, no_seed = 0, check = 0,
209 badops = 0, text = 0, i, need_rand = 0, genkey = 0;
210 char *infile = NULL, *outfile = NULL, *prog;
211 BIO *in = NULL, *out = NULL;
212 int informat, outformat, noout = 0, C = 0, ret = 1;
216 BIGNUM *ec_p = NULL, *ec_a = NULL, *ec_b = NULL,
217 *ec_gen = NULL, *ec_order = NULL, *ec_cofactor = NULL;
218 unsigned char *buffer = NULL;
223 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
224 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
226 if (!load_config(bio_err, NULL))
230 outformat=FORMAT_PEM;
237 if (strcmp(*argv,"-inform") == 0)
239 if (--argc < 1) goto bad;
240 informat=str2fmt(*(++argv));
242 else if (strcmp(*argv,"-outform") == 0)
244 if (--argc < 1) goto bad;
245 outformat=str2fmt(*(++argv));
247 else if (strcmp(*argv,"-in") == 0)
249 if (--argc < 1) goto bad;
252 else if (strcmp(*argv,"-out") == 0)
254 if (--argc < 1) goto bad;
257 else if (strcmp(*argv,"-text") == 0)
259 else if (strcmp(*argv,"-C") == 0)
261 else if (strcmp(*argv,"-check") == 0)
263 else if (strcmp (*argv, "-name") == 0)
267 curve_name = *(++argv);
269 else if (strcmp(*argv, "-list_curves") == 0)
271 else if (strcmp(*argv, "-conv_form") == 0)
277 if (strcmp(*argv, "compressed") == 0)
278 form = POINT_CONVERSION_COMPRESSED;
279 else if (strcmp(*argv, "uncompressed") == 0)
280 form = POINT_CONVERSION_UNCOMPRESSED;
281 else if (strcmp(*argv, "hybrid") == 0)
282 form = POINT_CONVERSION_HYBRID;
286 else if (strcmp(*argv, "-param_enc") == 0)
292 if (strcmp(*argv, "named_curve") == 0)
293 asn1_flag = OPENSSL_EC_NAMED_CURVE;
294 else if (strcmp(*argv, "explicit") == 0)
299 else if (strcmp(*argv, "-no_seed") == 0)
301 else if (strcmp(*argv, "-noout") == 0)
303 else if (strcmp(*argv,"-genkey") == 0)
308 else if (strcmp(*argv, "-rand") == 0)
310 if (--argc < 1) goto bad;
314 else if(strcmp(*argv, "-engine") == 0)
316 if (--argc < 1) goto bad;
321 BIO_printf(bio_err,"unknown option %s\n",*argv);
332 BIO_printf(bio_err, "%s [options] <infile >outfile\n",prog);
333 BIO_printf(bio_err, "where options are\n");
334 BIO_printf(bio_err, " -inform arg input format - "
335 "default PEM (DER or PEM)\n");
336 BIO_printf(bio_err, " -outform arg output format - "
338 BIO_printf(bio_err, " -in arg input file - "
340 BIO_printf(bio_err, " -out arg output file - "
342 BIO_printf(bio_err, " -noout do not print the "
344 BIO_printf(bio_err, " -text print the ec "
345 "parameters in text form\n");
346 BIO_printf(bio_err, " -check validate the ec "
348 BIO_printf(bio_err, " -C print a 'C' "
349 "function creating the parameters\n");
350 BIO_printf(bio_err, " -name arg use the "
351 "ec parameters with 'short name' name\n");
352 BIO_printf(bio_err, " -list_curves prints a list of "
353 "all currently available curve\n");
354 BIO_printf(bio_err, " 'short names'\n");
355 BIO_printf(bio_err, " -conv_form arg specifies the "
356 "point conversion form \n");
357 BIO_printf(bio_err, " possible values :"
359 BIO_printf(bio_err, " "
360 " uncompressed (default)\n");
361 BIO_printf(bio_err, " "
363 BIO_printf(bio_err, " -param_enc arg specifies the way"
364 " the ec parameters are encoded\n");
365 BIO_printf(bio_err, " in the asn1 der "
367 BIO_printf(bio_err, " possilbe values :"
368 " named_curve (default)\n");
369 BIO_printf(bio_err," "
371 BIO_printf(bio_err, " -no_seed if 'explicit'"
372 " parameters are choosen do not\n");
373 BIO_printf(bio_err, " use the seed\n");
374 BIO_printf(bio_err, " -genkey generate ecdsa"
376 BIO_printf(bio_err, " -rand file files to use for"
377 " random number input\n");
378 BIO_printf(bio_err, " -engine e use engine e, "
379 "possible a hardware device\n");
383 ERR_load_crypto_strings();
385 in=BIO_new(BIO_s_file());
386 out=BIO_new(BIO_s_file());
387 if ((in == NULL) || (out == NULL))
389 ERR_print_errors(bio_err);
394 BIO_set_fp(in,stdin,BIO_NOCLOSE);
397 if (BIO_read_filename(in,infile) <= 0)
405 BIO_set_fp(out,stdout,BIO_NOCLOSE);
406 #ifdef OPENSSL_SYS_VMS
408 BIO *tmpbio = BIO_new(BIO_f_linebuffer());
409 out = BIO_push(tmpbio, out);
415 if (BIO_write_filename(out,outfile) <= 0)
422 e = setup_engine(bio_err, engine, 0);
428 for (; counter < sizeof(curve_list)/sizeof(char *); counter++)
429 if (BIO_printf(bio_err, " %s\n", curve_list[counter])
436 if (curve_name != NULL)
438 int nid = OBJ_sn2nid(curve_name);
442 BIO_printf(bio_err, "unknown curve name (%s)\n",
447 group = EC_GROUP_new_by_nid(nid);
450 BIO_printf(bio_err, "unable to create curve (%s)\n",
454 EC_GROUP_set_asn1_flag(group, asn1_flag);
455 EC_GROUP_set_point_conversion_form(group, form);
457 else if (informat == FORMAT_ASN1)
459 group = d2i_ECPKParameters_bio(in, NULL);
461 else if (informat == FORMAT_PEM)
463 group = PEM_read_bio_ECPKParameters(in,NULL,NULL,NULL);
467 BIO_printf(bio_err, "bad input format specified\n");
474 "unable to load elliptic curve parameters\n");
475 ERR_print_errors(bio_err);
480 EC_GROUP_set_point_conversion_form(group, form);
483 EC_GROUP_set_asn1_flag(group, asn1_flag);
487 EC_GROUP_set_seed(group, NULL, 0);
492 if (!ECPKParameters_print(out, group, 0))
499 BIO_printf(bio_err, "no elliptic curve parameters\n");
500 BIO_printf(bio_err, "checking elliptic curve parameters: ");
501 if (!EC_GROUP_check(group, NULL))
503 BIO_printf(bio_err, "failed\n");
504 ERR_print_errors(bio_err);
507 BIO_printf(bio_err, "ok\n");
513 size_t buf_len = 0, tmp_len = 0;
514 const EC_POINT *point;
515 int is_prime, len = 0;
516 const EC_METHOD *meth = EC_GROUP_method_of(group);
518 if ((ec_p = BN_new()) == NULL || (ec_a = BN_new()) == NULL ||
519 (ec_b = BN_new()) == NULL || (ec_gen = BN_new()) == NULL ||
520 (ec_order = BN_new()) == NULL ||
521 (ec_cofactor = BN_new()) == NULL )
523 perror("OPENSSL_malloc");
527 is_prime = (EC_METHOD_get_field_type(meth) ==
528 NID_X9_62_prime_field);
532 if (!EC_GROUP_get_curve_GFp(group, ec_p, ec_a,
542 if ((point = EC_GROUP_get0_generator(group)) == NULL)
544 if (!EC_POINT_point2bn(group, point,
545 EC_GROUP_get_point_conversion_form(group), ec_gen,
548 if (!EC_GROUP_get_order(group, ec_order, NULL))
550 if (!EC_GROUP_get_cofactor(group, ec_cofactor, NULL))
553 if (!ec_p || !ec_a || !ec_b || !ec_gen ||
554 !ec_order || !ec_cofactor)
557 len = BN_num_bits(ec_order);
559 if ((tmp_len = (size_t)BN_num_bytes(ec_p)) > buf_len)
561 if ((tmp_len = (size_t)BN_num_bytes(ec_a)) > buf_len)
563 if ((tmp_len = (size_t)BN_num_bytes(ec_b)) > buf_len)
565 if ((tmp_len = (size_t)BN_num_bytes(ec_gen)) > buf_len)
567 if ((tmp_len = (size_t)BN_num_bytes(ec_order)) > buf_len)
569 if ((tmp_len = (size_t)BN_num_bytes(ec_cofactor)) > buf_len)
572 buffer = (unsigned char *)OPENSSL_malloc(buf_len);
576 perror("OPENSSL_malloc");
580 ecparam_print_var(out, ec_p, "ec_p", len, buffer);
581 ecparam_print_var(out, ec_a, "ec_a", len, buffer);
582 ecparam_print_var(out, ec_b, "ec_b", len, buffer);
583 ecparam_print_var(out, ec_gen, "ec_gen", len, buffer);
584 ecparam_print_var(out, ec_order, "ec_order", len, buffer);
585 ecparam_print_var(out, ec_cofactor, "ec_cofactor", len,
588 BIO_printf(out, "\n\n");
590 BIO_printf(out, "EC_GROUP *get_ec_group_%d(void)\n\t{\n", len);
591 BIO_printf(out, "\tint ok=0;\n");
592 BIO_printf(out, "\tEC_GROUP *group = NULL;\n");
593 BIO_printf(out, "\tEC_POINT *point = NULL;\n");
594 BIO_printf(out, "\tBIGNUM *tmp_1 = NULL, *tmp_2 = NULL, "
595 "*tmp_3 = NULL;\n\n");
596 BIO_printf(out, "\tif ((tmp_1 = BN_bin2bn(ec_p_%d, "
597 "sizeof(ec_p_%d), NULL)) == NULL)\n\t\t"
598 "goto err;\n", len, len);
599 BIO_printf(out, "\tif ((tmp_2 = BN_bin2bn(ec_a_%d, "
600 "sizeof(ec_a_%d), NULL)) == NULL)\n\t\t"
601 "goto err;\n", len, len);
602 BIO_printf(out, "\tif ((tmp_3 = BN_bin2bn(ec_b_%d, "
603 "sizeof(ec_b_%d), NULL)) == NULL)\n\t\t"
604 "goto err;\n", len, len);
607 BIO_printf(out, "\tif ((group = EC_GROUP_new_curve_"
608 "GFp(tmp_1, tmp_2, tmp_3, NULL)) == NULL)"
609 "\n\t\tgoto err;\n\n");
616 BIO_printf(out, "\t/* build generator */\n");
617 BIO_printf(out, "\tif ((tmp_1 = BN_bin2bn(ec_gen_%d, "
618 "sizeof(ec_gen_%d), tmp_1)) == NULL)"
619 "\n\t\tgoto err;\n", len, len);
620 BIO_printf(out, "\tpoint = EC_POINT_bn2point(group, tmp_1, "
622 BIO_printf(out, "\tif (point == NULL)\n\t\tgoto err;\n");
623 BIO_printf(out, "\tif ((tmp_2 = BN_bin2bn(ec_order_%d, "
624 "sizeof(ec_order_%d), tmp_2)) == NULL)"
625 "\n\t\tgoto err;\n", len, len);
626 BIO_printf(out, "\tif ((tmp_3 = BN_bin2bn(ec_cofactor_%d, "
627 "sizeof(ec_cofactor_%d), tmp_3)) == NULL)"
628 "\n\t\tgoto err;\n", len, len);
629 BIO_printf(out, "\tif (!EC_GROUP_set_generator(group, point,"
630 " tmp_2, tmp_3))\n\t\tgoto err;\n");
631 BIO_printf(out, "\n\tok=1;\n");
632 BIO_printf(out, "err:\n");
633 BIO_printf(out, "\tif (tmp_1)\n\t\tBN_free(tmp_1);\n");
634 BIO_printf(out, "\tif (tmp_2)\n\t\tBN_free(tmp_2);\n");
635 BIO_printf(out, "\tif (tmp_3)\n\t\tBN_free(tmp_3);\n");
636 BIO_printf(out, "\tif (point)\n\t\tEC_POINT_free(point);\n");
637 BIO_printf(out, "\tif (!ok)\n");
638 BIO_printf(out, "\t\t{\n");
639 BIO_printf(out, "\t\tEC_GROUP_free(group);\n");
640 BIO_printf(out, "\t\tgroup = NULL;\n");
641 BIO_printf(out, "\t\t}\n");
642 BIO_printf(out, "\treturn(group);\n\t}\n");
647 if (outformat == FORMAT_ASN1)
648 i = i2d_ECPKParameters_bio(out, group);
649 else if (outformat == FORMAT_PEM)
650 i = PEM_write_bio_ECPKParameters(out, group);
653 BIO_printf(bio_err,"bad output format specified for"
659 BIO_printf(bio_err, "unable to write elliptic "
660 "curve parameters\n");
661 ERR_print_errors(bio_err);
668 app_RAND_load_file(NULL, bio_err, (inrand != NULL));
670 BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
671 app_RAND_load_files(inrand));
676 ECDSA *ecdsa = ECDSA_new();
683 ecdsa->group = group;
685 if (!ECDSA_generate_key(ecdsa))
691 if (outformat == FORMAT_ASN1)
692 i = i2d_ECDSAPrivateKey_bio(out, ecdsa);
693 else if (outformat == FORMAT_PEM)
694 i = PEM_write_bio_ECDSAPrivateKey(out, ecdsa, NULL,
695 NULL, 0, NULL, NULL);
698 BIO_printf(bio_err, "bad output format specified "
709 app_RAND_write_file(NULL, bio_err);
724 BN_free(ec_cofactor);
726 OPENSSL_free(buffer);
732 EC_GROUP_free(group);
737 int ecparam_print_var(BIO *out, BIGNUM *in, const char *var,
738 int len, unsigned char *buffer)
740 BIO_printf(out, "static unsigned char %s_%d[] = {", var, len);
742 BIO_printf(out, "\n\t0x00");
747 l = BN_bn2bin(in, buffer);
748 for (i=0; i<l-1; i++)
751 BIO_printf(out, "\n\t");
752 BIO_printf(out, "0x%02X,", buffer[i]);
755 BIO_printf(out, "\n\t");
756 BIO_printf(out, "0x%02X", buffer[i]);
758 BIO_printf(out, "\n\t};\n\n");