diff options
author | Bodo Möller <bodo@openssl.org> | 2002-06-10 12:18:21 +0000 |
---|---|---|
committer | Bodo Möller <bodo@openssl.org> | 2002-06-10 12:18:21 +0000 |
commit | 458c29175ec2a7e9a76792fdf7324a20e04fdf08 (patch) | |
tree | 46e332427b9070d1e49b47bd92bcfa8f6c41e502 /crypto | |
parent | 8a5dbb0a2e90aedab1d553cefab6b3616c65e962 (diff) |
move ECC ASN1 that is not specific to ECDSA into crypto/ec/,
and make some appropriate changes to the EC library.
Submitted by: Nils Larsch
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/asn1/x_pubkey.c | 15 | ||||
-rw-r--r-- | crypto/ec/Makefile.ssl | 119 | ||||
-rw-r--r-- | crypto/ec/ec.h | 58 | ||||
-rw-r--r-- | crypto/ec/ec_err.c | 29 | ||||
-rw-r--r-- | crypto/ec/ec_lcl.h | 10 | ||||
-rw-r--r-- | crypto/ec/ec_lib.c | 52 | ||||
-rw-r--r-- | crypto/ec/ecp_mont.c | 1 | ||||
-rw-r--r-- | crypto/ec/ecp_smpl.c | 1 | ||||
-rw-r--r-- | crypto/ecdsa/Makefile.ssl | 8 | ||||
-rw-r--r-- | crypto/ecdsa/ecdsa.h | 12 | ||||
-rw-r--r-- | crypto/ecdsa/ecs_asn1.c | 647 | ||||
-rw-r--r-- | crypto/ecdsa/ecs_err.c | 17 | ||||
-rw-r--r-- | crypto/ecdsa/ecs_lib.c | 18 | ||||
-rw-r--r-- | crypto/ecdsa/ecs_locl.h | 117 |
14 files changed, 405 insertions, 699 deletions
diff --git a/crypto/asn1/x_pubkey.c b/crypto/asn1/x_pubkey.c index 7f7952f1ec..13c753aff3 100644 --- a/crypto/asn1/x_pubkey.c +++ b/crypto/asn1/x_pubkey.c @@ -145,7 +145,8 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) goto err; } - if ((ECDSA_get_parameter_flags(ecdsa) & ECDSA_FLAG_NAMED_CURVE) && (nid = EC_GROUP_get_nid(ecdsa->group))) + if ((EC_GROUP_get_asn1_flag(ecdsa->group) & OPENSSL_EC_NAMED_CURVE) + && (nid = EC_GROUP_get_nid(ecdsa->group))) { /* just set the OID */ a->parameter->type = V_ASN1_OBJECT; @@ -302,13 +303,17 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) /* type == V_ASN1_OBJECT => the parameters are given * by an asn1 OID */ + ECDSA *ecdsa; if (ret->pkey.ecdsa == NULL) ret->pkey.ecdsa = ECDSA_new(); - if (ret->pkey.ecdsa->group) - EC_GROUP_free(ret->pkey.ecdsa->group); - ret->pkey.ecdsa->parameter_flags |= ECDSA_FLAG_NAMED_CURVE; - if ((ret->pkey.ecdsa->group = EC_GROUP_new_by_name(OBJ_obj2nid(a->parameter->value.object))) == NULL) + ecdsa = ret->pkey.ecdsa; + if (ecdsa->group) + EC_GROUP_free(ecdsa->group); + if ((ecdsa->group = EC_GROUP_new_by_name( + OBJ_obj2nid(a->parameter->value.object))) == NULL) goto err; + EC_GROUP_set_asn1_flag(ecdsa->group, OPENSSL_EC_NAMED_CURVE | + (EC_GROUP_get_asn1_flag(ecdsa->group) & ~0x03)); } /* the case implicitlyCA is currently not implemented */ ret->save_parameters = 1; diff --git a/crypto/ec/Makefile.ssl b/crypto/ec/Makefile.ssl index 49b5300708..8aefe1e545 100644 --- a/crypto/ec/Makefile.ssl +++ b/crypto/ec/Makefile.ssl @@ -82,13 +82,14 @@ clean: # DO NOT DELETE THIS LINE -- make depend depends on it. -ec_check.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -ec_check.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -ec_check.o: ../../include/openssl/ec.h ../../include/openssl/err.h -ec_check.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h -ec_check.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h -ec_check.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -ec_check.o: ec_check.c ec_lcl.h +ec_check.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +ec_check.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +ec_check.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h +ec_check.o: ../../include/openssl/err.h ../../include/openssl/lhash.h +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 @@ -98,53 +99,71 @@ 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/asn1.h ../../include/openssl/bio.h +ec_cvt.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +ec_cvt.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h +ec_cvt.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h +ec_cvt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +ec_cvt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h ec_cvt.o: ../../include/openssl/symhacks.h ec_cvt.c ec_lcl.h -ec_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -ec_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -ec_err.o: ../../include/openssl/ec.h ../../include/openssl/err.h -ec_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h -ec_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +ec_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +ec_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +ec_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h +ec_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h +ec_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +ec_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h ec_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h ec_err.o: ec_err.c -ec_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -ec_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -ec_lib.o: ../../include/openssl/ec.h ../../include/openssl/err.h -ec_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h -ec_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h -ec_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -ec_lib.o: ec_lcl.h ec_lib.c -ec_mult.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -ec_mult.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -ec_mult.o: ../../include/openssl/ec.h ../../include/openssl/err.h -ec_mult.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h -ec_mult.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h -ec_mult.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -ec_mult.o: ec_lcl.h ec_mult.c +ec_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +ec_lib.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +ec_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h +ec_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h +ec_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h +ec_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +ec_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +ec_lib.o: ../../include/openssl/symhacks.h ec_lcl.h ec_lib.c +ec_mult.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +ec_mult.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +ec_mult.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h +ec_mult.o: ../../include/openssl/err.h ../../include/openssl/lhash.h +ec_mult.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h +ec_mult.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +ec_mult.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +ec_mult.o: ../../include/openssl/symhacks.h ec_lcl.h ec_mult.c +ec_print.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h ec_print.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h ec_print.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h -ec_print.o: ../../include/openssl/opensslconf.h -ec_print.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h -ec_print.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -ec_print.o: ec_lcl.h ec_print.c -ecp_mont.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -ecp_mont.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -ecp_mont.o: ../../include/openssl/ec.h ../../include/openssl/err.h -ecp_mont.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h -ecp_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h -ecp_mont.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -ecp_mont.o: ec_lcl.h ecp_mont.c -ecp_nist.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h -ecp_nist.o: ../../include/openssl/ec.h ../../include/openssl/opensslconf.h +ec_print.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h +ec_print.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +ec_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +ec_print.o: ../../include/openssl/symhacks.h ec_lcl.h ec_print.c +ecp_mont.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +ecp_mont.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +ecp_mont.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h +ecp_mont.o: ../../include/openssl/err.h ../../include/openssl/lhash.h +ecp_mont.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h +ecp_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +ecp_mont.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +ecp_mont.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_mont.c +ecp_nist.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +ecp_nist.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +ecp_nist.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h +ecp_nist.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h +ecp_nist.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +ecp_nist.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h ecp_nist.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_nist.c -ecp_recp.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h -ecp_recp.o: ../../include/openssl/ec.h ../../include/openssl/opensslconf.h +ecp_recp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +ecp_recp.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +ecp_recp.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h +ecp_recp.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h +ecp_recp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +ecp_recp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h ecp_recp.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_recp.c -ecp_smpl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -ecp_smpl.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -ecp_smpl.o: ../../include/openssl/ec.h ../../include/openssl/err.h -ecp_smpl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h -ecp_smpl.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h -ecp_smpl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -ecp_smpl.o: ec_lcl.h ecp_smpl.c +ecp_smpl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +ecp_smpl.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +ecp_smpl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h +ecp_smpl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h +ecp_smpl.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h +ecp_smpl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +ecp_smpl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +ecp_smpl.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_smpl.c diff --git a/crypto/ec/ec.h b/crypto/ec/ec.h index 2dbe3efadf..1d79dd6a47 100644 --- a/crypto/ec/ec.h +++ b/crypto/ec/ec.h @@ -61,6 +61,7 @@ #endif #include <openssl/bn.h> +#include <openssl/asn1.h> #include <openssl/symhacks.h> #ifdef __cplusplus @@ -108,6 +109,7 @@ void EC_GROUP_clear_free(EC_GROUP *); int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *); const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *); +int EC_METHOD_get_field_type(const EC_METHOD *); 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 *); @@ -226,6 +228,35 @@ int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *); +/* ASN1 stuff */ +#define OPENSSL_EC_EXPLICIT 0x001 +#define OPENSSL_EC_NAMED_CURVE 0x002 +#define OPENSSL_EC_COMPRESSED 0x010 +#define OPENSSL_EC_UNCOMPRESSED 0x020 +#define OPENSSL_EC_HYBRID 0x040 + +typedef struct ec_parameters_st ECPARAMETERS; +typedef struct ecpk_parameters_st ECPKPARAMETERS; + +DECLARE_ASN1_ITEM(ECPARAMETERS) +DECLARE_ASN1_ITEM(ECPKPARAMETERS) +DECLARE_ASN1_ENCODE_FUNCTIONS_const(ECPARAMETERS, ECPARAMETERS) +DECLARE_ASN1_ENCODE_FUNCTIONS_const(ECPKPARAMETERS, ECPKPARAMETERS) + +EC_GROUP *EC_ASN1_pkparameters2group(const ECPKPARAMETERS *); +ECPKPARAMETERS *EC_ASN1_group2pkparameters(const EC_GROUP *, ECPKPARAMETERS *); + +void EC_GROUP_set_asn1_flag(EC_GROUP *, int flag); +int EC_GROUP_get_asn1_flag(const EC_GROUP *); + +EC_GROUP *d2i_ECParameters(EC_GROUP **, const unsigned char **in, long len); +int i2d_ECParameters(const EC_GROUP *, unsigned char **out); + +EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len); +int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out); + + + /* BEGIN ERROR CODES */ /* The following lines are auto generated by the script mkerr.pl. Any changes * made after this point may be overwritten when the script is next run. @@ -236,6 +267,15 @@ void ERR_load_EC_strings(void); /* Function codes. */ #define EC_F_COMPUTE_WNAF 143 +#define EC_F_D2I_ECDSAPARAMETERS 154 +#define EC_F_D2I_ECPARAMETERS 155 +#define EC_F_D2I_ECPKPARAMETERS 161 +#define EC_F_EC_ASN1_GROUP2CURVE 159 +#define EC_F_EC_ASN1_GROUP2FIELDID 156 +#define EC_F_EC_ASN1_GROUP2PARAMETERS 160 +#define EC_F_EC_ASN1_GROUP2PKPARAMETERS 162 +#define EC_F_EC_ASN1_PARAMETERS2GROUP 157 +#define EC_F_EC_ASN1_PKPARAMETERS2GROUP 163 #define EC_F_EC_GFP_MONT_FIELD_DECODE 133 #define EC_F_EC_GFP_MONT_FIELD_ENCODE 134 #define EC_F_EC_GFP_MONT_FIELD_MUL 131 @@ -286,10 +326,23 @@ void ERR_load_EC_strings(void); #define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126 #define EC_F_EC_POINT_SET_TO_INFINITY 127 #define EC_F_GFP_MONT_GROUP_SET_CURVE_GFP 135 +#define EC_F_I2D_ECDSAPARAMETERS 158 +#define EC_F_I2D_ECPARAMETERS 164 +#define EC_F_I2D_ECPKPARAMETERS 165 /* Reason codes. */ +#define EC_R_ASN1_ERROR 130 +#define EC_R_ASN1_UNKNOWN_FIELD 131 #define EC_R_BUFFER_TOO_SMALL 100 +#define EC_R_D2I_ECPARAMETERS_FAILURE 132 +#define EC_R_D2I_ECPKPARAMETERS_FAILURE 133 +#define EC_R_D2I_EC_PARAMETERS_FAILURE 123 #define EC_R_DISCRIMINANT_IS_ZERO 118 +#define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 124 +#define EC_R_GROUP2PARAMETERS_FAILURE 125 +#define EC_R_GROUP2PKPARAMETERS_FAILURE 134 +#define EC_R_I2D_ECPKPARAMETERS_FAILURE 135 +#define EC_R_I2D_EC_PARAMETERS_FAILURE 126 #define EC_R_INCOMPATIBLE_OBJECTS 101 #define EC_R_INVALID_ARGUMENT 112 #define EC_R_INVALID_COMPRESSED_POINT 110 @@ -298,8 +351,12 @@ void ERR_load_EC_strings(void); #define EC_R_INVALID_FIELD 103 #define EC_R_INVALID_FORM 104 #define EC_R_INVALID_GROUP_ORDER 119 +#define EC_R_MISSING_PARAMETERS 127 +#define EC_R_NOT_IMPLEMENTED 136 #define EC_R_NOT_INITIALIZED 111 #define EC_R_NO_SUCH_EXTRA_DATA 105 +#define EC_R_PARAMETERS2GROUP_FAILURE 128 +#define EC_R_PKPARAMETERS2GROUP_FAILURE 137 #define EC_R_POINT_AT_INFINITY 106 #define EC_R_POINT_IS_NOT_ON_CURVE 107 #define EC_R_SLOT_FULL 108 @@ -308,6 +365,7 @@ void ERR_load_EC_strings(void); #define EC_R_UNKNOWN_GROUP 116 #define EC_R_UNKNOWN_NID 117 #define EC_R_UNKNOWN_ORDER 114 +#define EC_R_UNKNOWN_PARAMETERS_TYPE 129 #ifdef __cplusplus } diff --git a/crypto/ec/ec_err.c b/crypto/ec/ec_err.c index efdee969ce..75fa3a8d79 100644 --- a/crypto/ec/ec_err.c +++ b/crypto/ec/ec_err.c @@ -67,13 +67,22 @@ static ERR_STRING_DATA EC_str_functs[]= { {ERR_PACK(0,EC_F_COMPUTE_WNAF,0), "COMPUTE_WNAF"}, +{ERR_PACK(0,EC_F_D2I_ECDSAPARAMETERS,0), "d2i_ECDSAParameters"}, +{ERR_PACK(0,EC_F_D2I_ECPARAMETERS,0), "d2i_ECParameters"}, +{ERR_PACK(0,EC_F_D2I_ECPKPARAMETERS,0), "d2i_ECPKParameters"}, +{ERR_PACK(0,EC_F_EC_ASN1_GROUP2CURVE,0), "EC_ASN1_GROUP2CURVE"}, +{ERR_PACK(0,EC_F_EC_ASN1_GROUP2FIELDID,0), "EC_ASN1_GROUP2FIELDID"}, +{ERR_PACK(0,EC_F_EC_ASN1_GROUP2PARAMETERS,0), "EC_ASN1_GROUP2PARAMETERS"}, +{ERR_PACK(0,EC_F_EC_ASN1_GROUP2PKPARAMETERS,0), "EC_ASN1_GROUP2PKPARAMETERS"}, +{ERR_PACK(0,EC_F_EC_ASN1_PARAMETERS2GROUP,0), "EC_ASN1_PARAMETERS2GROUP"}, +{ERR_PACK(0,EC_F_EC_ASN1_PKPARAMETERS2GROUP,0), "EC_ASN1_PKPARAMETERS2GROUP"}, {ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_DECODE,0), "ec_GFp_mont_field_decode"}, {ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_ENCODE,0), "ec_GFp_mont_field_encode"}, {ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_MUL,0), "ec_GFp_mont_field_mul"}, {ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_SQR,0), "ec_GFp_mont_field_sqr"}, {ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT,0), "ec_GFp_simple_group_check_discriminant"}, {ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP,0), "ec_GFp_simple_group_set_curve_GFp"}, -{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR,0), "ec_GFp_simple_group_set_generator"}, +{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR,0), "EC_GFP_SIMPLE_GROUP_SET_GENERATOR"}, {ERR_PACK(0,EC_F_EC_GFP_SIMPLE_MAKE_AFFINE,0), "ec_GFp_simple_make_affine"}, {ERR_PACK(0,EC_F_EC_GFP_SIMPLE_OCT2POINT,0), "ec_GFp_simple_oct2point"}, {ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT2OCT,0), "ec_GFp_simple_point2oct"}, @@ -117,13 +126,26 @@ static ERR_STRING_DATA EC_str_functs[]= {ERR_PACK(0,EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP,0), "EC_POINT_set_Jprojective_coordinates_GFp"}, {ERR_PACK(0,EC_F_EC_POINT_SET_TO_INFINITY,0), "EC_POINT_set_to_infinity"}, {ERR_PACK(0,EC_F_GFP_MONT_GROUP_SET_CURVE_GFP,0), "GFP_MONT_GROUP_SET_CURVE_GFP"}, +{ERR_PACK(0,EC_F_I2D_ECDSAPARAMETERS,0), "i2d_ECDSAParameters"}, +{ERR_PACK(0,EC_F_I2D_ECPARAMETERS,0), "i2d_ECParameters"}, +{ERR_PACK(0,EC_F_I2D_ECPKPARAMETERS,0), "i2d_ECPKParameters"}, {0,NULL} }; static ERR_STRING_DATA EC_str_reasons[]= { +{EC_R_ASN1_ERROR ,"asn1 error"}, +{EC_R_ASN1_UNKNOWN_FIELD ,"asn1 unknown field"}, {EC_R_BUFFER_TOO_SMALL ,"buffer too small"}, +{EC_R_D2I_ECPARAMETERS_FAILURE ,"d2i ecparameters failure"}, +{EC_R_D2I_ECPKPARAMETERS_FAILURE ,"d2i ecpkparameters failure"}, +{EC_R_D2I_EC_PARAMETERS_FAILURE ,"d2i ec parameters failure"}, {EC_R_DISCRIMINANT_IS_ZERO ,"discriminant is zero"}, +{EC_R_EC_GROUP_NEW_BY_NAME_FAILURE ,"ec group new by name failure"}, +{EC_R_GROUP2PARAMETERS_FAILURE ,"group2parameters failure"}, +{EC_R_GROUP2PKPARAMETERS_FAILURE ,"group2pkparameters failure"}, +{EC_R_I2D_ECPKPARAMETERS_FAILURE ,"i2d ecpkparameters failure"}, +{EC_R_I2D_EC_PARAMETERS_FAILURE ,"i2d ec parameters failure"}, {EC_R_INCOMPATIBLE_OBJECTS ,"incompatible objects"}, {EC_R_INVALID_ARGUMENT ,"invalid argument"}, {EC_R_INVALID_COMPRESSED_POINT ,"invalid compressed point"}, @@ -132,8 +154,12 @@ static ERR_STRING_DATA EC_str_reasons[]= {EC_R_INVALID_FIELD ,"invalid field"}, {EC_R_INVALID_FORM ,"invalid form"}, {EC_R_INVALID_GROUP_ORDER ,"invalid group order"}, +{EC_R_MISSING_PARAMETERS ,"missing parameters"}, +{EC_R_NOT_IMPLEMENTED ,"not implemented"}, {EC_R_NOT_INITIALIZED ,"not initialized"}, {EC_R_NO_SUCH_EXTRA_DATA ,"no such extra data"}, +{EC_R_PARAMETERS2GROUP_FAILURE ,"parameters2group failure"}, +{EC_R_PKPARAMETERS2GROUP_FAILURE ,"pkparameters2group failure"}, {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"}, @@ -142,6 +168,7 @@ static ERR_STRING_DATA EC_str_reasons[]= {EC_R_UNKNOWN_GROUP ,"unknown group"}, {EC_R_UNKNOWN_NID ,"unknown nid"}, {EC_R_UNKNOWN_ORDER ,"unknown order"}, +{EC_R_UNKNOWN_PARAMETERS_TYPE ,"unknown parameters type"}, {0,NULL} }; diff --git a/crypto/ec/ec_lcl.h b/crypto/ec/ec_lcl.h index 79655e3d3a..b9f6fcbba2 100644 --- a/crypto/ec/ec_lcl.h +++ b/crypto/ec/ec_lcl.h @@ -56,6 +56,7 @@ #include <stdlib.h> +#include <openssl/obj_mac.h> #include <openssl/ec.h> @@ -63,6 +64,9 @@ * so all this may change in future versions. */ struct ec_method_st { + /* used by EC_METHOD_get_field_type: */ + int field_type; /* a NID */ + /* used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, EC_GROUP_copy: */ int (*group_init)(EC_GROUP *); void (*group_finish)(EC_GROUP *); @@ -140,13 +144,17 @@ struct ec_group_st { EC_POINT *generator; /* optional */ BIGNUM order, cofactor; - int nid; /* optional NID for named curve */ + int nid; /* optional NID for named curve */ + int asn1_flag; /* flag to control the asn1 encoding */ void *extra_data; void *(*extra_data_dup_func)(void *); void (*extra_data_free_func)(void *); void (*extra_data_clear_free_func)(void *); + unsigned char *seed; /* XXX */ + size_t seed_len; /* XXX */ + /* The following members are handled by the method functions, * even if they appear generic */ diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c index f469b679d8..06d45e998f 100644 --- a/crypto/ec/ec_lib.c +++ b/crypto/ec/ec_lib.c @@ -99,6 +99,10 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth) BN_init(&ret->cofactor); ret->nid = 0; + ret->asn1_flag = OPENSSL_EC_EXPLICIT | OPENSSL_EC_COMPRESSED; + + ret->seed = NULL; + ret->seed_len = 0; if (!meth->group_init(ret)) { @@ -124,6 +128,9 @@ void EC_GROUP_free(EC_GROUP *group) BN_free(&group->order); BN_free(&group->cofactor); + if (group->seed) + OPENSSL_free(group->seed); + OPENSSL_free(group); } @@ -144,6 +151,12 @@ void EC_GROUP_clear_free(EC_GROUP *group) BN_clear_free(&group->order); BN_clear_free(&group->cofactor); + if (group->seed) + { + memset(group->seed, 0, group->seed_len); + OPENSSL_free(group->seed); + } + memset(group, 0, sizeof *group); OPENSSL_free(group); } @@ -202,6 +215,27 @@ int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src) if (!BN_copy(&dest->cofactor, &src->cofactor)) return 0; dest->nid = src->nid; + dest->asn1_flag = src->asn1_flag; + + if (src->seed) + { + if (dest->seed) + OPENSSL_free(dest->seed); + dest->seed = OPENSSL_malloc(src->seed_len); + if (dest->seed == NULL) + return 0; + if (!memcpy(dest->seed, src->seed, src->seed_len)) + return 0; + dest->seed_len = src->seed_len; + } + else + { + if (dest->seed) + OPENSSL_free(dest->seed); + dest->seed = NULL; + dest->seed_len = 0; + } + return dest->meth->group_copy(dest, src); } @@ -213,6 +247,12 @@ const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group) } +int EC_METHOD_get_field_type(const EC_METHOD *meth) + { + return meth->field_type; + } + + int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor) { if (generator == NULL) @@ -278,6 +318,18 @@ int EC_GROUP_get_nid(const EC_GROUP *group) } +void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag) + { + group->asn1_flag = flag; + } + + +int EC_GROUP_get_asn1_flag(const EC_GROUP *group) + { + return group->asn1_flag; + } + + int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) { if (group->meth->group_set_curve_GFp == 0) diff --git a/crypto/ec/ecp_mont.c b/crypto/ec/ecp_mont.c index 6f1eaa497b..75c9f6ed15 100644 --- a/crypto/ec/ecp_mont.c +++ b/crypto/ec/ecp_mont.c @@ -61,6 +61,7 @@ const EC_METHOD *EC_GFp_mont_method(void) { static const EC_METHOD ret = { + NID_X9_62_prime_field, ec_GFp_mont_group_init, ec_GFp_mont_group_finish, ec_GFp_mont_group_clear_finish, diff --git a/crypto/ec/ecp_smpl.c b/crypto/ec/ecp_smpl.c index be7f15f782..a453f4f451 100644 --- a/crypto/ec/ecp_smpl.c +++ b/crypto/ec/ecp_smpl.c @@ -63,6 +63,7 @@ const EC_METHOD *EC_GFp_simple_method(void) { static const EC_METHOD ret = { + NID_X9_62_prime_field, ec_GFp_simple_group_init, ec_GFp_simple_group_finish, ec_GFp_simple_group_clear_finish, diff --git a/crypto/ecdsa/Makefile.ssl b/crypto/ecdsa/Makefile.ssl index f43258d693..85049bc39b 100644 --- a/crypto/ecdsa/Makefile.ssl +++ b/crypto/ecdsa/Makefile.ssl @@ -32,7 +32,7 @@ LIBOBJ= ecs_lib.o ecs_gen.o ecs_asn1.o ecs_ossl.o ecs_sign.o ecs_vrf.o \ SRC= $(LIBSRC) EXHEADER= ecdsa.h -HEADER= ecs_locl.h $(EXHEADER) +HEADER= $(EXHEADER) ALL= $(GENERAL) $(SRC) $(HEADER) @@ -87,12 +87,10 @@ ecs_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h ecs_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h ecs_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h ecs_asn1.o: ../../include/openssl/ec.h ../../include/openssl/err.h -ecs_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h -ecs_asn1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +ecs_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h ecs_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h ecs_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h ecs_asn1.o: ../../include/openssl/symhacks.h ../cryptlib.h ecdsa.h ecs_asn1.c -ecs_asn1.o: ecs_locl.h ecs_err.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h ecs_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h ecs_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h @@ -125,7 +123,7 @@ ecs_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h ecs_lib.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h ecs_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h ecs_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h -ecs_lib.o: ../cryptlib.h ecdsa.h ecs_lib.c ecs_locl.h +ecs_lib.o: ../cryptlib.h ecdsa.h ecs_lib.c ecs_ossl.o: ../../e_os.h ../../include/openssl/asn1.h ecs_ossl.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h ecs_ossl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h diff --git a/crypto/ecdsa/ecdsa.h b/crypto/ecdsa/ecdsa.h index 8dbe872d64..f9a34f14ae 100644 --- a/crypto/ecdsa/ecdsa.h +++ b/crypto/ecdsa/ecdsa.h @@ -93,9 +93,6 @@ typedef struct ecdsa_method char *app_data; } ECDSA_METHOD; -#define ECDSA_FLAG_NAMED_CURVE 1 -#define ECDSA_FLAG_IMPLICITLYCA 2 - struct ecdsa_st { int version; @@ -109,11 +106,6 @@ struct ecdsa_st BIGNUM *kinv; /* signing pre-calc */ BIGNUM *r; /* signing pre-calc */ - unsigned char *seed; /* seed for curve generation */ - unsigned int seed_len; - - int parameter_flags; - int references; int flags; CRYPTO_EX_DATA ex_data; @@ -161,9 +153,6 @@ int ECDSAParameters_print_fp(FILE *fp, const ECDSA *x); int ECDSA_print_fp(FILE *fp, const ECDSA *x, int off); #endif -void ECDSA_set_parameter_flags(ECDSA *, int); -int ECDSA_get_parameter_flags(const ECDSA*); - /* The ECDSA_{set|get}_conversion_type() functions set/get the * conversion form for ec-points (see ec.h) in a ECDSA-structure */ void ECDSA_set_conversion_form(ECDSA *, const point_conversion_form_t); @@ -259,6 +248,7 @@ void ERR_load_ECDSA_strings(void); #define ECDSA_R_I2D_ECDSA_PRIVATEKEY 115 #define ECDSA_R_I2D_ECDSA_PUBLICKEY 116 #define ECDSA_R_MISSING_PARAMETERS 117 +#define ECDSA_R_MISSING_PRIVATE_KEY 139 #define ECDSA_R_NOT_SUPPORTED 118 #define ECDSA_R_NO_CURVE_PARAMETER_A_SPECIFIED 119 #define ECDSA_R_NO_CURVE_PARAMETER_B_SPECIFIED 120 diff --git a/crypto/ecdsa/ecs_asn1.c b/crypto/ecdsa/ecs_asn1.c index 07899150be..38b27592bd 100644 --- a/crypto/ecdsa/ecs_asn1.c +++ b/crypto/ecdsa/ecs_asn1.c @@ -53,64 +53,31 @@ * */ +#include "ecdsa.h" #include "cryptlib.h" -#include "ecs_locl.h" #include <openssl/asn1.h> #include <openssl/asn1t.h> -#include <openssl/objects.h> + +typedef struct ecdsa_priv_key_st { + int version; + ECPKPARAMETERS *parameters; + ASN1_OBJECT *named_curve; + ASN1_OCTET_STRING *pub_key; + BIGNUM *priv_key; + } ECDSAPrivateKey; ASN1_SEQUENCE(ECDSA_SIG) = { ASN1_SIMPLE(ECDSA_SIG, r, CBIGNUM), ASN1_SIMPLE(ECDSA_SIG, s, CBIGNUM) } ASN1_SEQUENCE_END(ECDSA_SIG) +DECLARE_ASN1_FUNCTIONS_const(ECDSA_SIG) +DECLARE_ASN1_ENCODE_FUNCTIONS_const(ECDSA_SIG, ECDSA_SIG) IMPLEMENT_ASN1_FUNCTIONS_const(ECDSA_SIG) -ASN1_SEQUENCE(X9_62_FIELDID) = { - ASN1_SIMPLE(X9_62_FIELDID, fieldType, ASN1_OBJECT), - ASN1_SIMPLE(X9_62_FIELDID, parameters, ASN1_ANY) -} ASN1_SEQUENCE_END(X9_62_FIELDID) - -DECLARE_ASN1_FUNCTIONS_const(X9_62_FIELDID) -DECLARE_ASN1_ENCODE_FUNCTIONS_const(X9_62_FIELDID, X9_62_FIELDID) -IMPLEMENT_ASN1_FUNCTIONS_const(X9_62_FIELDID) - -ASN1_SEQUENCE(X9_62_CURVE) = { - ASN1_SIMPLE(X9_62_CURVE, a, ASN1_OCTET_STRING), - ASN1_SIMPLE(X9_62_CURVE, b, ASN1_OCTET_STRING), - ASN1_OPT(X9_62_CURVE, seed, ASN1_BIT_STRING) -} ASN1_SEQUENCE_END(X9_62_CURVE) - -DECLARE_ASN1_FUNCTIONS_const(X9_62_CURVE) -DECLARE_ASN1_ENCODE_FUNCTIONS_const(X9_62_CURVE, X9_62_CURVE) -IMPLEMENT_ASN1_FUNCTIONS_const(X9_62_CURVE) - -ASN1_SEQUENCE(X9_62_EC_PARAMETERS) = { - ASN1_SIMPLE(X9_62_EC_PARAMETERS, version, ASN1_INTEGER), - ASN1_SIMPLE(X9_62_EC_PARAMETERS, fieldID, X9_62_FIELDID), - ASN1_SIMPLE(X9_62_EC_PARAMETERS, curve, X9_62_CURVE), - ASN1_SIMPLE(X9_62_EC_PARAMETERS, base, ASN1_OCTET_STRING), - ASN1_SIMPLE(X9_62_EC_PARAMETERS, order, ASN1_INTEGER), - ASN1_SIMPLE(X9_62_EC_PARAMETERS, cofactor, ASN1_INTEGER) -} ASN1_SEQUENCE_END(X9_62_EC_PARAMETERS) - -DECLARE_ASN1_FUNCTIONS_const(X9_62_EC_PARAMETERS) -DECLARE_ASN1_ENCODE_FUNCTIONS_const(X9_62_EC_PARAMETERS, X9_62_EC_PARAMETERS) -IMPLEMENT_ASN1_FUNCTIONS_const(X9_62_EC_PARAMETERS) - -ASN1_CHOICE(EC_PARAMETERS) = { - ASN1_SIMPLE(EC_PARAMETERS, value.named_curve, ASN1_OBJECT), - ASN1_SIMPLE(EC_PARAMETERS, value.parameters, X9_62_EC_PARAMETERS), - ASN1_SIMPLE(EC_PARAMETERS, value.implicitlyCA, ASN1_NULL) -} ASN1_CHOICE_END(EC_PARAMETERS) - -DECLARE_ASN1_FUNCTIONS_const(EC_PARAMETERS) -DECLARE_ASN1_ENCODE_FUNCTIONS_const(EC_PARAMETERS, EC_PARAMETERS) -IMPLEMENT_ASN1_FUNCTIONS_const(EC_PARAMETERS) - ASN1_SEQUENCE(ECDSAPrivateKey) = { ASN1_SIMPLE(ECDSAPrivateKey, version, LONG), - ASN1_SIMPLE(ECDSAPrivateKey, parameters, EC_PARAMETERS), + ASN1_SIMPLE(ECDSAPrivateKey, parameters, ECPKPARAMETERS), ASN1_SIMPLE(ECDSAPrivateKey, pub_key, ASN1_OCTET_STRING), ASN1_SIMPLE(ECDSAPrivateKey, priv_key, BIGNUM) } ASN1_SEQUENCE_END(ECDSAPrivateKey) @@ -120,502 +87,213 @@ DECLARE_ASN1_ENCODE_FUNCTIONS_const(ECDSAPrivateKey, ecdsaPrivateKey) IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(ECDSAPrivateKey, ECDSAPrivateKey, ECDSAPrivateKey) IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ECDSAPrivateKey, ECDSAPrivateKey, ecdsaPrivateKey) - -X9_62_FIELDID *ECDSA_get_X9_62_FIELDID(const ECDSA *ecdsa, X9_62_FIELDID *field) -{ - /* TODO : characteristic two */ - int ok=0, reason=ERR_R_ASN1_LIB; - X9_62_FIELDID *ret=NULL; - BIGNUM *tmp=NULL; - - if (!ecdsa || !ecdsa->group) - OPENSSL_ECDSA_ABORT(ECDSA_R_MISSING_PARAMETERS) - if (field == NULL) - { - if ((ret = X9_62_FIELDID_new()) == NULL) return NULL; - } - else - { - ret = field; - if (ret->fieldType != NULL) ASN1_OBJECT_free(ret->fieldType); - if (ret->parameters != NULL) ASN1_TYPE_free(ret->parameters); - } - if ((tmp = BN_new()) == NULL) - OPENSSL_ECDSA_ABORT(ERR_R_BN_LIB) - if ((ret->fieldType = OBJ_nid2obj(NID_X9_62_prime_field)) == NULL) - OPENSSL_ECDSA_ABORT(ERR_R_OBJ_LIB) - if ((ret->parameters = ASN1_TYPE_new()) == NULL) goto err; - ret->parameters->type = V_ASN1_INTEGER; - if (!EC_GROUP_get_curve_GFp(ecdsa->group, tmp, NULL, NULL, NULL)) - OPENSSL_ECDSA_ABORT(ERR_R_EC_LIB) - if ((ret->parameters->value.integer = BN_to_ASN1_INTEGER(tmp, NULL)) == NULL) goto err; - ok = 1; -err : if (!ok) +int i2d_ECDSAParameters(ECDSA *a, unsigned char **out) { - if (ret && !field) X9_62_FIELDID_free(ret); - ret = NULL; - ECDSAerr(ECDSA_F_ECDSA_GET_X9_62_FIELDID, reason); + if (a == NULL) + { + ECDSAerr(ECDSA_F_I2D_ECDSAPARAMETERS, + ERR_R_PASSED_NULL_PARAMETER); + return 0; + } + return i2d_ECPKParameters(a->group, out); } - if (tmp) BN_free(tmp); - return(ret); -} -X9_62_CURVE *ECDSA_get_X9_62_CURVE(const ECDSA *ecdsa, X9_62_CURVE *curve) -{ - int ok=0, reason=ERR_R_BN_LIB, len1=0, len2=0; - X9_62_CURVE *ret=NULL; - BIGNUM *tmp1=NULL, *tmp2=NULL; - unsigned char *buffer=NULL; - unsigned char char_buf = 0; - - if (!ecdsa || !ecdsa->group) - OPENSSL_ECDSA_ABORT(ECDSA_R_MISSING_PARAMETERS) - if ((tmp1 = BN_new()) == NULL || (tmp2 = BN_new()) == NULL) goto err; - if (curve == NULL) - { - if ((ret = X9_62_CURVE_new()) == NULL) - OPENSSL_ECDSA_ABORT(ECDSA_R_X9_62_CURVE_NEW_FAILURE) - } - else +ECDSA *d2i_ECDSAParameters(ECDSA **a, const unsigned char **in, long len) { - ret = curve; - if (ret->a) ASN1_OCTET_STRING_free(ret->a); - if (ret->b) ASN1_OCTET_STRING_free(ret->b); - if (ret->seed) ASN1_BIT_STRING_free(ret->seed); - } - if (!EC_GROUP_get_curve_GFp(ecdsa->group, NULL, tmp1, tmp2, NULL)) - OPENSSL_ECDSA_ABORT(ERR_R_EC_LIB) + EC_GROUP *group; + ECDSA *ret; - if ((ret->a = M_ASN1_OCTET_STRING_new()) == NULL || - (ret->b |