add cofactor ECDH support from fips branch
authorDr. Stephen Henson <steve@openssl.org>
Sat, 10 Dec 2011 13:35:11 +0000 (13:35 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sat, 10 Dec 2011 13:35:11 +0000 (13:35 +0000)
crypto/ecdh/ecdh.h
crypto/ecdh/ech_ossl.c

index b4b58ee65ba2caee7a968e7a8d7070ea9d94ea01..8ac82b8cbdb6d86b8d8b18bfbfcd9b36fe250a69 100644 (file)
@@ -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 *);
index 94a8f4b696a5fcb97c3cd08ab4c471d8dc696210..2656797449e7075cd910bd69deaf4c6c8012b3f5 100644 (file)
@@ -146,6 +146,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);