ECPublicKey_set_octet_string and ECPublicKey_get_octet_string
authorBodo Möller <bodo@openssl.org>
Fri, 21 Feb 2003 13:58:23 +0000 (13:58 +0000)
committerBodo Möller <bodo@openssl.org>
Fri, 21 Feb 2003 13:58:23 +0000 (13:58 +0000)
behaviour was not quite consistent with the conventions
for d2i and i2d functions as far as handling of the 'out'
or 'in' pointer is concerned.

This patch changes this behaviour, and renames the functions to
o2i_ECPublicKey and i2o_ECPublicKey (not 'd2i' and 'i2d' because the
external encoding is just a raw object string without any DER icing).

Submitted by: Nils Larsch

crypto/asn1/d2i_pu.c
crypto/asn1/i2d_pu.c
crypto/ec/ec.h
crypto/ec/ec_asn1.c
crypto/ec/ec_err.c
util/libeay.num

index cf97b83eac4311a9179064c13d5b31cfd3d1fec3..4c2bd4e5c8a1e0cf747b10b662c114031285ac85 100644 (file)
@@ -113,9 +113,8 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
 #endif
 #ifndef OPENSSL_NO_EC
        case EVP_PKEY_EC:
-               if ((ret->pkey.eckey = ECPublicKey_set_octet_string(
-                       &(ret->pkey.eckey), (const unsigned char **)pp, 
-                       length)) == NULL)
+               if ((ret->pkey.eckey = o2i_ECPublicKey(&(ret->pkey.eckey),
+                       (const unsigned char **)pp, length)) == NULL)
                        {
                        ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB);
                        goto err;
index 85220b44d6861c4db2c05b828986060e4e36c895..44f186442e71cda969493ed545626544f18d9e7d 100644 (file)
@@ -85,7 +85,7 @@ int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
 #endif
 #ifndef OPENSSL_NO_EC
        case EVP_PKEY_EC:
-               return(ECPublicKey_get_octet_string(a->pkey.eckey, pp));
+               return(i2o_ECPublicKey(a->pkey.eckey, pp));
 #endif
        default:
                ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
index f68963e66f77ce594c278828960ea855faed78f5..1013bd8fa4e60214806a4fb6f1c1ea2c7a5d1c23 100644 (file)
@@ -319,16 +319,16 @@ int EC_KEY_generate_key(EC_KEY *);
 /* EC_KEY_check_key() */
 int EC_KEY_check_key(const EC_KEY *);
 
-/* de- and encode functions for the SEC1 ECPrivateKey */
+/* de- and encoding functions for SEC1 ECPrivateKey */
 EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len);
 int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out);
-/* de- and encode functions for the elliptic curve parameters */
+/* de- and encoding functions for EC parameters */
 EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len);
 int i2d_ECParameters(EC_KEY *a, unsigned char **out);
-
-EC_KEY *ECPublicKey_set_octet_string(EC_KEY **a, const unsigned char **in, 
-                                       long len);
-int ECPublicKey_get_octet_string(EC_KEY *a, unsigned char **out);
+/* de- and encoding functions for EC public key
+ * (octet string, not DER -- hence 'o2i' and 'i2o') */
+EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len);
+int i2o_ECPublicKey(EC_KEY *a, unsigned char **out);
 
 #ifndef OPENSSL_NO_BIO
 int    ECParameters_print(BIO *bp, const EC_KEY *x);
@@ -359,8 +359,6 @@ void ERR_load_EC_strings(void);
 #define EC_F_ECPARAMETERS_PRINT_FP                      148
 #define EC_F_ECPKPARAMETERS_PRINT                       149
 #define EC_F_ECPKPARAMETERS_PRINT_FP                    150
-#define EC_F_ECPUBLICKEY_GET_OCTET                      151
-#define EC_F_ECPUBLICKEY_SET_OCTET                      152
 #define EC_F_ECP_NIST_MOD_192                           203
 #define EC_F_ECP_NIST_MOD_224                           204
 #define EC_F_ECP_NIST_MOD_256                           205
@@ -455,6 +453,8 @@ void ERR_load_EC_strings(void);
 #define EC_F_I2D_ECPARAMETERS                           190
 #define EC_F_I2D_ECPKPARAMETERS                                 191
 #define EC_F_I2D_ECPRIVATEKEY                           192
+#define EC_F_I2O_ECPUBLICKEY                            151
+#define EC_F_O2I_ECPUBLICKEY                            152
 
 /* Reason codes. */
 #define EC_R_ASN1_ERROR                                         115
index c1c6ffee5ad589e0f05c7ab87facf22ccdbaf8ee..927a3716cff251e439e5154d96acfc3ccf9fb5bd 100644 (file)
@@ -1406,8 +1406,7 @@ EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len)
        return ret;
        }
 
-EC_KEY *ECPublicKey_set_octet_string(EC_KEY **a, const unsigned char **in, 
-                                       long len)
+EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len)
        {
        EC_KEY *ret=NULL;
 
@@ -1415,33 +1414,34 @@ EC_KEY *ECPublicKey_set_octet_string(EC_KEY **a, const unsigned char **in,
                {
                /* sorry, but a EC_GROUP-structur is necessary
                  * to set the public key */
-               ECerr(EC_F_ECPUBLICKEY_SET_OCTET, ERR_R_PASSED_NULL_PARAMETER);
+               ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER);
                return 0;
                }
        ret = *a;
        if (ret->pub_key == NULL && 
                (ret->pub_key = EC_POINT_new(ret->group)) == NULL)
                {
-               ECerr(EC_F_ECPUBLICKEY_SET_OCTET, ERR_R_MALLOC_FAILURE);
+               ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_MALLOC_FAILURE);
                return 0;
                }
        if (!EC_POINT_oct2point(ret->group, ret->pub_key, *in, len, NULL))
                {
-               ECerr(EC_F_ECPUBLICKEY_SET_OCTET, ERR_R_EC_LIB);
+               ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_EC_LIB);
                return 0;
                }
        /* save the point conversion form */
        ret->conv_form = (point_conversion_form_t)(*in[0] & ~0x01);
+       *in += len;
        return ret;
        }
 
-int ECPublicKey_get_octet_string(EC_KEY *a, unsigned char **out)
+int i2o_ECPublicKey(EC_KEY *a, unsigned char **out)
        {
         size_t  buf_len=0;
 
         if (a == NULL) 
                {
-               ECerr(EC_F_ECPUBLICKEY_GET_OCTET, ERR_R_PASSED_NULL_PARAMETER);
+               ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER);
                return 0;
                }
 
@@ -1455,17 +1455,17 @@ int ECPublicKey_get_octet_string(EC_KEY *a, unsigned char **out)
        if (*out == NULL)
                if ((*out = OPENSSL_malloc(buf_len)) == NULL)
                        {
-                       ECerr(EC_F_ECPUBLICKEY_GET_OCTET, 
-                               ERR_R_MALLOC_FAILURE);
+                       ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_MALLOC_FAILURE);
                        return 0;
                        }
         if (!EC_POINT_point2oct(a->group, a->pub_key, a->conv_form,
                                *out, buf_len, NULL))
                {
-               ECerr(EC_F_ECPUBLICKEY_GET_OCTET, ERR_R_EC_LIB);
+               ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_EC_LIB);
                OPENSSL_free(*out);
                *out = NULL;
                return 0;
                }
+       *out += buf_len;
        return buf_len;
        }
index 7730402d09788979d0afe98f8452b082d6e49d9a..d74ddace58fee3f9b8bc1c18f986d8a545142301 100644 (file)
@@ -74,8 +74,6 @@ static ERR_STRING_DATA EC_str_functs[]=
 {ERR_PACK(0,EC_F_ECPARAMETERS_PRINT_FP,0),     "ECParameters_print_fp"},
 {ERR_PACK(0,EC_F_ECPKPARAMETERS_PRINT,0),      "ECPKParameters_print"},
 {ERR_PACK(0,EC_F_ECPKPARAMETERS_PRINT_FP,0),   "ECPKParameters_print_fp"},
-{ERR_PACK(0,EC_F_ECPUBLICKEY_GET_OCTET,0),     "ECPUBLICKEY_GET_OCTET"},
-{ERR_PACK(0,EC_F_ECPUBLICKEY_SET_OCTET,0),     "ECPUBLICKEY_SET_OCTET"},
 {ERR_PACK(0,EC_F_ECP_NIST_MOD_192,0),  "ECP_NIST_MOD_192"},
 {ERR_PACK(0,EC_F_ECP_NIST_MOD_224,0),  "ECP_NIST_MOD_224"},
 {ERR_PACK(0,EC_F_ECP_NIST_MOD_256,0),  "ECP_NIST_MOD_256"},
@@ -170,6 +168,8 @@ static ERR_STRING_DATA EC_str_functs[]=
 {ERR_PACK(0,EC_F_I2D_ECPARAMETERS,0),  "i2d_ECParameters"},
 {ERR_PACK(0,EC_F_I2D_ECPKPARAMETERS,0),        "i2d_ECPKParameters"},
 {ERR_PACK(0,EC_F_I2D_ECPRIVATEKEY,0),  "i2d_ECPrivateKey"},
+{ERR_PACK(0,EC_F_I2O_ECPUBLICKEY,0),   "i2o_ECPublicKey"},
+{ERR_PACK(0,EC_F_O2I_ECPUBLICKEY,0),   "o2i_ECPublicKey"},
 {0,NULL}
        };
 
index bfddc357f137f44e5799c99e7ff4a19b8da39331..c03f58d64cafeeeaa25ea808fd9866a0b342f08f 100755 (executable)
@@ -2871,7 +2871,7 @@ BN_GF2m_mod_mul                         3309      EXIST::FUNCTION:
 EC_GROUP_set_seed                       3310   EXIST::FUNCTION:EC
 EC_GROUP_get_curve_GF2m                 3311   EXIST::FUNCTION:EC
 PEM_read_X509_CERT_PAIR                 3312   EXIST:!WIN16:FUNCTION:
-ECPublicKey_set_octet_string            3313   EXIST::FUNCTION:EC
+o2i_ECPublicKey                         3313   EXIST::FUNCTION:EC
 ECDSA_get_ex_data                       3314   EXIST::FUNCTION:ECDSA
 BN_GF2m_mod                             3315   EXIST::FUNCTION:
 EC_GROUP_get_seed_len                   3316   EXIST::FUNCTION:EC
@@ -2891,7 +2891,7 @@ BN_GF2m_mod_sqrt                        3328      EXIST::FUNCTION:
 ECDH_set_default_method                 3329   EXIST::FUNCTION:ECDH
 EC_KEY_generate_key                     3330   EXIST::FUNCTION:EC
 BN_GF2m_arr2poly                        3331   EXIST::FUNCTION:
-ECPublicKey_get_octet_string            3332   EXIST::FUNCTION:EC
+i2o_ECPublicKey                         3332   EXIST::FUNCTION:EC
 EC_GROUP_check                          3333   EXIST::FUNCTION:EC
 d2i_ECPrivateKey_bio                    3334   EXIST::FUNCTION:BIO,EC
 d2i_ECPrivateKey                        3335   EXIST::FUNCTION:EC