提交 62e3163b 编写于 作者: B Bodo Möller

ECPublicKey_set_octet_string and ECPublicKey_get_octet_string

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
上级 8214e74f
...@@ -113,9 +113,8 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp, ...@@ -113,9 +113,8 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
#endif #endif
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
case EVP_PKEY_EC: case EVP_PKEY_EC:
if ((ret->pkey.eckey = ECPublicKey_set_octet_string( if ((ret->pkey.eckey = o2i_ECPublicKey(&(ret->pkey.eckey),
&(ret->pkey.eckey), (const unsigned char **)pp, (const unsigned char **)pp, length)) == NULL)
length)) == NULL)
{ {
ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB);
goto err; goto err;
......
...@@ -85,7 +85,7 @@ int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) ...@@ -85,7 +85,7 @@ int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
#endif #endif
#ifndef OPENSSL_NO_EC #ifndef OPENSSL_NO_EC
case EVP_PKEY_EC: case EVP_PKEY_EC:
return(ECPublicKey_get_octet_string(a->pkey.eckey, pp)); return(i2o_ECPublicKey(a->pkey.eckey, pp));
#endif #endif
default: default:
ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
......
...@@ -319,16 +319,16 @@ int EC_KEY_generate_key(EC_KEY *); ...@@ -319,16 +319,16 @@ int EC_KEY_generate_key(EC_KEY *);
/* EC_KEY_check_key() */ /* EC_KEY_check_key() */
int EC_KEY_check_key(const EC_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); EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len);
int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out); 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); EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len);
int i2d_ECParameters(EC_KEY *a, unsigned char **out); int i2d_ECParameters(EC_KEY *a, unsigned char **out);
/* de- and encoding functions for EC public key
EC_KEY *ECPublicKey_set_octet_string(EC_KEY **a, const unsigned char **in, * (octet string, not DER -- hence 'o2i' and 'i2o') */
long len); EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len);
int ECPublicKey_get_octet_string(EC_KEY *a, unsigned char **out); int i2o_ECPublicKey(EC_KEY *a, unsigned char **out);
#ifndef OPENSSL_NO_BIO #ifndef OPENSSL_NO_BIO
int ECParameters_print(BIO *bp, const EC_KEY *x); int ECParameters_print(BIO *bp, const EC_KEY *x);
...@@ -359,8 +359,6 @@ void ERR_load_EC_strings(void); ...@@ -359,8 +359,6 @@ void ERR_load_EC_strings(void);
#define EC_F_ECPARAMETERS_PRINT_FP 148 #define EC_F_ECPARAMETERS_PRINT_FP 148
#define EC_F_ECPKPARAMETERS_PRINT 149 #define EC_F_ECPKPARAMETERS_PRINT 149
#define EC_F_ECPKPARAMETERS_PRINT_FP 150 #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_192 203
#define EC_F_ECP_NIST_MOD_224 204 #define EC_F_ECP_NIST_MOD_224 204
#define EC_F_ECP_NIST_MOD_256 205 #define EC_F_ECP_NIST_MOD_256 205
...@@ -455,6 +453,8 @@ void ERR_load_EC_strings(void); ...@@ -455,6 +453,8 @@ void ERR_load_EC_strings(void);
#define EC_F_I2D_ECPARAMETERS 190 #define EC_F_I2D_ECPARAMETERS 190
#define EC_F_I2D_ECPKPARAMETERS 191 #define EC_F_I2D_ECPKPARAMETERS 191
#define EC_F_I2D_ECPRIVATEKEY 192 #define EC_F_I2D_ECPRIVATEKEY 192
#define EC_F_I2O_ECPUBLICKEY 151
#define EC_F_O2I_ECPUBLICKEY 152
/* Reason codes. */ /* Reason codes. */
#define EC_R_ASN1_ERROR 115 #define EC_R_ASN1_ERROR 115
......
...@@ -1406,8 +1406,7 @@ EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len) ...@@ -1406,8 +1406,7 @@ EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len)
return ret; return ret;
} }
EC_KEY *ECPublicKey_set_octet_string(EC_KEY **a, const unsigned char **in, EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len)
long len)
{ {
EC_KEY *ret=NULL; EC_KEY *ret=NULL;
...@@ -1415,33 +1414,34 @@ EC_KEY *ECPublicKey_set_octet_string(EC_KEY **a, const unsigned char **in, ...@@ -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 /* sorry, but a EC_GROUP-structur is necessary
* to set the public key */ * 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; return 0;
} }
ret = *a; ret = *a;
if (ret->pub_key == NULL && if (ret->pub_key == NULL &&
(ret->pub_key = EC_POINT_new(ret->group)) == 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; return 0;
} }
if (!EC_POINT_oct2point(ret->group, ret->pub_key, *in, len, NULL)) 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; return 0;
} }
/* save the point conversion form */ /* save the point conversion form */
ret->conv_form = (point_conversion_form_t)(*in[0] & ~0x01); ret->conv_form = (point_conversion_form_t)(*in[0] & ~0x01);
*in += len;
return ret; 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; size_t buf_len=0;
if (a == NULL) 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; return 0;
} }
...@@ -1455,17 +1455,17 @@ int ECPublicKey_get_octet_string(EC_KEY *a, unsigned char **out) ...@@ -1455,17 +1455,17 @@ int ECPublicKey_get_octet_string(EC_KEY *a, unsigned char **out)
if (*out == NULL) if (*out == NULL)
if ((*out = OPENSSL_malloc(buf_len)) == NULL) if ((*out = OPENSSL_malloc(buf_len)) == NULL)
{ {
ECerr(EC_F_ECPUBLICKEY_GET_OCTET, ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_MALLOC_FAILURE);
ERR_R_MALLOC_FAILURE);
return 0; return 0;
} }
if (!EC_POINT_point2oct(a->group, a->pub_key, a->conv_form, if (!EC_POINT_point2oct(a->group, a->pub_key, a->conv_form,
*out, buf_len, NULL)) *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); OPENSSL_free(*out);
*out = NULL; *out = NULL;
return 0; return 0;
} }
*out += buf_len;
return buf_len; return buf_len;
} }
...@@ -74,8 +74,6 @@ static ERR_STRING_DATA EC_str_functs[]= ...@@ -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_ECPARAMETERS_PRINT_FP,0), "ECParameters_print_fp"},
{ERR_PACK(0,EC_F_ECPKPARAMETERS_PRINT,0), "ECPKParameters_print"}, {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_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_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_224,0), "ECP_NIST_MOD_224"},
{ERR_PACK(0,EC_F_ECP_NIST_MOD_256,0), "ECP_NIST_MOD_256"}, {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[]= ...@@ -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_ECPARAMETERS,0), "i2d_ECParameters"},
{ERR_PACK(0,EC_F_I2D_ECPKPARAMETERS,0), "i2d_ECPKParameters"}, {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_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} {0,NULL}
}; };
......
...@@ -2871,7 +2871,7 @@ BN_GF2m_mod_mul 3309 EXIST::FUNCTION: ...@@ -2871,7 +2871,7 @@ BN_GF2m_mod_mul 3309 EXIST::FUNCTION:
EC_GROUP_set_seed 3310 EXIST::FUNCTION:EC EC_GROUP_set_seed 3310 EXIST::FUNCTION:EC
EC_GROUP_get_curve_GF2m 3311 EXIST::FUNCTION:EC EC_GROUP_get_curve_GF2m 3311 EXIST::FUNCTION:EC
PEM_read_X509_CERT_PAIR 3312 EXIST:!WIN16:FUNCTION: 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 ECDSA_get_ex_data 3314 EXIST::FUNCTION:ECDSA
BN_GF2m_mod 3315 EXIST::FUNCTION: BN_GF2m_mod 3315 EXIST::FUNCTION:
EC_GROUP_get_seed_len 3316 EXIST::FUNCTION:EC EC_GROUP_get_seed_len 3316 EXIST::FUNCTION:EC
...@@ -2891,7 +2891,7 @@ BN_GF2m_mod_sqrt 3328 EXIST::FUNCTION: ...@@ -2891,7 +2891,7 @@ BN_GF2m_mod_sqrt 3328 EXIST::FUNCTION:
ECDH_set_default_method 3329 EXIST::FUNCTION:ECDH ECDH_set_default_method 3329 EXIST::FUNCTION:ECDH
EC_KEY_generate_key 3330 EXIST::FUNCTION:EC EC_KEY_generate_key 3330 EXIST::FUNCTION:EC
BN_GF2m_arr2poly 3331 EXIST::FUNCTION: 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 EC_GROUP_check 3333 EXIST::FUNCTION:EC
d2i_ECPrivateKey_bio 3334 EXIST::FUNCTION:BIO,EC d2i_ECPrivateKey_bio 3334 EXIST::FUNCTION:BIO,EC
d2i_ECPrivateKey 3335 EXIST::FUNCTION:EC d2i_ECPrivateKey 3335 EXIST::FUNCTION:EC
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册