Commit 7eb18f12 authored by Bodo Möller's avatar Bodo Möller
Browse files

Simplify handling of named curves: get rid of EC_GROUP_new_by_name(),

EC_GROUP_new_by_nid() should be enough.  This avoids a lot of
redundancy.

Submitted by: Nils Larsch
parent 265e892f
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -233,9 +233,8 @@ TODO: bug: pad x with leading zeros if necessary

  *) Include some named elliptic curves, and add OIDs from X9.62,
     SECG, and WAP/WTLS.  The curves can be obtained from the new
     functions
     function
          EC_GROUP_new_by_nid()
          EC_GROUP_new_by_name()
     Also add a 'curve_name' member to EC_GROUP objects, which can be
     accessed via
         EC_GROUP_set_nid()
+24 −79
Original line number Diff line number Diff line
/* apps/ecparam.c */
/*
 * Originally written by Nils Larsch for the OpenSSL project.
 * Written by Nils Larsch for the OpenSSL project.
 */
/* ====================================================================
 * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
@@ -92,9 +92,6 @@
#include <openssl/err.h>
#include <openssl/bn.h>
#include <openssl/ec.h>
#ifndef OPENSSL_NO_ECDSA
#include <openssl/ecdsa.h>
#endif
#include <openssl/x509.h>
#include <openssl/pem.h>

@@ -123,80 +120,11 @@
 *                                            explicit
 * -no_seed               - if 'explicit' parameters are choosen do not
 *                          use the seed
 * -genkey                - generates a ecdsa private key
 * -genkey                - generates a ec private key
 * -rand file
 * -engine e              - use engine e, possible a hardware device
 */

static const char *curve_list[67] = {
	"prime192v1   - 192 bit prime curve from the X9.62 draft",
	"prime192v2   - 192 bit prime curve from the X9.62 draft",
	"prime192v3   - 192 bit prime curve from the X9.62 draft",
	"prime239v1   - 239 bit prime curve from the X9.62 draft",
	"prime239v2   - 239 bit prime curve from the X9.62 draft",
	"prime239v3   - 239 bit prime curve from the X9.62 draft", 
	"prime256v1   - 256 bit prime curve from the X9.62 draft", 
	"secp112r1    - SECG recommended curve over a 112 bit prime field", 
	"secp112r2    - SECG recommended curve over a 112 bit prime field", 
	"secp128r1    - SECG recommended curve over a 128 bit prime field",
	"secp128r2    - SECG recommended curve over a 128 bit prime field", 
	"secp160k1    - SECG recommended curve over a 160 bit prime field", 
	"secp160r1    - SECG recommended curve over a 160 bit prime field", 
	"secp160r2    - SECG recommended curve over a 160 bit prime field", 
	"secp192k1    - SECG recommended curve over a 192 bit prime field",
	"prime192v1   - SECG recommended curve over a 192 bit prime field (aka secp192r1)",
	"secp224k1    - SECG recommended curve over a 224 bit prime field", 
	"secp224r1    - SECG/NIST recommended curve over a 224 bit prime field", 
	"secp256k1    - SECG recommended curve over a 256 bit prime field",
	"prime256v1   - SECG recommended curve over a 256 bit prime field (aka secp256r1)",
	"secp384r1    - SECG/NIST recommended curve over a 384 bit prime field", 
	"secp521r1    - SECG/NIST recommended curve over a 521 bit prime field",
	"wap-wsg-idm-ecid-wtls6  - 112 bit prime curve from the WTLS standard",
	"wap-wsg-idm-ecid-wtls8  - 112 bit prime curve from the WTLS standard",
	"wap-wsg-idm-ecid-wtls7  - 160 bit prime curve from the WTLS standard",
	"wap-wsg-idm-ecid-wtls9  - 160 bit prime curve from the WTLS standard",
	"wap-wsg-idm-ecid-wtls12 - 224 bit prime curve from the WTLS standard",
	"c2pnb163v1   - 163 bit binary curve from the X9.62 draft",
	"c2pnb163v2   - 163 bit binary curve from the X9.62 draft",
	"c2pnb163v3   - 163 bit binary curve from the X9.62 draft",
	"c2pnb176v1   - 176 bit binary curve from the X9.62 draft",
	"c2tnb191v1   - 191 bit binary curve from the X9.62 draft",
	"c2tnb191v2   - 191 bit binary curve from the X9.62 draft",
	"c2tnb191v3   - 191 bit binary curve from the X9.62 draft",
	"c2pnb208w1   - 208 bit binary curve from the X9.62 draft",
	"c2tnb239v1   - 239 bit binary curve from the X9.62 draft",
	"c2tnb239v2   - 239 bit binary curve from the X9.62 draft",
	"c2tnb239v3   - 239 bit binary curve from the X9.62 draft",
	"c2pnb272w1   - 272 bit binary curve from the X9.62 draft",
	"c2pnb304w1   - 304 bit binary curve from the X9.62 draft",
	"c2tnb359v1   - 359 bit binary curve from the X9.62 draft",
	"c2pnb368w1   - 368 bit binary curve from the X9.62 draft",
	"c2tnb431r1   - 431 bit binary curve from the X9.62 draft",
	"sect113r1    - SECG recommended curve over a 113 bit binary field",
	"sect113r2    - SECG recommended curve over a 113 bit binary field",
	"sect131r1    - SECG recommended curve over a 131 bit binary field",
	"sect131r2    - SECG recommended curve over a 131 bit binary field",
	"sect163k1    - SECG/NIST recommended curve over a 163 bit binary field",
	"sect163r1    - SECG recommended curve over a 163 bit binary field",
	"sect163r2    - SECG/NIST recommended curve over a 163 bit binary field",
	"sect193r1    - SECG recommended curve over a 193 bit binary field",
	"sect193r2    - SECG recommended curve over a 193 bit binary field",
	"sect233k1    - SECG/NIST recommended curve over a 233 bit binary field",
	"sect233r1    - SECG/NIST recommended curve over a 233 bit binary field",
	"sect239k1    - SECG recommended curve over a 239 bit binary field",
	"sect283k1    - SECG/NIST recommended curve over a 283 bit binary field",
	"sect283r1    - SECG/NIST recommended curve over a 283 bit binary field",
	"sect409k1    - SECG/NIST recommended curve over a 409 bit binary field",
	"sect409r1    - SECG/NIST recommended curve over a 409 bit binary field",
	"sect571k1    - SECG/NIST recommended curve over a 571 bit binary field",
	"sect571r1    - SECG/NIST recommended curve over a 571 bit binary field",
	"wap-wsg-idm-ecid-wtls1  - 113 bit binary curve from the WTLS standard",
	"wap-wsg-idm-ecid-wtls4  - 113 bit binary curve from the WTLS standard",
	"wap-wsg-idm-ecid-wtls3  - 163 bit binary curve from the WTLS standard",
	"wap-wsg-idm-ecid-wtls5  - 163 bit binary curve from the WTLS standard",
	"wap-wsg-idm-ecid-wtls10 - 233 bit binary curve from the WTLS standard",
	"wap-wsg-idm-ecid-wtls11 - 233 bit binary curve from the WTLS standard"
};

static int ecparam_print_var(BIO *,BIGNUM *,const char *,int,unsigned char *);

@@ -376,7 +304,7 @@ bad:
		BIO_printf(bio_err, " -no_seed                if 'explicit'"
				" parameters are choosen do not\n");
		BIO_printf(bio_err, "                         use the seed\n");
		BIO_printf(bio_err, " -genkey                 generate ecdsa"
		BIO_printf(bio_err, " -genkey                 generate ec"
				" key\n");
		BIO_printf(bio_err, " -rand file              files to use for"
				" random number input\n");
@@ -430,10 +358,27 @@ bad:
		{
		int counter=0;

		for (; counter < sizeof(curve_list)/sizeof(char *); counter++)
			if (BIO_printf(bio_err, " %s\n", curve_list[counter]) 
				<= 0) 
				goto end;
		for (;;)
			{
			const char *comment;
			const char *sname;
			int len, nid = ec_group_index2nid(counter++);
			if (!nid)
				break;
			comment = EC_GROUP_get0_comment(nid);
			sname   = OBJ_nid2sn(nid);
			if (comment == NULL)
				comment = "";
			if (sname == NULL)
				sname == "";

			len = BIO_printf(out, "  %-10s: ", sname);
			if (len + strlen(comment) > 80)
				BIO_printf(out, "\n%80s\n", comment);
			else
				BIO_printf(out, "%s\n", comment);
			} 

		ret = 0;
		goto end;
		}
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@
 */
/* ====================================================================
 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
 * ECDH support in OpenSSL originally developed by 
 * ECC cipher suite support in OpenSSL originally developed by 
 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
 */

+15 −15
Original line number Diff line number Diff line
@@ -559,22 +559,22 @@ int MAIN(int argc, char **argv)
	static unsigned int test_curves[EC_NUM] = 
	{	
	/* Prime Curves */
	EC_GROUP_SECG_PRIME_160R1,
	EC_GROUP_NIST_PRIME_224,
	EC_GROUP_NIST_PRIME_256,
	EC_GROUP_NIST_PRIME_384,
	EC_GROUP_NIST_PRIME_521,
	NID_secp160r1,
	NID_secp224r1,
	NID_X9_62_prime256v1,
	NID_secp384r1,
	NID_secp521r1,
	/* Binary Curves */
	EC_GROUP_NIST_CHAR2_K163,
	EC_GROUP_NIST_CHAR2_K233,
	EC_GROUP_NIST_CHAR2_K283,
	EC_GROUP_NIST_CHAR2_K409,
	EC_GROUP_NIST_CHAR2_K571,
	EC_GROUP_NIST_CHAR2_B163,
	EC_GROUP_NIST_CHAR2_B233,
	EC_GROUP_NIST_CHAR2_B283,
	EC_GROUP_NIST_CHAR2_B409,
	EC_GROUP_NIST_CHAR2_B571
	NID_sect163k1,
	NID_sect233k1,
	NID_sect283k1,
	NID_sect409k1,
	NID_sect571k1,
	NID_sect163r2,
	NID_sect233r1,
	NID_sect283r1,
	NID_sect409r1,
	NID_sect571r1
	}; 
	static char * test_curves_names[EC_NUM] = 
	{
+5 −6
Original line number Diff line number Diff line
@@ -118,12 +118,11 @@ ec_check.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ec_check.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec_check.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec_check.o: ../../include/openssl/symhacks.h ec_check.c ec_lcl.h
ec_curve.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
ec_curve.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
ec_curve.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
ec_curve.o: ../../include/openssl/ec.h ../../include/openssl/err.h
ec_curve.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
ec_curve.o: ../../include/openssl/opensslconf.h
ec_curve.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ec_curve.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ec_curve.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ec_curve.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ec_curve.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ec_curve.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec_curve.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec_curve.o: ../../include/openssl/symhacks.h ec_curve.c ec_lcl.h
Loading