diff options
author | Bodo Möller <bodo@openssl.org> | 2002-02-13 17:22:59 +0000 |
---|---|---|
committer | Bodo Möller <bodo@openssl.org> | 2002-02-13 17:22:59 +0000 |
commit | 945e15a2536892d1e19345c58462512ac30f4d36 (patch) | |
tree | c53deb12dad5b328b568c21ed4bc45035efcf76a | |
parent | 1fe198b6f9581ebfda2e26073585d756cf193e8e (diff) | |
download | openssl-945e15a2536892d1e19345c58462512ac30f4d36.tar.gz |
add support for named curves
Submitted by: Nils Larsch <nla@trustcenter.de>
-rw-r--r-- | crypto/ec/Makefile.ssl | 13 | ||||
-rw-r--r-- | crypto/ec/ec.h | 41 | ||||
-rw-r--r-- | crypto/ec/ec_curve.c | 274 | ||||
-rw-r--r-- | crypto/ec/ec_err.c | 7 | ||||
-rw-r--r-- | crypto/ec/ec_lcl.h | 3 | ||||
-rw-r--r-- | crypto/ec/ec_lib.c | 28 |
6 files changed, 358 insertions, 8 deletions
diff --git a/crypto/ec/Makefile.ssl b/crypto/ec/Makefile.ssl index 7a21b7195f..002841eff2 100644 --- a/crypto/ec/Makefile.ssl +++ b/crypto/ec/Makefile.ssl @@ -24,10 +24,10 @@ APPS= LIB=$(TOP)/libcrypto.a LIBSRC= ec_lib.c ecp_smpl.c ecp_mont.c ecp_recp.c ecp_nist.c ec_cvt.c ec_mult.c \ - ec_err.c + ec_err.c ec_curve.c LIBOBJ= ec_lib.o ecp_smpl.o ecp_mont.o ecp_recp.o ecp_nist.o ec_cvt.o ec_mult.o \ - ec_err.o + ec_err.o ec_curve.o SRC= $(LIBSRC) @@ -82,6 +82,15 @@ clean: # DO NOT DELETE THIS LINE -- make depend depends on it. +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/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 ec_cvt.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h ec_cvt.o: ../../include/openssl/ec.h ../../include/openssl/opensslconf.h ec_cvt.o: ../../include/openssl/symhacks.h ec_cvt.c ec_lcl.h diff --git a/crypto/ec/ec.h b/crypto/ec/ec.h index a52d4edf14..448bcd428f 100644 --- a/crypto/ec/ec.h +++ b/crypto/ec/ec.h @@ -107,8 +107,11 @@ void EC_GROUP_free(EC_GROUP *); void EC_GROUP_clear_free(EC_GROUP *); int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *); +void EC_GROUP_set_nid(EC_GROUP *, int); +int EC_GROUP_get_nid(const EC_GROUP *); + const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *); - + /* We don't have types for field specifications and field elements in general. * Otherwise we could declare @@ -117,15 +120,36 @@ const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *); int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); -/* EC_GROUP_new_GFp() calls EC_GROUP_new() and EC_GROUP_set_GFp() - * after choosing an appropriate EC_METHOD */ -EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); - int EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor); EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *); int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *); int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *); + +/* EC_GROUP_new_GFp() calls EC_GROUP_new() and EC_GROUP_set_GFp() + * after choosing an appropriate EC_METHOD */ +EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); + +EC_GROUP *EC_GROUP_get_group_by_name(int name); +/* Valid arguments to EC_GROUP_get_group_by_name(): */ +#define EC_GROUP_NO_CURVE 0 +#define EC_GROUP_NIST_PRIME_192 1 +#define EC_GROUP_NIST_PRIME_224 2 +#define EC_GROUP_NIST_PRIME_256 3 +#define EC_GROUP_NIST_PRIME_384 4 +#define EC_GROUP_NIST_PRIME_521 5 +#define EC_GROUP_X9_62_PRIME_192V1 NID_X9_62_prime192v1 +#define EC_GROUP_X9_62_PRIME_192V2 NID_X9_62_prime192v2 +#define EC_GROUP_X9_62_PRIME_192V3 NID_X9_62_prime192v3 +#define EC_GROUP_X9_62_PRIME_239V1 NID_X9_62_prime239v1 +#define EC_GROUP_X9_62_PRIME_239V2 NID_X9_62_prime239v2 +#define EC_GROUP_X9_62_PRIME_239V3 NID_X9_62_prime239v3 +#define EC_GROUP_X9_62_PRIME_256V1 NID_X9_62_prime256v1 + +EC_GROUP *EC_GROUP_nid2group(const int nid); +int EC_GROUP_group2nid(const EC_GROUP *group); + + EC_POINT *EC_POINT_new(const EC_GROUP *); void EC_POINT_free(EC_POINT *); void EC_POINT_clear_free(EC_POINT *); @@ -196,12 +220,16 @@ void ERR_load_EC_strings(void); #define EC_F_EC_GROUP_GET_COFACTOR 140 #define EC_F_EC_GROUP_GET_CURVE_GFP 130 #define EC_F_EC_GROUP_GET_EXTRA_DATA 107 +#define EC_F_EC_GROUP_GET_GROUP_BY_NAME 144 #define EC_F_EC_GROUP_GET_ORDER 141 +#define EC_F_EC_GROUP_GROUP2NID 145 #define EC_F_EC_GROUP_NEW 108 +#define EC_F_EC_GROUP_NID2GROUP 146 #define EC_F_EC_GROUP_PRECOMPUTE_MULT 142 #define EC_F_EC_GROUP_SET_CURVE_GFP 109 #define EC_F_EC_GROUP_SET_EXTRA_DATA 110 #define EC_F_EC_GROUP_SET_GENERATOR 111 +#define EC_F_EC_GROUP_SET_PRIME_GROUP 147 #define EC_F_EC_POINTS_MAKE_AFFINE 136 #define EC_F_EC_POINTS_MUL 138 #define EC_F_EC_POINT_ADD 112 @@ -231,12 +259,15 @@ void ERR_load_EC_strings(void); #define EC_R_INVALID_ENCODING 102 #define EC_R_INVALID_FIELD 103 #define EC_R_INVALID_FORM 104 +#define EC_R_MISSING_PARAMETERS 115 #define EC_R_NOT_INITIALIZED 111 #define EC_R_NO_SUCH_EXTRA_DATA 105 #define EC_R_POINT_AT_INFINITY 106 #define EC_R_POINT_IS_NOT_ON_CURVE 107 #define EC_R_SLOT_FULL 108 #define EC_R_UNDEFINED_GENERATOR 113 +#define EC_R_UNKNOWN_GROUP 116 +#define EC_R_UNKNOWN_NID 117 #define EC_R_UNKNOWN_ORDER 114 #ifdef __cplusplus diff --git a/crypto/ec/ec_curve.c b/crypto/ec/ec_curve.c new file mode 100644 index 0000000000..4c3ac8430e --- /dev/null +++ b/crypto/ec/ec_curve.c @@ -0,0 +1,274 @@ +/* crypto/ec/ec_curve.c */ +/* ==================================================================== + * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include "ec_lcl.h" +#include <openssl/err.h> +#include <openssl/obj_mac.h> +#include <openssl/asn1.h> +#include <openssl/asn1t.h> + +EC_GROUP *EC_GROUP_nid2group(const int nid) + { + switch(nid) + { + case NID_X9_62_prime192v1: + return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_192V1); + case NID_X9_62_prime192v2: + return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_192V2); + case NID_X9_62_prime192v3: + return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_192V3); + case NID_X9_62_prime239v1: + return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_239V1); + case NID_X9_62_prime239v2: + return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_239V2); + case NID_X9_62_prime239v3: + return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_239V3); + case NID_X9_62_prime256v1: + return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_256V1); + } + ECerr(EC_F_EC_GROUP_NID2GROUP, EC_R_UNKNOWN_NID); + return NULL; + } + +int EC_GROUP_group2nid(const EC_GROUP *group) + { + return EC_GROUP_get_nid(group); + +#if 0 +/* TODO: a real compare function for EC_GROUPs */ +#define EC_GROUP_cmp(a,b) ((a) != (b)) + + if (group == NULL) + { + ECerr(EC_F_EC_GROUP_GROUP2NID, EC_R_MISSING_PARAMETERS); + return 0; + } + if (!EC_GROUP_cmp(group, EC_GROUP_GET_X9_62_192V1_GROUP())) + return NID_X9_62_prime192v1; + else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_192v2_group())) + return NID_X9_62_prime192v2; + else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_192v3_group())) + return NID_X9_62_prime192v3; + else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_239v1_group())) + return NID_X9_62_prime239v1; + else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_239v2_group())) + return NID_X9_62_prime239v2; + else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_239v3_group())) + return NID_X9_62_prime239v3; + else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_256v1_group())) + return NID_X9_62_prime256v1; + ECerr(EC_F_EC_GROUP_GROUP2NID, EC_R_UNKNOWN_GROUP); + return 0; +#endif + } + +static EC_GROUP *ec_group_set_prime_group(const char *prime_in, + const char *a_in, const char *b_in, + const char *x_in, const int y_bit, const char *order_in) + { + EC_GROUP *group=NULL; + EC_POINT *P=NULL; + BN_CTX *ctx=NULL; + BIGNUM *prime=NULL,*a=NULL,*b=NULL,*x=NULL,*order=NULL; + int ok=0; + + if ((ctx = BN_CTX_new()) == NULL) goto bn_err; + if ((prime = BN_new()) == NULL || (a = BN_new()) == NULL || (b = BN_new()) == NULL || + (x = BN_new()) == NULL || (order = BN_new()) == NULL) goto bn_err; + + if (!BN_hex2bn(&prime, prime_in)) goto bn_err; + if (!BN_hex2bn(&a, a_in)) goto bn_err; + if (!BN_hex2bn(&b, b_in)) goto bn_err; + + if ((group = EC_GROUP_new_curve_GFp(prime, a, b, ctx)) == NULL) goto err; + if ((P = EC_POINT_new(group)) == NULL) goto err; + + if (!BN_hex2bn(&x, x_in)) goto bn_err; + if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, y_bit, ctx)) goto err; + if (!BN_hex2bn(&order, order_in)) goto bn_err; + if (!EC_GROUP_set_generator(group, P, order, BN_value_one())) goto err; + ok=1; +bn_err: + if (!ok) + ECerr(EC_F_EC_GROUP_SET_PRIME_GROUP, ERR_R_BN_LIB); +err: + if (!ok) + { + EC_GROUP_free(group); + group = NULL; + } + if (P) EC_POINT_free(P); + if (ctx) BN_CTX_free(ctx); + if (prime) BN_free(prime); + if (a) BN_free(a); + if (b) BN_free(b); + if (order) BN_free(order); + if (x) BN_free(x); + return(group); +} + +EC_GROUP *EC_GROUP_get_group_by_name(int name) + { + EC_GROUP *ret = NULL; + switch (name) + { + case EC_GROUP_NO_CURVE: + return NULL; + + case EC_GROUP_NIST_PRIME_224: + return ec_group_set_prime_group( + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE", + "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4", + "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21",0, + "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D"); + + case EC_GROUP_NIST_PRIME_384: + return ec_group_set_prime_group( + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC", + "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF", + "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7",1, + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973"); + + case EC_GROUP_NIST_PRIME_521: + return ec_group_set_prime_group( + "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", + "051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B" + "315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", + "C6858E06B70404E9CD9E3ECB662395B4429C648139053F" + "B521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66",0, + "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + "FFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409"); + + case EC_GROUP_NIST_PRIME_192: + case EC_GROUP_X9_62_PRIME_192V1: + ret = ec_group_set_prime_group( + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", + "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1", + "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012",1, + "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831"); + EC_GROUP_set_nid(ret, NID_X9_62_prime192v1); + return ret; + + case EC_GROUP_X9_62_PRIME_192V2: + ret = ec_group_set_prime_group( + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", + "CC22D6DFB95C6B25E49C0D6364A4E5980C393AA21668D953", + "EEA2BAE7E1497842F2DE7769CFE9C989C072AD696F48034A",1, + "FFFFFFFFFFFFFFFFFFFFFFFE5FB1A724DC80418648D8DD31"); + EC_GROUP_set_nid(ret, NID_X9_62_prime192v2); + return ret; + + case EC_GROUP_X9_62_PRIME_192V3: + ret = ec_group_set_prime_group( + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", + "22123DC2395A05CAA7423DAECCC94760A7D462256BD56916", + "7D29778100C65A1DA1783716588DCE2B8B4AEE8E228F1896",0, + "FFFFFFFFFFFFFFFFFFFFFFFF7A62D031C83F4294F640EC13"); + EC_GROUP_set_nid(ret, NID_X9_62_prime192v3); + return ret; + + case EC_GROUP_X9_62_PRIME_239V1: + ret = ec_group_set_prime_group( + "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF", + "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC", + "6B016C3BDCF18941D0D654921475CA71A9DB2FB27D1D37796185C2942C0A", + "0FFA963CDCA8816CCC33B8642BEDF905C3D358573D3F27FBBD3B3CB9AAAF",0, + "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF9E5E9A9F5D9071FBD1522688909D0B"); + EC_GROUP_set_nid(ret, NID_X9_62_prime239v1); + return ret; + + case EC_GROUP_X9_62_PRIME_239V2: + ret = ec_group_set_prime_group( + "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF", + "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC", + "617FAB6832576CBBFED50D99F0249C3FEE58B94BA0038C7AE84C8C832F2C", + "38AF09D98727705120C921BB5E9E26296A3CDCF2F35757A0EAFD87B830E7",0, + "7FFFFFFFFFFFFFFFFFFFFFFF800000CFA7E8594377D414C03821BC582063"); + EC_GROUP_set_nid(ret, NID_X9_62_prime239v2); + return ret; + + case EC_GROUP_X9_62_PRIME_239V3: + ret = ec_group_set_prime_group( + "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF", + "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC", + "255705FA2A306654B1F4CB03D6A750A30C250102D4988717D9BA15AB6D3E", + "6768AE8E18BB92CFCF005C949AA2C6D94853D0E660BBF854B1C9505FE95A",1, + "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF975DEB41B3A6057C3C432146526551"); + EC_GROUP_set_nid(ret, NID_X9_62_prime239v3); + return ret; + + case EC_GROUP_NIST_PRIME_256: + case EC_GROUP_X9_62_PRIME_256V1: + ret = ec_group_set_prime_group( + "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", + "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", + "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B", + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296",1, + "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551"); + EC_GROUP_set_nid(ret, NID_X9_62_prime256v1); + return ret; + } + + ECerr(EC_F_EC_GROUP_GET_GROUP_BY_NAME, EC_R_UNKNOWN_GROUP); + return NULL; +} diff --git a/crypto/ec/ec_err.c b/crypto/ec/ec_err.c index 394cdc021f..1b023d7099 100644 --- a/crypto/ec/ec_err.c +++ b/crypto/ec/ec_err.c @@ -85,12 +85,16 @@ static ERR_STRING_DATA EC_str_functs[]= {ERR_PACK(0,EC_F_EC_GROUP_GET_COFACTOR,0), "EC_GROUP_get_cofactor"}, {ERR_PACK(0,EC_F_EC_GROUP_GET_CURVE_GFP,0), "EC_GROUP_get_curve_GFp"}, {ERR_PACK(0,EC_F_EC_GROUP_GET_EXTRA_DATA,0), "EC_GROUP_get_extra_data"}, +{ERR_PACK(0,EC_F_EC_GROUP_GET_GROUP_BY_NAME,0), "EC_GROUP_get_group_by_name"}, {ERR_PACK(0,EC_F_EC_GROUP_GET_ORDER,0), "EC_GROUP_get_order"}, +{ERR_PACK(0,EC_F_EC_GROUP_GROUP2NID,0), "EC_GROUP_group2nid"}, {ERR_PACK(0,EC_F_EC_GROUP_NEW,0), "EC_GROUP_new"}, +{ERR_PACK(0,EC_F_EC_GROUP_NID2GROUP,0), "EC_GROUP_nid2group"}, {ERR_PACK(0,EC_F_EC_GROUP_PRECOMPUTE_MULT,0), "EC_GROUP_precompute_mult"}, {ERR_PACK(0,EC_F_EC_GROUP_SET_CURVE_GFP,0), "EC_GROUP_set_curve_GFp"}, {ERR_PACK(0,EC_F_EC_GROUP_SET_EXTRA_DATA,0), "EC_GROUP_set_extra_data"}, {ERR_PACK(0,EC_F_EC_GROUP_SET_GENERATOR,0), "EC_GROUP_set_generator"}, +{ERR_PACK(0,EC_F_EC_GROUP_SET_PRIME_GROUP,0), "EC_GROUP_SET_PRIME_GROUP"}, {ERR_PACK(0,EC_F_EC_POINTS_MAKE_AFFINE,0), "EC_POINTs_make_affine"}, {ERR_PACK(0,EC_F_EC_POINTS_MUL,0), "EC_POINTs_mul"}, {ERR_PACK(0,EC_F_EC_POINT_ADD,0), "EC_POINT_add"}, @@ -123,12 +127,15 @@ static ERR_STRING_DATA EC_str_reasons[]= {EC_R_INVALID_ENCODING ,"invalid encoding"}, {EC_R_INVALID_FIELD ,"invalid field"}, {EC_R_INVALID_FORM ,"invalid form"}, +{EC_R_MISSING_PARAMETERS ,"missing parameters"}, {EC_R_NOT_INITIALIZED ,"not initialized"}, {EC_R_NO_SUCH_EXTRA_DATA ,"no such extra data"}, {EC_R_POINT_AT_INFINITY ,"point at infinity"}, {EC_R_POINT_IS_NOT_ON_CURVE ,"point is not on curve"}, {EC_R_SLOT_FULL ,"slot full"}, {EC_R_UNDEFINED_GENERATOR ,"undefined generator"}, +{EC_R_UNKNOWN_GROUP ,"unknown group"}, +{EC_R_UNKNOWN_NID ,"unknown nid"}, {EC_R_UNKNOWN_ORDER ,"unknown order"}, {0,NULL} }; diff --git a/crypto/ec/ec_lcl.h b/crypto/ec/ec_lcl.h index cc4cf27755..9603e74e7d 100644 --- a/crypto/ec/ec_lcl.h +++ b/crypto/ec/ec_lcl.h @@ -166,6 +166,9 @@ struct ec_group_st { EC_POINT *generator; /* optional */ BIGNUM order, cofactor; + int references; + int nid; + void *field_data1; /* method-specific (e.g., Montgomery structure) */ void *field_data2; /* method-specific */ } /* EC_GROUP */; diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c index e0d78d67fb..5cbc6874d2 100644 --- a/crypto/ec/ec_lib.c +++ b/crypto/ec/ec_lib.c @@ -93,7 +93,11 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth) ret->extra_data_dup_func = 0; ret->extra_data_free_func = 0; ret->extra_data_clear_free_func = 0; - + + ret->nid = 0; + + ret->references = 1; + if (!meth->group_init(ret)) { OPENSSL_free(ret); @@ -106,6 +110,12 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth) void EC_GROUP_free(EC_GROUP *group) { + int i; + + i = CRYPTO_add(&group->references, -1, CRYPTO_LOCK_EC); + if (i > 0) + return; + if (group->meth->group_finish != 0) group->meth->group_finish(group); @@ -117,6 +127,12 @@ void EC_GROUP_free(EC_GROUP *group) void EC_GROUP_clear_free(EC_GROUP *group) { + int i; + + i = CRYPTO_add(&group->references, -1, CRYPTO_LOCK_EC); + if (i > 0) + return; + if (group->meth->group_clear_finish != 0) group->meth->group_clear_finish(group); else if (group->meth != NULL && group->meth->group_finish != 0) @@ -297,6 +313,16 @@ void EC_GROUP_clear_free_extra_data(EC_GROUP *group) group->extra_data_clear_free_func = 0; } +void EC_GROUP_set_nid(EC_GROUP *group, int nid) +{ + group->nid = nid; +} + +int EC_GROUP_get_nid(const EC_GROUP *group) +{ + return group->nid; +} + /* functions for EC_POINT objects */ |