diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2011-12-10 13:35:11 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2013-10-01 14:01:18 +0100 |
commit | 3e792793f6bd74e3a753c1b104417ba2b162f4f5 (patch) | |
tree | d21e0c9409b51fa38aa07bbc9caf272e02b2a3d7 /crypto/ecdh | |
parent | ac5cb33356962409acf8ddf334831cf5de6cc2aa (diff) |
add cofactor ECDH support from fips branch
(cherry picked from commit a3a2e3a43d13d8486c5e100e1bef7fec8e61b27b)
Diffstat (limited to 'crypto/ecdh')
-rw-r--r-- | crypto/ecdh/ecdh.h | 2 | ||||
-rw-r--r-- | crypto/ecdh/ech_ossl.c | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/crypto/ecdh/ecdh.h b/crypto/ecdh/ecdh.h index 98c6cdf9be..6d792180d6 100644 --- a/crypto/ecdh/ecdh.h +++ b/crypto/ecdh/ecdh.h @@ -85,6 +85,8 @@ extern "C" { #endif +#define EC_FLAG_COFACTOR_ECDH 0x1000 + const ECDH_METHOD *ECDH_OpenSSL(void); void ECDH_set_default_method(const ECDH_METHOD *); diff --git a/crypto/ecdh/ech_ossl.c b/crypto/ecdh/ech_ossl.c index 4a30628fbc..fa98eb11ce 100644 --- a/crypto/ecdh/ech_ossl.c +++ b/crypto/ecdh/ech_ossl.c @@ -137,6 +137,18 @@ static int ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, } group = EC_KEY_get0_group(ecdh); + + if (EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) + { + if (!EC_GROUP_get_cofactor(group, x, ctx) || + !BN_mul(x, x, priv_key, ctx)) + { + ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); + goto err; + } + priv_key = x; + } + if ((tmp=EC_POINT_new(group)) == NULL) { ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); |