move ECC ASN1 that is not specific to ECDSA into crypto/ec/,
authorBodo Möller <bodo@openssl.org>
Mon, 10 Jun 2002 12:18:21 +0000 (12:18 +0000)
committerBodo Möller <bodo@openssl.org>
Mon, 10 Jun 2002 12:18:21 +0000 (12:18 +0000)
and make some appropriate changes to the EC library.

Submitted by: Nils Larsch

17 files changed:
CHANGES
apps/ecdsaparam.c
crypto/asn1/x_pubkey.c
crypto/ec/Makefile.ssl
crypto/ec/ec.h
crypto/ec/ec_err.c
crypto/ec/ec_lcl.h
crypto/ec/ec_lib.c
crypto/ec/ecp_mont.c
crypto/ec/ecp_smpl.c
crypto/ecdsa/Makefile.ssl
crypto/ecdsa/ecdsa.h
crypto/ecdsa/ecs_asn1.c
crypto/ecdsa/ecs_err.c
crypto/ecdsa/ecs_lib.c
crypto/ecdsa/ecs_locl.h [deleted file]
util/libeay.num

diff --git a/CHANGES b/CHANGES
index 21e4491..5c49040 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,19 @@
 
  Changes between 0.9.7 and 0.9.8  [xx XXX 2002]
 
+  *) Add 'nid' and 'asn1_flag' members to EC_GROUP, and functions
+          EC_GROUP_get_nid()
+          EC_GROUP_get_set_asn1_flag()
+          EC_GROUP_get_get_asn1_flag()
+     'nid' is an optional NID for named curves.  'asn1_flag'
+     determines the encoding to be used for ASN1 purposes.
+     [Nils Larsch <nla@trustcenter.de>]
+
+  *) Add 'field_type' member to EC_METHOD, which holds the NID
+     of the appropriate field type OID.  The new function
+     EC_METHOD_get_field_type() returns this value.
+     [Nils Larsch <nla@trustcenter.de>]
+
   *) Add functions 
           EC_POINT_point2bn()
           EC_POINT_bn2point()
index d3eca16..9f78af6 100644 (file)
@@ -431,7 +431,9 @@ bad:
                        goto end;
                ecdsa->group = EC_GROUP_new_by_name(curve_type);
                if (named_curve)
-                       ECDSA_set_parameter_flags(ecdsa, ECDSA_FLAG_NAMED_CURVE);
+                       EC_GROUP_set_asn1_flag(ecdsa->group, 
+                                OPENSSL_EC_NAMED_CURVE |
+                               (EC_GROUP_get_asn1_flag(ecdsa->group) & ~0x3));
        }
        else if (informat == FORMAT_ASN1)
                ecdsa = d2i_ECDSAParameters_bio(in,NULL);
index 7f7952f..13c753a 100644 (file)
@@ -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;
index 49b5300..8aefe1e 100644 (file)
@@ -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
index 2dbe3ef..1d79dd6 100644 (file)
@@ -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
 }
index efdee96..75fa3a8 100644 (file)
 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}
        };
 
index 79655e3..b9f6fcb 100644 (file)
@@ -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 */
        
index f469b67..06d45e9 100644 (file)
@@ -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)
index 6f1eaa4..75c9f6e 100644 (file)
@@ -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,
index be7f15f..a453f4f 100644 (file)
@@ -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,
index f43258d..85049bc 100644 (file)
@@ -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
index 8dbe872..f9a34f1 100644 (file)
@@ -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
index 0789915..38b2759 100644 (file)
  *
  */
 
+#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 = M_ASN1_OCTET_STRING_new()) == NULL )
-               OPENSSL_ECDSA_ABORT(ERR_R_ASN1_LIB)
+       if (in == NULL || *in == NULL)
+               {
+               ECDSAerr(ECDSA_F_D2I_ECDSAPARAMETERS, 
+                         ERR_R_PASSED_NULL_PARAMETER);
+               return NULL;
+               }
 
-       len1 = BN_num_bytes(tmp1);
-       len2 = BN_num_bytes(tmp2);
+       group = d2i_ECPKParameters(NULL, in, len);
 
-       if ((buffer = OPENSSL_malloc(len1 > len2 ? len1 : len2)) == NULL)
-               OPENSSL_ECDSA_ABORT(ERR_R_MALLOC_FAILURE)
+       if (group == NULL)
+               {
+               ECDSAerr(ECDSA_F_D2I_ECDSAPARAMETERS, 
+                         ERR_R_EC_LIB);
+               return NULL;
+               }
 
-       if (len1 == 0) /* => a == 0 */
-       {
-               if (!M_ASN1_OCTET_STRING_set(ret->a, &char_buf, 1))
-                       OPENSSL_ECDSA_ABORT(ERR_R_ASN1_LIB)
-       }
-       else
-       {
-               if ((len1 = BN_bn2bin(tmp1, buffer)) == 0) goto err;
-               if (!M_ASN1_OCTET_STRING_set(ret->a, buffer, len1))
-                       OPENSSL_ECDSA_ABORT(ERR_R_ASN1_LIB)
-       }
-       if (len2 == 0) /* => b == 0 */
-       {
-               if (!M_ASN1_OCTET_STRING_set(ret->a, &char_buf, 1))
-                       OPENSSL_ECDSA_ABORT(ERR_R_ASN1_LIB)
-       }
+       if (a == NULL || *a == NULL)
+               {
+               if ((ret = ECDSA_new()) == NULL)
+                       {
+                       ECDSAerr(ECDSA_F_D2I_ECDSAPARAMETERS, 
+                                 ERR_R_MALLOC_FAILURE);
+                       return NULL;
+                       }
+               if (a)
+                       *a = ret;
+               }
        else
-       {
-               if ((len2 = BN_bn2bin(tmp2, buffer)) == 0) goto err;
-               if (!M_ASN1_OCTET_STRING_set(ret->b, buffer, len2))
-                       OPENSSL_ECDSA_ABORT(ERR_R_ASN1_LIB)
-       }
+               ret = *a;
 
-       if (ecdsa->seed)
-       {       
-               if ((ret->seed = ASN1_BIT_STRING_new()) == NULL) goto err;
-               if (!ASN1_BIT_STRING_set(ret->seed, ecdsa->seed, (int)ecdsa->seed_len))
-                       OPENSSL_ECDSA_ABORT(ERR_R_ASN1_LIB)
-       }
-       else
-               ret->seed = NULL;
+       if (ret->group)
+               EC_GROUP_clear_free(ret->group);
 
-       ok = 1;
-err :  if (!ok)
-       {
-               if (ret && !curve) X9_62_CURVE_free(ret);
-               ret = NULL;
-               ECDSAerr(ECDSA_F_ECDSA_GET_X9_62_CURVE, reason);
-       }
-       if (buffer) OPENSSL_free(buffer);
-       if (tmp1)   BN_free(tmp1);
-       if (tmp2)   BN_free(tmp2);
-       return(ret);
-}
-
-X9_62_EC_PARAMETERS *ECDSA_get_X9_62_EC_PARAMETERS(const ECDSA *ecdsa, X9_62_EC_PARAMETERS *param)
-{
-       int     ok=0, reason=ERR_R_ASN1_LIB;
-       size_t  len=0;
-       X9_62_EC_PARAMETERS *ret=NULL;
-       BIGNUM        *tmp=NULL;
-       unsigned char *buffer=NULL;
-       EC_POINT      *point=NULL;
-
-       if (!ecdsa || !ecdsa->group)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_MISSING_PARAMETERS)
-       if ((tmp = BN_new()) == NULL)
-               OPENSSL_ECDSA_ABORT(ERR_R_BN_LIB)
-       if (param == NULL)
-       {
-               if ((ret = X9_62_EC_PARAMETERS_new()) == NULL)
-                       OPENSSL_ECDSA_ABORT(ECDSA_R_X9_62_EC_PARAMETERS_NEW_FAILURE)
+       ret->group = group;
+       
+       return ret;
        }
-       else
-               ret = param;
-       if (ret->version == NULL && (ret->version = ASN1_INTEGER_new()) == NULL)
-               OPENSSL_ECDSA_ABORT(ERR_R_MALLOC_FAILURE)
-       if (!ASN1_INTEGER_set(ret->version, (long)ecdsa->version)) goto err;
-       if ((ret->fieldID = ECDSA_get_X9_62_FIELDID(ecdsa, ret->fieldID)) == NULL)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_ECDSA_GET_X9_62_FIELDID_FAILURE)
-       if ((ret->curve = ECDSA_get_X9_62_CURVE(ecdsa, ret->curve)) == NULL)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_ECDSA_GET_X9_62_CURVE_FAILURE)
-       if ((point = EC_GROUP_get0_generator(ecdsa->group)) == NULL)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_CAN_NOT_GET_GENERATOR)
-       if (!(len = EC_POINT_point2oct(ecdsa->group, point, POINT_CONVERSION_COMPRESSED, NULL, len, NULL)))
-               OPENSSL_ECDSA_ABORT(ECDSA_R_UNEXPECTED_PARAMETER_LENGTH)
-       if ((buffer = OPENSSL_malloc(len)) == NULL)
-               OPENSSL_ECDSA_ABORT(ERR_R_MALLOC_FAILURE)
-       if (!EC_POINT_point2oct(ecdsa->group, point, POINT_CONVERSION_COMPRESSED, buffer, len, NULL)) 
-               OPENSSL_ECDSA_ABORT(ERR_R_EC_LIB)
-       if (ret->base == NULL && (ret->base = ASN1_OCTET_STRING_new()) == NULL)
-               OPENSSL_ECDSA_ABORT(ERR_R_MALLOC_FAILURE)
-       if (!ASN1_OCTET_STRING_set(ret->base, buffer, len)) goto err;
-       if (!EC_GROUP_get_order(ecdsa->group, tmp, NULL))
-               OPENSSL_ECDSA_ABORT(ERR_R_EC_LIB)
-       if ((ret->order = BN_to_ASN1_INTEGER(tmp, ret->order)) == NULL) goto err;
-       if (!EC_GROUP_get_cofactor(ecdsa->group, tmp, NULL))
-               OPENSSL_ECDSA_ABORT(ERR_R_EC_LIB)
-       if ((ret->cofactor = BN_to_ASN1_INTEGER(tmp, ret->cofactor)) == NULL) goto err;
-       ok = 1;
 
-err :  if(!ok)
+ECDSA *d2i_ECDSAPrivateKey(ECDSA **a, const unsigned char **in, long len)
        {
-               ECDSAerr(ECDSA_F_ECDSA_GET_X9_62_EC_PARAMETERS, reason);
-               if (ret && !param) X9_62_EC_PARAMETERS_free(ret);
-               ret = NULL;
-       }
-       if (tmp)    BN_free(tmp);
-       if (buffer) OPENSSL_free(buffer);
-       return(ret);
-}
+       int             ok=0;
+       ECDSA           *ret=NULL;
+       ECDSAPrivateKey *priv_key=NULL;
 
-EC_PARAMETERS *ECDSA_get_EC_PARAMETERS(const ECDSA *ecdsa, EC_PARAMETERS *params)
-{
-       int ok = 1;
-       int tmp = 0;
-       EC_PARAMETERS *ret = params;
-       if (ret == NULL)
-               if ((ret = EC_PARAMETERS_new()) == NULL)
+       if ((priv_key = ECDSAPrivateKey_new()) == NULL)
                {
-                       ECDSAerr(ECDSA_F_ECDSA_GET_EC_PARAMETERS, ERR_R_MALLOC_FAILURE);
-                       return NULL;
-               }
-       if (ecdsa == NULL)
-       {       /* missing parameter */
-               ECDSAerr(ECDSA_F_ECDSA_GET_EC_PARAMETERS, ECDSA_R_MISSING_PARAMETERS);
-               EC_PARAMETERS_free(params);
+               ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ERR_R_MALLOC_FAILURE);
                return NULL;
-       }
-       if (ecdsa->parameter_flags & ECDSA_FLAG_NAMED_CURVE)
-       {       /* use a named curve */
-               tmp = EC_GROUP_get_nid(ecdsa->group);
-               if (tmp)
-               {
-                       ret->type = 0;
-                       if ((ret->value.named_curve = OBJ_nid2obj(tmp)) == NULL)
-                               ok = 0;
-               }
-               else
-               {
-                       /* use the x9_64 ec_parameters structure */
-                       ret->type = 1;
-                       if ((ret->value.parameters = ECDSA_get_X9_62_EC_PARAMETERS(ecdsa, NULL)) == NULL)
-                               ok = 0;
                }
-       }
-       else if (ecdsa->parameter_flags & ECDSA_FLAG_IMPLICITLYCA)
-       {       /* use implicitlyCA */
-               ret->type = 2;
-               if ((ret->value.implicitlyCA = ASN1_NULL_new()) == NULL)
-                       ok = 0;
-       }
-       else
-       {       /* use the x9_64 ec_parameters structure */
-               ret->type = 1;
-               if ((ret->value.parameters = ECDSA_get_X9_62_EC_PARAMETERS(ecdsa, NULL)) == NULL)
-                       ok = 0;
-       }
-       if (!ok)
-       {
-               EC_PARAMETERS_free(ret);
-               return NULL;
-       }
-               return ret;
-}
 
-ECDSA         *ECDSA_x9_62parameters2ecdsa(const X9_62_EC_PARAMETERS *params, ECDSA *ecdsa)
-{
-       int       ok=0, reason=ERR_R_EC_LIB, tmp;
-       ECDSA     *ret=NULL;
-       const EC_METHOD *meth=NULL;
-       BIGNUM    *tmp_1=NULL, *tmp_2=NULL, *tmp_3=NULL;
-       EC_POINT  *point=NULL;
-
-       if (!params) 
-               OPENSSL_ECDSA_ABORT(ECDSA_R_MISSING_PARAMETERS)
-       if (ecdsa == NULL)
-       {
-               if ((ret = ECDSA_new()) == NULL) 
-                       OPENSSL_ECDSA_ABORT(ECDSA_R_ECDSA_NEW_FAILURE)
-       }
-       else
-       {
-               if (ecdsa->group)       EC_GROUP_free(ecdsa->group);
-               if (ecdsa->pub_key)     EC_POINT_free(ecdsa->pub_key);
-               ecdsa->pub_key = NULL;
-               if (ecdsa->priv_key)    BN_clear_free(ecdsa->priv_key);
-               ecdsa->priv_key = NULL;
-               if (ecdsa->seed)        OPENSSL_free(ecdsa->seed);
-               ecdsa->seed = NULL;
-               if (ecdsa->kinv)        
+       if ((priv_key = d2i_ecdsaPrivateKey(&priv_key, in, len)) == NULL)
                {
-                       BN_clear_free(ecdsa->kinv);
-                       ecdsa->kinv = NULL;
+               ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY,
+                         ECDSA_R_D2I_ECDSA_PRIVATEKEY_FAILURE);
+               ECDSAPrivateKey_free(priv_key);
+               return NULL;
                }
-               if (ecdsa->r)
+
+       if (a == NULL || *a == NULL)
                {
-                       BN_clear_free(ecdsa->r);
-                       ecdsa->r = NULL;
+               if ((ret = ECDSA_new()) == NULL)        
+                       {
+                       ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY,
+                                 ERR_R_MALLOC_FAILURE);
+                       goto err;
+                       }
+               if (a)
+                       *a = ret;
                }
-               ret = ecdsa;
-       }
-       /* TODO : characteristic two */
-       if (!params->fieldID || !params->fieldID->fieldType || !params->fieldID->parameters)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_NO_FIELD_SPECIFIED)
-       tmp = OBJ_obj2nid(params->fieldID->fieldType); 
-       if (tmp == NID_X9_62_characteristic_two_field)
-       {
-               OPENSSL_ECDSA_ABORT(ECDSA_R_NOT_SUPPORTED)
-       }
-       else if (tmp == NID_X9_62_prime_field)
-       {
-               /* TODO : optimal method for the curve */
-               meth = EC_GFp_mont_method();
-               if ((ret->group = EC_GROUP_new(meth)) == NULL) goto err;
-               if (params->fieldID->parameters->type != V_ASN1_INTEGER)
-                       OPENSSL_ECDSA_ABORT(ECDSA_R_UNEXPECTED_ASN1_TYPE)
-               if (!params->fieldID->parameters->value.integer)
-                       OPENSSL_ECDSA_ABORT(ECDSA_R_PRIME_MISSING)
-               if ((tmp_1 = ASN1_INTEGER_to_BN(params->fieldID->parameters->value.integer, NULL)) == NULL)
-                       OPENSSL_ECDSA_ABORT(ERR_R_ASN1_LIB)
-               if (!params->curve)
-                       OPENSSL_ECDSA_ABORT(ECDSA_R_NO_CURVE_SPECIFIED)
-               if (!params->curve->a || !params->curve->a->data)
-                       OPENSSL_ECDSA_ABORT(ECDSA_R_NO_CURVE_PARAMETER_A_SPECIFIED)
-               if ((tmp_2 = BN_bin2bn(params->curve->a->data, params->curve->a->length, NULL)) == NULL)
-                       OPENSSL_ECDSA_ABORT(ERR_R_BN_LIB)
-               if (!params->curve->b || !params->curve->b->data)
-                       OPENSSL_ECDSA_ABORT(ECDSA_R_NO_CURVE_PARAMETER_B_SPECIFIED)
-               if ((tmp_3 = BN_bin2bn(params->curve->b->data, params->curve->b->length, NULL)) == NULL)
-                       OPENSSL_ECDSA_ABORT(ERR_R_BN_LIB)
-               if (!EC_GROUP_set_curve_GFp(ret->group, tmp_1, tmp_2, tmp_3, NULL)) goto err;
-               if ((point = EC_POINT_new(ret->group)) == NULL) goto err;
-       }
-       else OPENSSL_ECDSA_ABORT(ECDSA_R_WRONG_FIELD_IDENTIFIER)
-       if (params->curve->seed != NULL)
-       {
-               if (ret->seed != NULL)
-                       OPENSSL_free(ret->seed);
-               if ((ret->seed = OPENSSL_malloc(params->curve->seed->length)) == NULL)
-                       OPENSSL_ECDSA_ABORT(ERR_R_MALLOC_FAILURE)
-               memcpy(ret->seed, params->curve->seed->data, params->curve->seed->length);
-               ret->seed_len = params->curve->seed->length;
-       }
-       if (params->version)
-       {
-               if ((ret->version = (int)ASN1_INTEGER_get(params->version)) < 0)
-                       OPENSSL_ECDSA_ABORT(ECDSA_R_UNEXPECTED_VERSION_NUMER)
-       }
        else
-               ret->version  = 1;
-       if (params->order && params->cofactor && params->base && params->base->data)
-       {
-               if ((tmp_1 = ASN1_INTEGER_to_BN(params->order, tmp_1)) == NULL)
-                       OPENSSL_ECDSA_ABORT(ERR_R_ASN1_LIB)
-               if ((tmp_2 = ASN1_INTEGER_to_BN(params->cofactor, tmp_2)) == NULL)
-                       OPENSSL_ECDSA_ABORT(ERR_R_ASN1_LIB)
-               if (!EC_POINT_oct2point(ret->group, point, params->base->data, 
-                               params->base->length, NULL)) goto err;
-               if (!EC_GROUP_set_generator(ret->group, point, tmp_1, tmp_2)) goto err;
-       }
-       ok = 1;
+               ret = *a;
 
-err:   if (!ok)
-       {
-               ECDSAerr(ECDSA_F_ECDSA_GET, reason);
-               if (ret && !ecdsa) ECDSA_free(ret);
-               ret = NULL;
-       }
-       if (tmp_1)      BN_free(tmp_1);
-       if (tmp_2)      BN_free(tmp_2);
-       if (tmp_3)      BN_free(tmp_3);
-       if (point)      EC_POINT_free(point);
-       return(ret);
-}
+       if (ret->group)
+               EC_GROUP_clear_free(ret->group);
 
-ECDSA *ECDSA_ecparameters2ecdsa(const EC_PARAMETERS *params, ECDSA *ecdsa)
-{
-       ECDSA *ret = ecdsa;
-       int tmp = 0;
-       if (ret == NULL)
-               if ((ret = ECDSA_new()) == NULL)
+       ret->group = EC_ASN1_pkparameters2group(priv_key->parameters);
+       if (ret->group == NULL)
                {
-                       ECDSAerr(ECDSA_F_ECDSA_GET_ECDSA, ERR_R_MALLOC_FAILURE);
-                       return NULL;
-               }
-       if (params == NULL)
-       {
-               ECDSAerr(ECDSA_F_ECDSA_GET_ECDSA, ECDSA_R_MISSING_PARAMETERS);
-               ECDSA_free(ret);
-               return NULL;
-       }
-       if (params->type == 0)
-       {
-               if (ret->group)
-                       EC_GROUP_free(ret->group);
-               tmp = OBJ_obj2nid(params->value.named_curve);
-               ret->parameter_flags |= ECDSA_FLAG_NAMED_CURVE;
-               if ((ret->group = EC_GROUP_new_by_name(tmp)) == NULL)
-               {
-                       ECDSAerr(ECDSA_F_ECDSA_GET_ECDSA, ECDSA_R_EC_GROUP_NID2CURVE_FAILURE);
-                       ECDSA_free(ret);
-                       return NULL;
+               ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ERR_R_EC_LIB);
+               goto err;
                }
-       }
-       else if (params->type == 1)
-       {
-               ret = ECDSA_x9_62parameters2ecdsa(params->value.parameters, ret);
-       }
-       else if (params->type == 2)
-       {
-               if (ret->group)
-                       EC_GROUP_free(ret->group);
-               ret->group = NULL;
-               ret->parameter_flags |= ECDSA_FLAG_IMPLICITLYCA;                
-       }
-       else
-       {
-               ECDSAerr(ECDSA_F_ECDSA_GET_ECDSA, ECDSA_R_UNKNOWN_PARAMETERS_TYPE);
-               ECDSA_free(ret);
-               ret = NULL;
-       }
-       return ret;
-}
-
-ECDSA  *d2i_ECDSAParameters(ECDSA **a, const unsigned char **in, long len)
-{
-       ECDSA           *ecdsa = (a && *a)? *a : NULL;
-       EC_PARAMETERS   *params = NULL;
 
-       if ((params = d2i_EC_PARAMETERS(NULL, in, len)) == NULL)
-       {
-               ECDSAerr(ECDSA_F_D2I_ECDSAPARAMETERS, ECDSA_R_D2I_EC_PARAMETERS_FAILURE);
-               EC_PARAMETERS_free(params);
-               return NULL;
-       }
-       if ((ecdsa = ECDSA_ecparameters2ecdsa(params, ecdsa)) == NULL)
-       {
-               ECDSAerr(ECDSA_F_D2I_ECDSAPARAMETERS, ECDSA_R_ECPARAMETERS2ECDSA_FAILURE);
-               return NULL; 
-       }
-       EC_PARAMETERS_free(params);
-       return(ecdsa);  
-}
-
-int    i2d_ECDSAParameters(ECDSA *a, unsigned char **out)
-{
-       int             ret=0;
-       EC_PARAMETERS   *tmp = ECDSA_get_EC_PARAMETERS(a, NULL);
-       if (tmp == NULL)
-       {
-               ECDSAerr(ECDSA_F_I2D_ECDSAPARAMETERS, ECDSA_R_ECDSA_GET_EC_PARAMETERS_FAILURE);
-               return 0;
-       }
-       if ((ret = i2d_EC_PARAMETERS(tmp, out)) == 0)
-       {
-               ECDSAerr(ECDSA_F_I2D_ECDSAPARAMETERS, ECDSA_R_ECDSA_R_D2I_EC_PARAMETERS_FAILURE);
-               EC_PARAMETERS_free(tmp);
-               return 0;
-       }       
-       EC_PARAMETERS_free(tmp);
-       return(ret);
-}
-
-ECDSA  *d2i_ECDSAPrivateKey(ECDSA **a, const unsigned char **in, long len)
-{
-       int reason=ERR_R_BN_LIB, ok=0;
-       ECDSA *ret=NULL;
-       ECDSAPrivateKey *priv_key=NULL;
-
-       if ((priv_key = ECDSAPrivateKey_new()) == NULL)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_ECDSAPRIVATEKEY_NEW_FAILURE)
-       if ((priv_key = d2i_ecdsaPrivateKey(&priv_key, in, len)) == NULL)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_D2I_ECDSA_PRIVATEKEY_FAILURE)
-       if ((ret = ECDSA_ecparameters2ecdsa(priv_key->parameters, NULL)) == NULL)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_ECDSA_GET_FAILURE)
        ret->version = priv_key->version;
        if (priv_key->priv_key)
-       {
+               {
                if ((ret->priv_key = BN_dup(priv_key->priv_key)) == NULL)
-                       OPENSSL_ECDSA_ABORT(ERR_R_BN_LIB)
-       }
+                       {
+                       ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY,
+                                 ERR_R_BN_LIB);
+                       goto err;
+                       }
+               }
        else
-               OPENSSL_ECDSA_ABORT(ECDSA_R_D2I_ECDSAPRIVATEKEY_MISSING_PRIVATE_KEY)
+               {
+               ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, 
+                         ECDSA_R_MISSING_PRIVATE_KEY);
+               goto err;
+               }
+
        if ((ret->pub_key = EC_POINT_new(ret->group)) == NULL)
-               OPENSSL_ECDSA_ABORT(ERR_R_EC_LIB)
-       if (!EC_POINT_oct2point(ret->group, ret->pub_key, priv_key->pub_key->data, priv_key->pub_key->length, NULL))
-               OPENSSL_ECDSA_ABORT(ERR_R_EC_LIB)
+               {
+               ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ERR_R_EC_LIB);
+               goto err;
+               }
+
+       if (!EC_POINT_oct2point(ret->group, ret->pub_key, 
+                priv_key->pub_key->data, priv_key->pub_key->length, NULL))
+               {
+               ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, ERR_R_EC_LIB);
+               goto err;
+               }
+
        ok = 1;
+
 err :  if (!ok)
        {
                if (ret) ECDSA_free(ret);
                ret = NULL;
-               ECDSAerr(ECDSA_F_D2I_ECDSAPRIVATEKEY, reason);
        }
-       if (priv_key)   ECDSAPrivateKey_free(priv_key);
+       if (priv_key)
+               ECDSAPrivateKey_free(priv_key);
        return(ret);
 }
 
 int    i2d_ECDSAPrivateKey(ECDSA *a, unsigned char **out)
 {
-       int ret=0, ok=0, reason=ERR_R_EC_LIB;
+       int ret=0, ok=0;
        unsigned char   *buffer=NULL;
        size_t          buf_len=0;
        ECDSAPrivateKey *priv_key=NULL;
 
        if (a == NULL || a->group == NULL)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_MISSING_PARAMETERS)
+               {
+               ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY,
+                         ERR_R_PASSED_NULL_PARAMETER);
+               goto err;
+               }
+
        if ((priv_key = ECDSAPrivateKey_new()) == NULL)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_ECDSAPRIVATEKEY_NEW_FAILURE)
-       if ((priv_key->parameters = ECDSA_get_EC_PARAMETERS(a, priv_key->parameters)) == NULL)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_ECDSA_GET_X9_62_EC_PARAMETERS_FAILURE)
+               {
+               ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY,
+                         ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+
+       if ((priv_key->parameters = EC_ASN1_group2pkparameters(a->group, 
+                                    priv_key->parameters)) == NULL)
+               {
+               ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, ERR_R_EC_LIB);
+               goto err;
+               }
+
        priv_key->version      = a->version;
+
        if (BN_copy(priv_key->priv_key, a->priv_key) == NULL)
-               OPENSSL_ECDSA_ABORT(ERR_R_BN_LIB)
-       buf_len = EC_POINT_point2oct(a->group, a->pub_key, POINT_CONVERSION_COMPRESSED, NULL, 0, NULL);
+               {
+               ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, ERR_R_BN_LIB);
+               goto err;
+               }
+
+       buf_len = EC_POINT_point2oct(a->group, a->pub_key, 
+                           ECDSA_get_conversion_form(a), NULL, 0, NULL);
        if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
-               OPENSSL_ECDSA_ABORT(ERR_R_MALLOC_FAILURE)
-       if (!EC_POINT_point2oct(a->group, a->pub_key, POINT_CONVERSION_COMPRESSED,
-                               buffer, buf_len, NULL)) goto err;
+               {
+               ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, ERR_R_MALLOC_FAILURE);
+               goto err;
+               }
+       if (!EC_POINT_point2oct(a->group, a->pub_key, 
+                       ECDSA_get_conversion_form(a), buffer, buf_len, NULL))
+               {
+               ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, ERR_R_EC_LIB);
+               goto err;
+               }
        if (!M_ASN1_OCTET_STRING_set(priv_key->pub_key, buffer, buf_len))
-               OPENSSL_ECDSA_ABORT(ERR_R_ASN1_LIB)
+               {
+               ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, ERR_R_ASN1_LIB);
+               goto err;
+               }
        if ((ret = i2d_ecdsaPrivateKey(priv_key, out)) == 0)
-               OPENSSL_ECDSA_ABORT(ECDSA_R_I2D_ECDSA_PRIVATEKEY)
+               {
+               ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, 
+                         ECDSA_R_I2D_ECDSA_PRIVATEKEY);
+               goto err;
+               }
        ok=1;
        
-err:   if (!ok)
-               ECDSAerr(ECDSA_F_I2D_ECDSAPRIVATEKEY, reason);
-       if (buffer)   OPENSSL_free(buffer);
-       if (priv_key) ECDSAPrivateKey_free(priv_key);   
+err:
+       if (buffer)
+               OPENSSL_free(buffer);
+       if (priv_key)
+               ECDSAPrivateKey_free(priv_key); 
        return(ok?ret:0);
 }
 
@@ -655,7 +333,8 @@ int         ECDSAPublicKey_get_octet_string(ECDSA *a, unsigned char **out)
                ECDSAerr(ECDSA_F_I2D_ECDSAPUBLICKEY, ECDSA_R_MISSING_PARAMETERS);
                return 0;
        }
-        buf_len = EC_POINT_point2oct(a->group, a->pub_key, ECDSA_get_conversion_form(a), NULL, 0, NULL);
+        buf_len = EC_POINT_point2oct(a->group, a->pub_key, 
+                              ECDSA_get_conversion_form(a), NULL, 0, NULL);
        if (out == NULL || buf_len == 0)
        /* out == NULL => just return the length of the octet string */
                return buf_len;
index f788dc9..b8a9edd 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/ecdsa/ecs_err.c */
 /* ====================================================================
- * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-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
@@ -76,19 +76,19 @@ static ERR_STRING_DATA ECDSA_str_functs[]=
 {ERR_PACK(0,ECDSA_F_ECDSA_GET,0),      "ECDSA_GET"},
 {ERR_PACK(0,ECDSA_F_ECDSA_GET_CURVE_NID,0),    "ECDSA_GET_CURVE_NID"},
 {ERR_PACK(0,ECDSA_F_ECDSA_GET_ECDSA,0),        "ECDSA_GET_ECDSA"},
-{ERR_PACK(0,ECDSA_F_ECDSA_GET_EC_PARAMETERS,0),        "ECDSA_get_EC_PARAMETERS"},
-{ERR_PACK(0,ECDSA_F_ECDSA_GET_X9_62_CURVE,0),  "ECDSA_get_X9_62_CURVE"},
-{ERR_PACK(0,ECDSA_F_ECDSA_GET_X9_62_EC_PARAMETERS,0),  "ECDSA_get_X9_62_EC_PARAMETERS"},
-{ERR_PACK(0,ECDSA_F_ECDSA_GET_X9_62_FIELDID,0),        "ECDSA_get_X9_62_FIELDID"},
-{ERR_PACK(0,ECDSA_F_ECDSA_NEW,0),      "ECDSA_NEW"},
+{ERR_PACK(0,ECDSA_F_ECDSA_GET_EC_PARAMETERS,0),        "ECDSA_GET_EC_PARAMETERS"},
+{ERR_PACK(0,ECDSA_F_ECDSA_GET_X9_62_CURVE,0),  "ECDSA_GET_X9_62_CURVE"},
+{ERR_PACK(0,ECDSA_F_ECDSA_GET_X9_62_EC_PARAMETERS,0),  "ECDSA_GET_X9_62_EC_PARAMETERS"},
+{ERR_PACK(0,ECDSA_F_ECDSA_GET_X9_62_FIELDID,0),        "ECDSA_GET_X9_62_FIELDID"},
+{ERR_PACK(0,ECDSA_F_ECDSA_NEW,0),      "ECDSA_new"},
 {ERR_PACK(0,ECDSA_F_ECDSA_PRINT,0),    "ECDSA_print"},
 {ERR_PACK(0,ECDSA_F_ECDSA_PRINT_FP,0), "ECDSA_print_fp"},
-{ERR_PACK(0,ECDSA_F_ECDSA_SET_GROUP_P,0),      "ECDSA_set_group_p"},
+{ERR_PACK(0,ECDSA_F_ECDSA_SET_GROUP_P,0),      "ECDSA_SET_GROUP_P"},
 {ERR_PACK(0,ECDSA_F_ECDSA_SET_PRIME_GROUP,0),  "ECDSA_SET_PRIME_GROUP"},
 {ERR_PACK(0,ECDSA_F_ECDSA_SIGN_SETUP,0),       "ECDSA_sign_setup"},
 {ERR_PACK(0,ECDSA_F_I2D_ECDSAPARAMETERS,0),    "i2d_ECDSAParameters"},
 {ERR_PACK(0,ECDSA_F_I2D_ECDSAPRIVATEKEY,0),    "i2d_ECDSAPrivateKey"},
-{ERR_PACK(0,ECDSA_F_I2D_ECDSAPUBLICKEY,0),     "i2d_ECDSAPublicKey"},
+{ERR_PACK(0,ECDSA_F_I2D_ECDSAPUBLICKEY,0),     "I2D_ECDSAPUBLICKEY"},
 {ERR_PACK(0,ECDSA_F_SIG_CB,0), "SIG_CB"},
 {0,NULL}
        };
@@ -118,6 +118,7 @@ static ERR_STRING_DATA ECDSA_str_reasons[]=
 {ECDSA_R_I2D_ECDSA_PRIVATEKEY            ,"i2d ecdsa privatekey"},
 {ECDSA_R_I2D_ECDSA_PUBLICKEY             ,"i2d ecdsa publickey"},
 {ECDSA_R_MISSING_PARAMETERS              ,"missing parameters"},
+{ECDSA_R_MISSING_PRIVATE_KEY             ,"missing private key"},
 {ECDSA_R_NOT_SUPPORTED                   ,"not supported"},
 {ECDSA_R_NO_CURVE_PARAMETER_A_SPECIFIED  ,"no curve parameter a specified"},
 {ECDSA_R_NO_CURVE_PARAMETER_B_SPECIFIED  ,"no curve parameter b specified"},
index 7063d8a..3e60bab 100644 (file)
  */
 
 #include "cryptlib.h"
-#include "ecs_locl.h"
+#include "ecdsa.h"
 #include <openssl/engine.h>
 
 const char *ECDSA_version="ECDSA" OPENSSL_VERSION_PTEXT;
@@ -186,11 +186,6 @@ ECDSA *ECDSA_new_method(ENGINE *engine)
        ret->kinv = NULL;
        ret->r = NULL;
 
-       ret->seed = NULL;
-       ret->seed_len = 0;
-
-       ret->parameter_flags = 0;
-
        ret->references = 1;
        ret->flags = ret->meth->flags;
        CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ECDSA, ret, &ret->ex_data);
@@ -235,7 +230,6 @@ void ECDSA_free(ECDSA *r)
        if (r->priv_key != NULL) BN_clear_free(r->priv_key);
        if (r->kinv != NULL) BN_clear_free(r->kinv);
        if (r->r    != NULL) BN_clear_free(r->r);
-       if (r->seed != NULL) OPENSSL_free(r->seed);
        OPENSSL_free(r);
 }
 
@@ -301,16 +295,6 @@ int ECDSA_up_ref(ECDSA *ecdsa)
         return ((i > 1) ? 1 : 0);
 }
         
-void ECDSA_set_parameter_flags(ECDSA *ecdsa, int flag)
-{
-       ecdsa->parameter_flags = flag;
-}
-
-int ECDSA_get_parameter_flags(const ECDSA *ecdsa)
-{
-       return ecdsa->parameter_flags;
-}
-
 void   ECDSA_set_conversion_form(ECDSA *ecdsa, const point_conversion_form_t form)
 {
        if (ecdsa) ecdsa->conversion_form = form;
diff --git a/crypto/ecdsa/ecs_locl.h b/crypto/ecdsa/ecs_locl.h
deleted file mode 100644 (file)
index 3c35304..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/* crypto/ecdsa/ecs_locl.h */
-/* ====================================================================
- * 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
- *    licensing@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 "ecdsa.h"
-
-#ifndef HEADER_ECS_LOCL_H
-#define HEADER_ECS_LOCL_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define OPENSSL_ECDSA_ABORT(r) { reason = (r); goto err; }
-
-/* some structures needed for the asn1 encoding */
-typedef struct x9_62_fieldid_st {
-        ASN1_OBJECT *fieldType;
-        ASN1_TYPE   *parameters;
-        } X9_62_FIELDID;
-
-typedef struct x9_62_curve_st {
-        ASN1_OCTET_STRING *a;
-        ASN1_OCTET_STRING *b;
-        ASN1_BIT_STRING   *seed;
-        } X9_62_CURVE;
-
-typedef struct x9_62_ec_parameters {
-        ASN1_INTEGER      *version;
-        X9_62_FIELDID     *fieldID;
-        X9_62_CURVE       *curve;
-        ASN1_OCTET_STRING *base;
-        ASN1_INTEGER      *order;
-        ASN1_INTEGER      *cofactor;
-        } X9_62_EC_PARAMETERS;
-
-typedef struct ec_parameters {
-       int     type;
-       union {
-               ASN1_OBJECT         *named_curve;
-               X9_62_EC_PARAMETERS *parameters;
-               ASN1_NULL           *implicitlyCA;
-       } value;
-       } EC_PARAMETERS;
-
-typedef struct ecdsa_priv_key_st {
-        int               version;
-        EC_PARAMETERS    *parameters;
-       ASN1_OBJECT       *named_curve;
-        ASN1_OCTET_STRING *pub_key;
-        BIGNUM            *priv_key;
-        } ECDSAPrivateKey;
-
-
-X9_62_FIELDID *ECDSA_get_X9_62_FIELDID(const ECDSA *ecdsa, X9_62_FIELDID *field);
-X9_62_CURVE   *ECDSA_get_X9_62_CURVE(const ECDSA *ecdsa, X9_62_CURVE *curve);
-X9_62_EC_PARAMETERS *ECDSA_get_X9_62_EC_PARAMETERS(const ECDSA *ecdsa, X9_62_EC_PARAMETERS *params);
-EC_PARAMETERS *ECDSA_get_EC_PARAMETERS(const ECDSA *ecdsa, EC_PARAMETERS *params);
-
-ECDSA  *ECDSA_x9_62parameters2ecdsa(const X9_62_EC_PARAMETERS *params, ECDSA *ecdsa);
-ECDSA  *ECDSA_ecparameters2ecdsa(const EC_PARAMETERS *params, ECDSA *ecdsa);
-
-#ifdef  __cplusplus
-}
-#endif
-#endif
index 407943b..dfcd3a8 100755 (executable)
@@ -2830,13 +2830,13 @@ EVP_PKEY_set1_ECDSA                     3272    EXIST::FUNCTION:ECDSA
 EC_GROUP_get_nid                        3273   EXIST::FUNCTION:EC
 d2i_ECDSA_PUBKEY_fp                     3274   EXIST::FUNCTION:ECDSA,FP_API
 ECDSA_OpenSSL                           3275   EXIST::FUNCTION:ECDSA
-ECDSA_get_parameter_flags               3276   EXIST::FUNCTION:ECDSA
+ECDSA_get_parameter_flags               3276   NOEXIST::FUNCTION:
 PEM_read_ECDSAParameters                3277   EXIST:!WIN16:FUNCTION:ECDSA
 ECDSA_get_ex_data                       3278   EXIST::FUNCTION:ECDSA
 ECDSA_do_verify                         3279   EXIST::FUNCTION:ECDSA
 ECDSA_do_sign                           3280   EXIST::FUNCTION:ECDSA
 EC_POINT_point2bn                       3281   EXIST::FUNCTION:EC
-ECDSA_set_parameter_flags               3282   EXIST::FUNCTION:ECDSA
+ECDSA_set_parameter_flags               3282   NOEXIST::FUNCTION:
 i2d_ECDSA_SIG                           3283   EXIST::FUNCTION:ECDSA
 PEM_read_bio_ECDSAParameters            3284   EXIST::FUNCTION:ECDSA
 ECDSAPublicKey_get_octet_string         3285   EXIST::FUNCTION:ECDSA
@@ -2862,3 +2862,20 @@ PEM_write_ECDSAParameters               3304     EXIST:!WIN16:FUNCTION:ECDSA
 i2d_ECDSAPrivateKey_fp                  3305   EXIST::FUNCTION:ECDSA,FP_API
 PEM_read_ECDSAPrivateKey                3306   EXIST:!WIN16:FUNCTION:ECDSA
 ECDSAPublicKey_set_octet_string         3307   EXIST::FUNCTION:ECDSA
+EC_GROUP_get_asn1_flag                  3308   EXIST::FUNCTION:EC
+EC_ASN1_group2pkparameters              3309   EXIST::FUNCTION:EC
+d2i_ECPARAMETERS                        3310   EXIST::FUNCTION:EC
+i2d_ECPARAMETERS                        3311   EXIST::FUNCTION:EC
+d2i_ECPKPARAMETERS                      3312   EXIST::FUNCTION:EC
+EC_GROUP_set_asn1_flag                  3313   EXIST::FUNCTION:EC
+ECPKPARAMETERS_it                       3314   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:EC
+ECPKPARAMETERS_it                       3314   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:EC
+d2i_ECParameters                        3315   EXIST::FUNCTION:EC
+EC_METHOD_get_field_type                3316   EXIST::FUNCTION:EC
+i2d_ECPKPARAMETERS                      3317   EXIST::FUNCTION:EC
+i2d_ECParameters                        3318   EXIST::FUNCTION:EC
+d2i_ECPKParameters                      3319   EXIST::FUNCTION:EC
+ECPARAMETERS_it                         3320   EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:EC
+ECPARAMETERS_it                         3320   EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:EC
+EC_ASN1_pkparameters2group              3321   EXIST::FUNCTION:EC
+i2d_ECPKParameters                      3322   EXIST::FUNCTION:EC