88 #define PROG ecparam_main
115 static int ecparam_print_var(
BIO *,
BIGNUM *,
const char *,
int,
unsigned char *);
117 int MAIN(
int,
char **);
119 int MAIN(
int argc,
char **argv)
125 int new_asn1_flag = 0;
126 char *curve_name = NULL, *inrand = NULL;
127 int list_curves = 0, no_seed = 0, check = 0,
128 badops = 0,
text = 0, i, need_rand = 0, genkey = 0;
129 char *infile = NULL, *outfile = NULL, *prog;
131 int informat, outformat, noout = 0, C = 0, ret = 1;
134 BIGNUM *ec_p = NULL, *ec_a = NULL, *ec_b = NULL,
135 *ec_gen = NULL, *ec_order = NULL, *ec_cofactor = NULL;
136 unsigned char *buffer = NULL;
155 if (strcmp(*argv,
"-inform") == 0)
157 if (--argc < 1)
goto bad;
160 else if (strcmp(*argv,
"-outform") == 0)
162 if (--argc < 1)
goto bad;
165 else if (strcmp(*argv,
"-in") == 0)
167 if (--argc < 1)
goto bad;
170 else if (strcmp(*argv,
"-out") == 0)
172 if (--argc < 1)
goto bad;
175 else if (strcmp(*argv,
"-text") == 0)
177 else if (strcmp(*argv,
"-C") == 0)
179 else if (strcmp(*argv,
"-check") == 0)
181 else if (strcmp (*argv,
"-name") == 0)
185 curve_name = *(++argv);
187 else if (strcmp(*argv,
"-list_curves") == 0)
189 else if (strcmp(*argv,
"-conv_form") == 0)
195 if (strcmp(*argv,
"compressed") == 0)
197 else if (strcmp(*argv,
"uncompressed") == 0)
199 else if (strcmp(*argv,
"hybrid") == 0)
204 else if (strcmp(*argv,
"-param_enc") == 0)
210 if (strcmp(*argv,
"named_curve") == 0)
212 else if (strcmp(*argv,
"explicit") == 0)
217 else if (strcmp(*argv,
"-no_seed") == 0)
219 else if (strcmp(*argv,
"-noout") == 0)
221 else if (strcmp(*argv,
"-genkey") == 0)
226 else if (strcmp(*argv,
"-rand") == 0)
228 if (--argc < 1)
goto bad;
232 else if(strcmp(*argv,
"-engine") == 0)
234 if (--argc < 1)
goto bad;
253 "default PEM (DER or PEM)\n");
263 "parameters in text form\n");
267 "function creating the parameters\n");
269 "ec parameters with 'short name' name\n");
271 "all currently available curve 'short names'\n");
273 "point conversion form \n");
277 " uncompressed (default)\n");
281 " the ec parameters are encoded\n");
285 " named_curve (default)\n");
289 " parameters are choosen do not"
294 " random number input\n");
296 "possibly a hardware device\n");
304 if ((in == NULL) || (out == NULL))
323 #ifdef OPENSSL_SYS_VMS
339 #ifndef OPENSSL_NO_ENGINE
363 for (n = 0; n < crv_len; n++)
370 comment =
"CURVE DESCRIPTION NOT AVAILABLE";
383 if (curve_name != NULL)
391 if (!strcmp(curve_name,
"secp192r1"))
394 "instead of secp192r1\n");
397 else if (!strcmp(curve_name,
"secp256r1"))
400 "instead of secp256r1\n");
429 group = PEM_read_bio_ECPKParameters(in,NULL,NULL,NULL);
440 "unable to load elliptic curve parameters\n");
479 size_t buf_len = 0, tmp_len = 0;
481 int is_prime,
len = 0;
484 if ((ec_p =
BN_new()) == NULL || (ec_a =
BN_new()) == NULL ||
485 (ec_b =
BN_new()) == NULL || (ec_gen =
BN_new()) == NULL ||
486 (ec_order =
BN_new()) == NULL ||
487 (ec_cofactor =
BN_new()) == NULL )
489 perror(
"OPENSSL_malloc");
519 if (!ec_p || !ec_a || !ec_b || !ec_gen ||
520 !ec_order || !ec_cofactor)
533 if ((tmp_len = (
size_t)
BN_num_bytes(ec_order)) > buf_len)
535 if ((tmp_len = (
size_t)
BN_num_bytes(ec_cofactor)) > buf_len)
542 perror(
"OPENSSL_malloc");
546 ecparam_print_var(out, ec_p,
"ec_p", len, buffer);
547 ecparam_print_var(out, ec_a,
"ec_a", len, buffer);
548 ecparam_print_var(out, ec_b,
"ec_b", len, buffer);
549 ecparam_print_var(out, ec_gen,
"ec_gen", len, buffer);
550 ecparam_print_var(out, ec_order,
"ec_order", len, buffer);
551 ecparam_print_var(out, ec_cofactor,
"ec_cofactor", len,
556 BIO_printf(out,
"EC_GROUP *get_ec_group_%d(void)\n\t{\n", len);
558 BIO_printf(out,
"\tEC_GROUP *group = NULL;\n");
559 BIO_printf(out,
"\tEC_POINT *point = NULL;\n");
560 BIO_printf(out,
"\tBIGNUM *tmp_1 = NULL, *tmp_2 = NULL, "
561 "*tmp_3 = NULL;\n\n");
562 BIO_printf(out,
"\tif ((tmp_1 = BN_bin2bn(ec_p_%d, "
563 "sizeof(ec_p_%d), NULL)) == NULL)\n\t\t"
564 "goto err;\n", len, len);
565 BIO_printf(out,
"\tif ((tmp_2 = BN_bin2bn(ec_a_%d, "
566 "sizeof(ec_a_%d), NULL)) == NULL)\n\t\t"
567 "goto err;\n", len, len);
568 BIO_printf(out,
"\tif ((tmp_3 = BN_bin2bn(ec_b_%d, "
569 "sizeof(ec_b_%d), NULL)) == NULL)\n\t\t"
570 "goto err;\n", len, len);
573 BIO_printf(out,
"\tif ((group = EC_GROUP_new_curve_"
574 "GFp(tmp_1, tmp_2, tmp_3, NULL)) == NULL)"
575 "\n\t\tgoto err;\n\n");
583 BIO_printf(out,
"\tif ((tmp_1 = BN_bin2bn(ec_gen_%d, "
584 "sizeof(ec_gen_%d), tmp_1)) == NULL)"
585 "\n\t\tgoto err;\n", len, len);
586 BIO_printf(out,
"\tpoint = EC_POINT_bn2point(group, tmp_1, "
588 BIO_printf(out,
"\tif (point == NULL)\n\t\tgoto err;\n");
589 BIO_printf(out,
"\tif ((tmp_2 = BN_bin2bn(ec_order_%d, "
590 "sizeof(ec_order_%d), tmp_2)) == NULL)"
591 "\n\t\tgoto err;\n", len, len);
592 BIO_printf(out,
"\tif ((tmp_3 = BN_bin2bn(ec_cofactor_%d, "
593 "sizeof(ec_cofactor_%d), tmp_3)) == NULL)"
594 "\n\t\tgoto err;\n", len, len);
595 BIO_printf(out,
"\tif (!EC_GROUP_set_generator(group, point,"
596 " tmp_2, tmp_3))\n\t\tgoto err;\n");
599 BIO_printf(out,
"\tif (tmp_1)\n\t\tBN_free(tmp_1);\n");
600 BIO_printf(out,
"\tif (tmp_2)\n\t\tBN_free(tmp_2);\n");
601 BIO_printf(out,
"\tif (tmp_3)\n\t\tBN_free(tmp_3);\n");
602 BIO_printf(out,
"\tif (point)\n\t\tEC_POINT_free(point);\n");
605 BIO_printf(out,
"\t\tEC_GROUP_free(group);\n");
616 i = PEM_write_bio_ECPKParameters(out, group);
626 "curve parameters\n");
660 i = PEM_write_bio_ECPrivateKey(out, eckey, NULL,
661 NULL, 0, NULL, NULL);
701 static int ecparam_print_var(
BIO *out,
BIGNUM *in,
const char *var,
702 int len,
unsigned char *buffer)
704 BIO_printf(out,
"static unsigned char %s_%d[] = {", var, len);
712 for (i=0; i<l-1; i++)
728 static void *dummy=&dummy;