From: Dr. Stephen Henson Date: Thu, 22 Oct 2015 17:48:59 +0000 (+0100) Subject: Add compute key support to EC_KEY_METHOD X-Git-Tag: OpenSSL_1_1_0-pre1~69 X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff_plain;h=a22a7e70899a28fff4719d458e12f8bfcd457f62 Add compute key support to EC_KEY_METHOD Reviewed-by: Richard Levitte --- diff --git a/crypto/ec/ec_kmeth.c b/crypto/ec/ec_kmeth.c index ba6db6e1df..6be99c2265 100644 --- a/crypto/ec/ec_kmeth.c +++ b/crypto/ec/ec_kmeth.c @@ -61,7 +61,8 @@ static const EC_KEY_METHOD openssl_ec_key_method = { "OpenSSL EC_KEY method", 0, - ossl_ec_key_gen + ossl_ec_key_gen, + ossl_ecdh_compute_key }; const EC_KEY_METHOD *default_ec_key_meth = &openssl_ec_key_method; @@ -119,3 +120,14 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine) ret->references = 1; return (ret); } + +int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, + EC_KEY *eckey, + void *(*KDF) (const void *in, size_t inlen, void *out, + size_t *outlen)) +{ + if (eckey->meth->compute_key) + return eckey->meth->compute_key(out, outlen, pub_key, eckey, KDF); + ECerr(EC_F_ECDH_COMPUTE_KEY, EC_R_OPERATION_NOT_SUPPORTED); + return 0; +} diff --git a/crypto/ec/ec_lcl.h b/crypto/ec/ec_lcl.h index 40612dbe95..1630b40060 100644 --- a/crypto/ec/ec_lcl.h +++ b/crypto/ec/ec_lcl.h @@ -561,8 +561,16 @@ struct ec_key_method_st { const char *name; int32_t flags; int (*keygen)(EC_KEY *key); + int (*compute_key)(void *out, size_t outlen, const EC_POINT *pub_key, + EC_KEY *ecdh, + void *(*KDF) (const void *in, size_t inlen, + void *out, size_t *outlen)); } /* EC_KEY_METHOD */ ; #define EC_KEY_METHOD_DYNAMIC 1 int ossl_ec_key_gen(EC_KEY *eckey); +int ossl_ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, + EC_KEY *ecdh, + void *(*KDF) (const void *in, size_t inlen, + void *out, size_t *outlen)); diff --git a/include/openssl/ec.h b/include/openssl/ec.h index de0e5760cb..99c945a184 100644 --- a/include/openssl/ec.h +++ b/include/openssl/ec.h @@ -749,6 +749,7 @@ typedef struct ec_key_method_st EC_KEY_METHOD; /* some values for the flags field */ # define EC_FLAG_NON_FIPS_ALLOW 0x1 # define EC_FLAG_FIPS_CHECKED 0x2 +# define EC_FLAG_COFACTOR_ECDH 0x1000 /** Creates a new EC_KEY object. * \return EC_KEY object or NULL if an error occurred. @@ -994,6 +995,10 @@ int ECDH_KDF_X9_62(unsigned char *out, size_t outlen, const unsigned char *sinfo, size_t sinfolen, const EVP_MD *md); +int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, + EC_KEY *ecdh, void *(*KDF) (const void *in, size_t inlen, + void *out, size_t *outlen)); + # define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x) # ifndef __cplusplus