Blame SOURCES/openssl-1.0.2a-fips-ec.patch

e62613
diff -up openssl-1.0.2a/crypto/ecdh/ecdhtest.c.fips-ec openssl-1.0.2a/crypto/ecdh/ecdhtest.c
e62613
--- openssl-1.0.2a/crypto/ecdh/ecdhtest.c.fips-ec	2015-03-19 14:30:36.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/ecdh/ecdhtest.c	2015-04-22 19:00:19.721884512 +0200
e62613
@@ -501,11 +501,13 @@ int main(int argc, char *argv[])
e62613
         goto err;
e62613
 
e62613
     /* NIST PRIME CURVES TESTS */
e62613
+# if 0
e62613
     if (!test_ecdh_curve
e62613
         (NID_X9_62_prime192v1, "NIST Prime-Curve P-192", ctx, out))
e62613
         goto err;
e62613
     if (!test_ecdh_curve(NID_secp224r1, "NIST Prime-Curve P-224", ctx, out))
e62613
         goto err;
e62613
+# endif
e62613
     if (!test_ecdh_curve
e62613
         (NID_X9_62_prime256v1, "NIST Prime-Curve P-256", ctx, out))
e62613
         goto err;
e62613
@@ -536,13 +538,14 @@ int main(int argc, char *argv[])
e62613
     if (!test_ecdh_curve(NID_sect571r1, "NIST Binary-Curve B-571", ctx, out))
e62613
         goto err;
e62613
 # endif
e62613
+# if 0
e62613
     if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP256r1", 256))
e62613
         goto err;
e62613
     if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP384r1", 384))
e62613
         goto err;
e62613
     if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP512r1", 512))
e62613
         goto err;
e62613
-
e62613
+# endif
e62613
     ret = 0;
e62613
 
e62613
  err:
e62613
diff -up openssl-1.0.2a/crypto/ecdh/ech_lib.c.fips-ec openssl-1.0.2a/crypto/ecdh/ech_lib.c
e62613
--- openssl-1.0.2a/crypto/ecdh/ech_lib.c.fips-ec	2015-03-19 14:19:00.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/ecdh/ech_lib.c	2015-04-22 19:00:19.721884512 +0200
e62613
@@ -93,14 +93,7 @@ void ECDH_set_default_method(const ECDH_
e62613
 const ECDH_METHOD *ECDH_get_default_method(void)
e62613
 {
e62613
     if (!default_ECDH_method) {
e62613
-#ifdef OPENSSL_FIPS
e62613
-        if (FIPS_mode())
e62613
-            return FIPS_ecdh_openssl();
e62613
-        else
e62613
-            return ECDH_OpenSSL();
e62613
-#else
e62613
         default_ECDH_method = ECDH_OpenSSL();
e62613
-#endif
e62613
     }
e62613
     return default_ECDH_method;
e62613
 }
e62613
diff -up openssl-1.0.2a/crypto/ecdh/ech_ossl.c.fips-ec openssl-1.0.2a/crypto/ecdh/ech_ossl.c
e62613
--- openssl-1.0.2a/crypto/ecdh/ech_ossl.c.fips-ec	2015-03-19 14:30:36.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/ecdh/ech_ossl.c	2015-04-22 19:00:19.722884536 +0200
e62613
@@ -78,6 +78,10 @@
e62613
 #include <openssl/obj_mac.h>
e62613
 #include <openssl/bn.h>
e62613
 
e62613
+#ifdef OPENSSL_FIPS
e62613
+# include <openssl/fips.h>
e62613
+#endif
e62613
+
e62613
 static int ecdh_compute_key(void *out, size_t len, const EC_POINT *pub_key,
e62613
                             EC_KEY *ecdh,
e62613
                             void *(*KDF) (const void *in, size_t inlen,
e62613
@@ -90,7 +94,7 @@ static ECDH_METHOD openssl_ecdh_meth = {
e62613
     NULL,                       /* init */
e62613
     NULL,                       /* finish */
e62613
 #endif
e62613
-    0,                          /* flags */
e62613
+    ECDH_FLAG_FIPS_METHOD,      /* flags */
e62613
     NULL                        /* app_data */
e62613
 };
e62613
 
e62613
@@ -119,6 +123,13 @@ static int ecdh_compute_key(void *out, s
e62613
     size_t buflen, len;
e62613
     unsigned char *buf = NULL;
e62613
 
e62613
+#ifdef OPENSSL_FIPS
e62613
+    if (FIPS_selftest_failed()) {
e62613
+        FIPSerr(FIPS_F_ECDH_COMPUTE_KEY, FIPS_R_FIPS_SELFTEST_FAILED);
e62613
+        return -1;
e62613
+    }
e62613
+#endif
e62613
+
e62613
     if (outlen > INT_MAX) {
e62613
         ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); /* sort of,
e62613
                                                                  * anyway */
e62613
diff -up openssl-1.0.2a/crypto/ecdsa/ecdsatest.c.fips-ec openssl-1.0.2a/crypto/ecdsa/ecdsatest.c
e62613
--- openssl-1.0.2a/crypto/ecdsa/ecdsatest.c.fips-ec	2015-03-19 14:19:00.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/ecdsa/ecdsatest.c	2015-04-22 19:00:19.722884536 +0200
e62613
@@ -138,11 +138,14 @@ int restore_rand(void)
e62613
 }
e62613
 
e62613
 static int fbytes_counter = 0;
e62613
-static const char *numbers[8] = {
e62613
+static const char *numbers[10] = {
e62613
+    "651056770906015076056810763456358567190100156695615665659",
e62613
     "651056770906015076056810763456358567190100156695615665659",
e62613
     "6140507067065001063065065565667405560006161556565665656654",
e62613
     "8763001015071075675010661307616710783570106710677817767166"
e62613
         "71676178726717",
e62613
+    "8763001015071075675010661307616710783570106710677817767166"
e62613
+        "71676178726717",
e62613
     "7000000175690566466555057817571571075705015757757057795755"
e62613
         "55657156756655",
e62613
     "1275552191113212300012030439187146164646146646466749494799",
e62613
@@ -158,7 +161,7 @@ int fbytes(unsigned char *buf, int num)
e62613
     int ret;
e62613
     BIGNUM *tmp = NULL;
e62613
 
e62613
-    if (fbytes_counter >= 8)
e62613
+    if (fbytes_counter >= 10)
e62613
         return 0;
e62613
     tmp = BN_new();
e62613
     if (!tmp)
e62613
@@ -532,8 +535,10 @@ int main(void)
e62613
     RAND_seed(rnd_seed, sizeof(rnd_seed));
e62613
 
e62613
     /* the tests */
e62613
+# if 0
e62613
     if (!x9_62_tests(out))
e62613
         goto err;
e62613
+# endif
e62613
     if (!test_builtin(out))
e62613
         goto err;
e62613
 
e62613
diff -up openssl-1.0.2a/crypto/ecdsa/ecs_lib.c.fips-ec openssl-1.0.2a/crypto/ecdsa/ecs_lib.c
e62613
--- openssl-1.0.2a/crypto/ecdsa/ecs_lib.c.fips-ec	2015-03-19 14:30:36.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/ecdsa/ecs_lib.c	2015-04-22 19:00:19.722884536 +0200
e62613
@@ -80,14 +80,7 @@ void ECDSA_set_default_method(const ECDS
e62613
 const ECDSA_METHOD *ECDSA_get_default_method(void)
e62613
 {
e62613
     if (!default_ECDSA_method) {
e62613
-#ifdef OPENSSL_FIPS
e62613
-        if (FIPS_mode())
e62613
-            return FIPS_ecdsa_openssl();
e62613
-        else
e62613
-            return ECDSA_OpenSSL();
e62613
-#else
e62613
         default_ECDSA_method = ECDSA_OpenSSL();
e62613
-#endif
e62613
     }
e62613
     return default_ECDSA_method;
e62613
 }
e62613
diff -up openssl-1.0.2a/crypto/ecdsa/ecs_ossl.c.fips-ec openssl-1.0.2a/crypto/ecdsa/ecs_ossl.c
e62613
--- openssl-1.0.2a/crypto/ecdsa/ecs_ossl.c.fips-ec	2015-03-19 14:30:36.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/ecdsa/ecs_ossl.c	2015-04-22 19:00:19.722884536 +0200
e62613
@@ -60,6 +60,9 @@
e62613
 #include <openssl/err.h>
e62613
 #include <openssl/obj_mac.h>
e62613
 #include <openssl/bn.h>
e62613
+#ifdef OPENSSL_FIPS
e62613
+# include <openssl/fips.h>
e62613
+#endif
e62613
 
e62613
 static ECDSA_SIG *ecdsa_do_sign(const unsigned char *dgst, int dlen,
e62613
                                 const BIGNUM *, const BIGNUM *,
e62613
@@ -78,7 +81,7 @@ static ECDSA_METHOD openssl_ecdsa_meth =
e62613
     NULL,                       /* init */
e62613
     NULL,                       /* finish */
e62613
 #endif
e62613
-    0,                          /* flags */
e62613
+    ECDSA_FLAG_FIPS_METHOD,     /* flags */
e62613
     NULL                        /* app_data */
e62613
 };
e62613
 
e62613
@@ -245,6 +248,13 @@ static ECDSA_SIG *ecdsa_do_sign(const un
e62613
     ECDSA_DATA *ecdsa;
e62613
     const BIGNUM *priv_key;
e62613
 
e62613
+#ifdef OPENSSL_FIPS
e62613
+    if (FIPS_selftest_failed()) {
e62613
+        FIPSerr(FIPS_F_ECDSA_DO_SIGN, FIPS_R_FIPS_SELFTEST_FAILED);
e62613
+        return NULL;
e62613
+    }
e62613
+#endif
e62613
+
e62613
     ecdsa = ecdsa_check(eckey);
e62613
     group = EC_KEY_get0_group(eckey);
e62613
     priv_key = EC_KEY_get0_private_key(eckey);
e62613
@@ -358,6 +368,13 @@ static int ecdsa_do_verify(const unsigne
e62613
     const EC_GROUP *group;
e62613
     const EC_POINT *pub_key;
e62613
 
e62613
+#ifdef OPENSSL_FIPS
e62613
+    if (FIPS_selftest_failed()) {
e62613
+        FIPSerr(FIPS_F_ECDSA_DO_VERIFY, FIPS_R_FIPS_SELFTEST_FAILED);
e62613
+        return -1;
e62613
+    }
e62613
+#endif
e62613
+
e62613
     /* check input values */
e62613
     if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL ||
e62613
         (pub_key = EC_KEY_get0_public_key(eckey)) == NULL || sig == NULL) {
e62613
diff -up openssl-1.0.2a/crypto/ec/ec_cvt.c.fips-ec openssl-1.0.2a/crypto/ec/ec_cvt.c
e62613
--- openssl-1.0.2a/crypto/ec/ec_cvt.c.fips-ec	2015-03-19 14:30:36.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/ec/ec_cvt.c	2015-04-22 19:01:08.703040756 +0200
e62613
@@ -82,10 +82,6 @@ EC_GROUP *EC_GROUP_new_curve_GFp(const B
e62613
     const EC_METHOD *meth;
e62613
     EC_GROUP *ret;
e62613
 
e62613
-#ifdef OPENSSL_FIPS
e62613
-    if (FIPS_mode())
e62613
-        return FIPS_ec_group_new_curve_gfp(p, a, b, ctx);
e62613
-#endif
e62613
 #if defined(OPENSSL_BN_ASM_MONT)
e62613
     /*
e62613
      * This might appear controversial, but the fact is that generic
e62613
@@ -160,10 +156,6 @@ EC_GROUP *EC_GROUP_new_curve_GF2m(const
e62613
     const EC_METHOD *meth;
e62613
     EC_GROUP *ret;
e62613
 
e62613
-# ifdef OPENSSL_FIPS
e62613
-    if (FIPS_mode())
e62613
-        return FIPS_ec_group_new_curve_gf2m(p, a, b, ctx);
e62613
-# endif
e62613
     meth = EC_GF2m_simple_method();
e62613
 
e62613
     ret = EC_GROUP_new(meth);
e62613
diff -up openssl-1.0.2a/crypto/ec/ec_key.c.fips-ec openssl-1.0.2a/crypto/ec/ec_key.c
e62613
--- openssl-1.0.2a/crypto/ec/ec_key.c.fips-ec	2015-03-19 14:19:00.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/ec/ec_key.c	2015-04-22 19:00:19.722884536 +0200
e62613
@@ -64,9 +64,6 @@
e62613
 #include <string.h>
e62613
 #include "ec_lcl.h"
e62613
 #include <openssl/err.h>
e62613
-#ifdef OPENSSL_FIPS
e62613
-# include <openssl/fips.h>
e62613
-#endif
e62613
 
e62613
 EC_KEY *EC_KEY_new(void)
e62613
 {
e62613
@@ -227,6 +224,38 @@ int EC_KEY_up_ref(EC_KEY *r)
e62613
     return ((i > 1) ? 1 : 0);
e62613
 }
e62613
 
e62613
+#ifdef OPENSSL_FIPS
e62613
+
e62613
+# include <openssl/evp.h>
e62613
+# include <openssl/fips.h>
e62613
+# include <openssl/fips_rand.h>
e62613
+
e62613
+static int fips_check_ec(EC_KEY *key)
e62613
+{
e62613
+    EVP_PKEY *pk;
e62613
+    unsigned char tbs[] = "ECDSA Pairwise Check Data";
e62613
+    int ret = 0;
e62613
+
e62613
+    if ((pk = EVP_PKEY_new()) == NULL)
e62613
+        goto err;
e62613
+
e62613
+    EVP_PKEY_set1_EC_KEY(pk, key);
e62613
+
e62613
+    if (fips_pkey_signature_test(pk, tbs, -1, NULL, 0, NULL, 0, NULL))
e62613
+        ret = 1;
e62613
+
e62613
+ err:
e62613
+    if (ret == 0) {
e62613
+        FIPSerr(FIPS_F_FIPS_CHECK_EC, FIPS_R_PAIRWISE_TEST_FAILED);
e62613
+        fips_set_selftest_fail();
e62613
+    }
e62613
+    if (pk)
e62613
+        EVP_PKEY_free(pk);
e62613
+    return ret;
e62613
+}
e62613
+
e62613
+#endif
e62613
+
e62613
 int EC_KEY_generate_key(EC_KEY *eckey)
e62613
 {
e62613
     int ok = 0;
e62613
@@ -235,8 +264,10 @@ int EC_KEY_generate_key(EC_KEY *eckey)
e62613
     EC_POINT *pub_key = NULL;
e62613
 
e62613
 #ifdef OPENSSL_FIPS
e62613
-    if (FIPS_mode())
e62613
-        return FIPS_ec_key_generate_key(eckey);
e62613
+    if (FIPS_selftest_failed()) {
e62613
+        FIPSerr(FIPS_F_EC_KEY_GENERATE_KEY, FIPS_R_FIPS_SELFTEST_FAILED);
e62613
+        return 0;
e62613
+    }
e62613
 #endif
e62613
 
e62613
     if (!eckey || !eckey->group) {
e62613
@@ -277,6 +308,14 @@ int EC_KEY_generate_key(EC_KEY *eckey)
e62613
     eckey->priv_key = priv_key;
e62613
     eckey->pub_key = pub_key;
e62613
 
e62613
+#ifdef OPENSSL_FIPS
e62613
+    if (!fips_check_ec(eckey)) {
e62613
+        eckey->priv_key = NULL;
e62613
+        eckey->pub_key = NULL;
e62613
+        goto err;
e62613
+    }
e62613
+#endif
e62613
+
e62613
     ok = 1;
e62613
 
e62613
  err:
e62613
@@ -408,10 +447,12 @@ int EC_KEY_set_public_key_affine_coordin
e62613
             goto err;
e62613
     }
e62613
     /*
e62613
-     * Check if retrieved coordinates match originals: if not values are out
e62613
-     * of range.
e62613
+     * Check if retrieved coordinates match originals and are less
e62613
+     * than field order: if not values are out of range.
e62613
      */
e62613
-    if (BN_cmp(x, tx) || BN_cmp(y, ty)) {
e62613
+    if (BN_cmp(x, tx) || BN_cmp(y, ty)
e62613
+        || (BN_cmp(x, &key->group->field) >= 0)
e62613
+        || (BN_cmp(y, &key->group->field) >= 0)) {
e62613
         ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES,
e62613
               EC_R_COORDINATES_OUT_OF_RANGE);
e62613
         goto err;
e62613
diff -up openssl-1.0.2a/crypto/ec/ecp_mont.c.fips-ec openssl-1.0.2a/crypto/ec/ecp_mont.c
e62613
--- openssl-1.0.2a/crypto/ec/ecp_mont.c.fips-ec	2015-03-19 14:19:00.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/ec/ecp_mont.c	2015-04-22 19:00:19.722884536 +0200
e62613
@@ -63,10 +63,6 @@
e62613
 
e62613
 #include <openssl/err.h>
e62613
 
e62613
-#ifdef OPENSSL_FIPS
e62613
-# include <openssl/fips.h>
e62613
-#endif
e62613
-
e62613
 #include "ec_lcl.h"
e62613
 
e62613
 const EC_METHOD *EC_GFp_mont_method(void)
e62613
@@ -111,11 +107,6 @@ const EC_METHOD *EC_GFp_mont_method(void
e62613
         ec_GFp_mont_field_set_to_one
e62613
     };
e62613
 
e62613
-#ifdef OPENSSL_FIPS
e62613
-    if (FIPS_mode())
e62613
-        return fips_ec_gfp_mont_method();
e62613
-#endif
e62613
-
e62613
     return &ret;
e62613
 }
e62613
 
e62613
diff -up openssl-1.0.2a/crypto/ec/ecp_nist.c.fips-ec openssl-1.0.2a/crypto/ec/ecp_nist.c
e62613
--- openssl-1.0.2a/crypto/ec/ecp_nist.c.fips-ec	2015-03-19 14:19:00.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/ec/ecp_nist.c	2015-04-22 19:00:19.723884560 +0200
e62613
@@ -67,10 +67,6 @@
e62613
 #include <openssl/obj_mac.h>
e62613
 #include "ec_lcl.h"
e62613
 
e62613
-#ifdef OPENSSL_FIPS
e62613
-# include <openssl/fips.h>
e62613
-#endif
e62613
-
e62613
 const EC_METHOD *EC_GFp_nist_method(void)
e62613
 {
e62613
     static const EC_METHOD ret = {
e62613
@@ -113,11 +109,6 @@ const EC_METHOD *EC_GFp_nist_method(void
e62613
         0                       /* field_set_to_one */
e62613
     };
e62613
 
e62613
-#ifdef OPENSSL_FIPS
e62613
-    if (FIPS_mode())
e62613
-        return fips_ec_gfp_nist_method();
e62613
-#endif
e62613
-
e62613
     return &ret;
e62613
 }
e62613
 
e62613
diff -up openssl-1.0.2a/crypto/ec/ecp_smpl.c.fips-ec openssl-1.0.2a/crypto/ec/ecp_smpl.c
e62613
--- openssl-1.0.2a/crypto/ec/ecp_smpl.c.fips-ec	2015-03-19 14:19:00.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/ec/ecp_smpl.c	2015-04-22 19:00:19.723884560 +0200
e62613
@@ -66,10 +66,6 @@
e62613
 #include <openssl/err.h>
e62613
 #include <openssl/symhacks.h>
e62613
 
e62613
-#ifdef OPENSSL_FIPS
e62613
-# include <openssl/fips.h>
e62613
-#endif
e62613
-
e62613
 #include "ec_lcl.h"
e62613
 
e62613
 const EC_METHOD *EC_GFp_simple_method(void)
e62613
@@ -114,11 +110,6 @@ const EC_METHOD *EC_GFp_simple_method(vo
e62613
         0                       /* field_set_to_one */
e62613
     };
e62613
 
e62613
-#ifdef OPENSSL_FIPS
e62613
-    if (FIPS_mode())
e62613
-        return fips_ec_gfp_simple_method();
e62613
-#endif
e62613
-
e62613
     return &ret;
e62613
 }
e62613
 
e62613
@@ -187,6 +178,11 @@ int ec_GFp_simple_group_set_curve(EC_GRO
e62613
         return 0;
e62613
     }
e62613
 
e62613
+    if (BN_num_bits(p) < 256) {
e62613
+        ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE, EC_R_UNSUPPORTED_FIELD);
e62613
+        return 0;
e62613
+    }
e62613
+
e62613
     if (ctx == NULL) {
e62613
         ctx = new_ctx = BN_CTX_new();
e62613
         if (ctx == NULL)
e62613
diff -up openssl-1.0.2a/crypto/evp/m_ecdsa.c.fips-ec openssl-1.0.2a/crypto/evp/m_ecdsa.c
e62613
--- openssl-1.0.2a/crypto/evp/m_ecdsa.c.fips-ec	2015-03-19 14:30:36.000000000 +0100
e62613
+++ openssl-1.0.2a/crypto/evp/m_ecdsa.c	2015-04-22 19:00:19.723884560 +0200
e62613
@@ -136,7 +136,7 @@ static const EVP_MD ecdsa_md = {
e62613
     NID_ecdsa_with_SHA1,
e62613
     NID_ecdsa_with_SHA1,
e62613
     SHA_DIGEST_LENGTH,
e62613
-    EVP_MD_FLAG_PKEY_DIGEST,
e62613
+    EVP_MD_FLAG_PKEY_DIGEST | EVP_MD_FLAG_FIPS,
e62613
     init,
e62613
     update,
e62613
     final,
e62613
diff -up openssl-1.0.2a/crypto/fips/cavs/fips_ecdhvs.c.fips-ec openssl-1.0.2a/crypto/fips/cavs/fips_ecdhvs.c
e62613
--- openssl-1.0.2a/crypto/fips/cavs/fips_ecdhvs.c.fips-ec	2015-04-22 19:00:19.723884560 +0200
e62613
+++ openssl-1.0.2a/crypto/fips/cavs/fips_ecdhvs.c	2015-04-22 19:00:19.723884560 +0200
e62613
@@ -0,0 +1,456 @@
e62613
+/* fips/ecdh/fips_ecdhvs.c */
e62613
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
e62613
+ * project.
e62613
+ */
e62613
+/* ====================================================================
e62613
+ * Copyright (c) 2011 The OpenSSL Project.  All rights reserved.
e62613
+ *
e62613
+ * Redistribution and use in source and binary forms, with or without
e62613
+ * modification, are permitted provided that the following conditions
e62613
+ * are met:
e62613
+ *
e62613
+ * 1. Redistributions of source code must retain the above copyright
e62613
+ *    notice, this list of conditions and the following disclaimer. 
e62613
+ *
e62613
+ * 2. Redistributions in binary form must reproduce the above copyright
e62613
+ *    notice, this list of conditions and the following disclaimer in
e62613
+ *    the documentation and/or other materials provided with the
e62613
+ *    distribution.
e62613
+ *
e62613
+ * 3. All advertising materials mentioning features or use of this
e62613
+ *    software must display the following acknowledgment:
e62613
+ *    "This product includes software developed by the OpenSSL Project
e62613
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
e62613
+ *
e62613
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
e62613
+ *    endorse or promote products derived from this software without
e62613
+ *    prior written permission. For written permission, please contact
e62613
+ *    licensing@OpenSSL.org.
e62613
+ *
e62613
+ * 5. Products derived from this software may not be called "OpenSSL"
e62613
+ *    nor may "OpenSSL" appear in their names without prior written
e62613
+ *    permission of the OpenSSL Project.
e62613
+ *
e62613
+ * 6. Redistributions of any form whatsoever must retain the following
e62613
+ *    acknowledgment:
e62613
+ *    "This product includes software developed by the OpenSSL Project
e62613
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
e62613
+ *
e62613
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
e62613
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e62613
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
e62613
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
e62613
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
e62613
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
e62613
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
e62613
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
e62613
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
e62613
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
e62613
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
e62613
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
e62613
+ * ====================================================================
e62613
+ */
e62613
+
e62613
+#define OPENSSL_FIPSAPI
e62613
+#include <openssl/opensslconf.h>
e62613
+
e62613
+#ifndef OPENSSL_FIPS
e62613
+# include <stdio.h>
e62613
+
e62613
+int main(int argc, char **argv)
e62613
+{
e62613
+    printf("No FIPS ECDH support\n");
e62613
+    return (0);
e62613
+}
e62613
+#else
e62613
+
e62613
+# include <openssl/crypto.h>
e62613
+# include <openssl/bn.h>
e62613
+# include <openssl/ecdh.h>
e62613
+# include <openssl/fips.h>
e62613
+# include <openssl/err.h>
e62613
+# include <openssl/evp.h>
e62613
+# include <string.h>
e62613
+# include <ctype.h>
e62613
+
e62613
+# include "fips_utl.h"
e62613
+
e62613
+static const EVP_MD *eparse_md(char *line)
e62613
+{
e62613
+    char *p;
e62613
+    if (line[0] != '[' || line[1] != 'E')
e62613
+        return NULL;
e62613
+    p = strchr(line, '-');
e62613
+    if (!p)
e62613
+        return NULL;
e62613
+    line = p + 1;
e62613
+    p = strchr(line, ']');
e62613
+    if (!p)
e62613
+        return NULL;
e62613
+    *p = 0;
e62613
+    p = line;
e62613
+    while (isspace(*p))
e62613
+        p++;
e62613
+    if (!strcmp(p, "SHA1"))
e62613
+        return EVP_sha1();
e62613
+    else if (!strcmp(p, "SHA224"))
e62613
+        return EVP_sha224();
e62613
+    else if (!strcmp(p, "SHA256"))
e62613
+        return EVP_sha256();
e62613
+    else if (!strcmp(p, "SHA384"))
e62613
+        return EVP_sha384();
e62613
+    else if (!strcmp(p, "SHA512"))
e62613
+        return EVP_sha512();
e62613
+    else
e62613
+        return NULL;
e62613
+}
e62613
+
e62613
+static int lookup_curve2(char *cname)
e62613
+{
e62613
+    char *p;
e62613
+    p = strchr(cname, ']');
e62613
+    if (!p) {
e62613
+        fprintf(stderr, "Parse error: missing ]\n");
e62613
+        return NID_undef;
e62613
+    }
e62613
+    *p = 0;
e62613
+
e62613
+    if (!strcmp(cname, "B-163"))
e62613
+        return NID_sect163r2;
e62613
+    if (!strcmp(cname, "B-233"))
e62613
+        return NID_sect233r1;
e62613
+    if (!strcmp(cname, "B-283"))
e62613
+        return NID_sect283r1;
e62613
+    if (!strcmp(cname, "B-409"))
e62613
+        return NID_sect409r1;
e62613
+    if (!strcmp(cname, "B-571"))
e62613
+        return NID_sect571r1;
e62613
+    if (!strcmp(cname, "K-163"))
e62613
+        return NID_sect163k1;
e62613
+    if (!strcmp(cname, "K-233"))
e62613
+        return NID_sect233k1;
e62613
+    if (!strcmp(cname, "K-283"))
e62613
+        return NID_sect283k1;
e62613
+    if (!strcmp(cname, "K-409"))
e62613
+        return NID_sect409k1;
e62613
+    if (!strcmp(cname, "K-571"))
e62613
+        return NID_sect571k1;
e62613
+    if (!strcmp(cname, "P-192"))
e62613
+        return NID_X9_62_prime192v1;
e62613
+    if (!strcmp(cname, "P-224"))
e62613
+        return NID_secp224r1;
e62613
+    if (!strcmp(cname, "P-256"))
e62613
+        return NID_X9_62_prime256v1;
e62613
+    if (!strcmp(cname, "P-384"))
e62613
+        return NID_secp384r1;
e62613
+    if (!strcmp(cname, "P-521"))
e62613
+        return NID_secp521r1;
e62613
+
e62613
+    fprintf(stderr, "Unknown Curve name %s\n", cname);
e62613
+    return NID_undef;
e62613
+}
e62613
+
e62613
+static int lookup_curve(char *cname)
e62613
+{
e62613
+    char *p;
e62613
+    p = strchr(cname, ':');
e62613
+    if (!p) {
e62613
+        fprintf(stderr, "Parse error: missing :\n");
e62613
+        return NID_undef;
e62613
+    }
e62613
+    cname = p + 1;
e62613
+    while (isspace(*cname))
e62613
+        cname++;
e62613
+    return lookup_curve2(cname);
e62613
+}
e62613
+
e62613
+static EC_POINT *make_peer(EC_GROUP *group, BIGNUM *x, BIGNUM *y)
e62613
+{
e62613
+    EC_POINT *peer;
e62613
+    int rv;
e62613
+    BN_CTX *c;
e62613
+    peer = EC_POINT_new(group);
e62613
+    if (!peer)
e62613
+        return NULL;
e62613
+    c = BN_CTX_new();
e62613
+    if (EC_METHOD_get_field_type(EC_GROUP_method_of(group))
e62613
+        == NID_X9_62_prime_field)
e62613
+        rv = EC_POINT_set_affine_coordinates_GFp(group, peer, x, y, c);
e62613
+    else
e62613
+# ifdef OPENSSL_NO_EC2M
e62613
+    {
e62613
+        fprintf(stderr, "ERROR: GF2m not supported\n");
e62613
+        exit(1);
e62613
+    }
e62613
+# else
e62613
+        rv = EC_POINT_set_affine_coordinates_GF2m(group, peer, x, y, c);
e62613
+# endif
e62613
+
e62613
+    BN_CTX_free(c);
e62613
+    if (rv)
e62613
+        return peer;
e62613
+    EC_POINT_free(peer);
e62613
+    return NULL;
e62613
+}
e62613
+
e62613
+static int ec_print_key(FILE *out, EC_KEY *key, int add_e, int exout)
e62613
+{
e62613
+    const EC_POINT *pt;
e62613
+    const EC_GROUP *grp;
e62613
+    const EC_METHOD *meth;
e62613
+    int rv;
e62613
+    BIGNUM *tx, *ty;
e62613
+    const BIGNUM *d = NULL;
e62613
+    BN_CTX *ctx;
e62613
+    ctx = BN_CTX_new();
e62613
+    if (!ctx)
e62613
+        return 0;
e62613
+    tx = BN_CTX_get(ctx);
e62613
+    ty = BN_CTX_get(ctx);
e62613
+    if (!tx || !ty)
e62613
+        return 0;
e62613
+    grp = EC_KEY_get0_group(key);
e62613
+    pt = EC_KEY_get0_public_key(key);
e62613
+    if (exout)
e62613
+        d = EC_KEY_get0_private_key(key);
e62613
+    meth = EC_GROUP_method_of(grp);
e62613
+    if (EC_METHOD_get_field_type(meth) == NID_X9_62_prime_field)
e62613
+        rv = EC_POINT_get_affine_coordinates_GFp(grp, pt, tx, ty, ctx);
e62613
+    else
e62613
+# ifdef OPENSSL_NO_EC2M
e62613
+    {
e62613
+        fprintf(stderr, "ERROR: GF2m not supported\n");
e62613
+        exit(1);
e62613
+    }
e62613
+# else
e62613
+        rv = EC_POINT_get_affine_coordinates_GF2m(grp, pt, tx, ty, ctx);
e62613
+# endif
e62613
+
e62613
+    if (add_e) {
e62613
+        do_bn_print_name(out, "QeIUTx", tx);
e62613
+        do_bn_print_name(out, "QeIUTy", ty);
e62613
+        if (d)
e62613
+            do_bn_print_name(out, "QeIUTd", d);
e62613
+    } else {
e62613
+        do_bn_print_name(out, "QIUTx", tx);
e62613
+        do_bn_print_name(out, "QIUTy", ty);
e62613
+        if (d)
e62613
+            do_bn_print_name(out, "QIUTd", d);
e62613
+    }
e62613
+
e62613
+    BN_CTX_free(ctx);
e62613
+
e62613
+    return rv;
e62613
+
e62613
+}
e62613
+
e62613
+static void ec_output_Zhash(FILE *out, int exout, EC_GROUP *group,
e62613
+                            BIGNUM *ix, BIGNUM *iy, BIGNUM *id, BIGNUM *cx,
e62613
+                            BIGNUM *cy, const EVP_MD *md,
e62613
+                            unsigned char *rhash, size_t rhashlen)
e62613
+{
e62613
+    EC_KEY *ec = NULL;
e62613
+    EC_POINT *peerkey = NULL;
e62613
+    unsigned char *Z;
e62613
+    unsigned char chash[EVP_MAX_MD_SIZE];
e62613
+    int Zlen;
e62613
+    ec = EC_KEY_new();
e62613
+    EC_KEY_set_flags(ec, EC_FLAG_COFACTOR_ECDH);
e62613
+    EC_KEY_set_group(ec, group);
e62613
+    peerkey = make_peer(group, cx, cy);
e62613
+    if (rhash == NULL) {
e62613
+        if (md)
e62613
+            rhashlen = M_EVP_MD_size(md);
e62613
+        EC_KEY_generate_key(ec);
e62613
+        ec_print_key(out, ec, md ? 1 : 0, exout);
e62613
+    } else {
e62613
+        EC_KEY_set_public_key_affine_coordinates(ec, ix, iy);
e62613
+        EC_KEY_set_private_key(ec, id);
e62613
+    }
e62613
+    Zlen = (EC_GROUP_get_degree(group) + 7) / 8;
e62613
+    Z = OPENSSL_malloc(Zlen);
e62613
+    if (!Z)
e62613
+        exit(1);
e62613
+    ECDH_compute_key(Z, Zlen, peerkey, ec, 0);
e62613
+    if (md) {
e62613
+        if (exout)
e62613
+            OutputValue("Z", Z, Zlen, out, 0);
e62613
+        FIPS_digest(Z, Zlen, chash, NULL, md);
e62613
+        OutputValue(rhash ? "IUTHashZZ" : "HashZZ", chash, rhashlen, out, 0);
e62613
+        if (rhash) {
e62613
+            fprintf(out, "Result = %s\n",
e62613
+                    memcmp(chash, rhash, rhashlen) ? "F" : "P");
e62613
+        }
e62613
+    } else
e62613
+        OutputValue("ZIUT", Z, Zlen, out, 0);
e62613
+    OPENSSL_cleanse(Z, Zlen);
e62613
+    OPENSSL_free(Z);
e62613
+    EC_KEY_free(ec);
e62613
+    EC_POINT_free(peerkey);
e62613
+}
e62613
+
e62613
+# ifdef FIPS_ALGVS
e62613
+int fips_ecdhvs_main(int argc, char **argv)
e62613
+# else
e62613
+int main(int argc, char **argv)
e62613
+# endif
e62613
+{
e62613
+    char **args = argv + 1;
e62613
+    int argn = argc - 1;
e62613
+    FILE *in, *out;
e62613
+    char buf[2048], lbuf[2048];
e62613
+    unsigned char *rhash = NULL;
e62613
+    long rhashlen;
e62613
+    BIGNUM *cx = NULL, *cy = NULL;
e62613
+    BIGNUM *id = NULL, *ix = NULL, *iy = NULL;
e62613
+    const EVP_MD *md = NULL;
e62613
+    EC_GROUP *group = NULL;
e62613
+    char *keyword = NULL, *value = NULL;
e62613
+    int do_verify = -1, exout = 0;
e62613
+    int rv = 1;
e62613
+
e62613
+    int curve_nids[5] = { 0, 0, 0, 0, 0 };
e62613
+    int param_set = -1;
e62613
+
e62613
+    fips_algtest_init();
e62613
+
e62613
+    if (argn && !strcmp(*args, "ecdhver")) {
e62613
+        do_verify = 1;
e62613
+        args++;
e62613
+        argn--;
e62613
+    } else if (argn && !strcmp(*args, "ecdhgen")) {
e62613
+        do_verify = 0;
e62613
+        args++;
e62613
+        argn--;
e62613
+    }
e62613
+
e62613
+    if (argn && !strcmp(*args, "-exout")) {
e62613
+        exout = 1;
e62613
+        args++;
e62613
+        argn--;
e62613
+    }
e62613
+
e62613
+    if (do_verify == -1) {
e62613
+        fprintf(stderr, "%s [ecdhver|ecdhgen|] [-exout] (infile outfile)\n",
e62613
+                argv[0]);
e62613
+        exit(1);
e62613
+    }
e62613
+
e62613
+    if (argn == 2) {
e62613
+        in = fopen(*args, "r");
e62613
+        if (!in) {
e62613
+            fprintf(stderr, "Error opening input file\n");
e62613
+            exit(1);
e62613
+        }
e62613
+        out = fopen(args[1], "w");
e62613
+        if (!out) {
e62613
+            fprintf(stderr, "Error opening output file\n");
e62613
+            exit(1);
e62613
+        }
e62613
+    } else if (argn == 0) {
e62613
+        in = stdin;
e62613
+        out = stdout;
e62613
+    } else {
e62613
+        fprintf(stderr, "%s [dhver|dhgen|] [-exout] (infile outfile)\n",
e62613
+                argv[0]);
e62613
+        exit(1);
e62613
+    }
e62613
+
e62613
+    while (fgets(buf, sizeof(buf), in) != NULL) {
e62613
+        fputs(buf, out);
e62613
+        if (buf[0] == '[' && buf[1] == 'E') {
e62613
+            int c = buf[2];
e62613
+            if (c < 'A' || c > 'E')
e62613
+                goto parse_error;
e62613
+            param_set = c - 'A';
e62613
+            /* If just [E?] then initial paramset */
e62613
+            if (buf[3] == ']')
e62613
+                continue;
e62613
+            if (group)
e62613
+                EC_GROUP_free(group);
e62613
+            group = EC_GROUP_new_by_curve_name(curve_nids[c - 'A']);
e62613
+        }
e62613
+        if (strlen(buf) > 10 && !strncmp(buf, "[Curve", 6)) {
e62613
+            int nid;
e62613
+            if (param_set == -1)
e62613
+                goto parse_error;
e62613
+            nid = lookup_curve(buf);
e62613
+            if (nid == NID_undef)
e62613
+                goto parse_error;
e62613
+            curve_nids[param_set] = nid;
e62613
+        }
e62613
+
e62613
+        if (strlen(buf) > 4 && buf[0] == '[' && buf[2] == '-') {
e62613
+            int nid = lookup_curve2(buf + 1);
e62613
+            if (nid == NID_undef)
e62613
+                goto parse_error;
e62613
+            if (group)
e62613
+                EC_GROUP_free(group);
e62613
+            group = EC_GROUP_new_by_curve_name(nid);
e62613
+            if (!group) {
e62613
+                fprintf(stderr, "ERROR: unsupported curve %s\n", buf + 1);
e62613
+                return 1;
e62613
+            }
e62613
+        }
e62613
+
e62613
+        if (strlen(buf) > 6 && !strncmp(buf, "[E", 2)) {
e62613
+            md = eparse_md(buf);
e62613
+            if (md == NULL)
e62613
+                goto parse_error;
e62613
+            continue;
e62613
+        }
e62613
+        if (!parse_line(&keyword, &value, lbuf, buf))
e62613
+            continue;
e62613
+        if (!strcmp(keyword, "QeCAVSx") || !strcmp(keyword, "QCAVSx")) {
e62613
+            if (!do_hex2bn(&cx, value))
e62613
+                goto parse_error;
e62613
+        } else if (!strcmp(keyword, "QeCAVSy") || !strcmp(keyword, "QCAVSy")) {
e62613
+            if (!do_hex2bn(&cy, value))
e62613
+                goto parse_error;
e62613
+            if (do_verify == 0)
e62613
+                ec_output_Zhash(out, exout, group,
e62613
+                                NULL, NULL, NULL,
e62613
+                                cx, cy, md, rhash, rhashlen);
e62613
+        } else if (!strcmp(keyword, "deIUT")) {
e62613
+            if (!do_hex2bn(&id, value))
e62613
+                goto parse_error;
e62613
+        } else if (!strcmp(keyword, "QeIUTx")) {
e62613
+            if (!do_hex2bn(&ix, value))
e62613
+                goto parse_error;
e62613
+        } else if (!strcmp(keyword, "QeIUTy")) {
e62613
+            if (!do_hex2bn(&iy, value))
e62613
+                goto parse_error;
e62613
+        } else if (!strcmp(keyword, "CAVSHashZZ")) {
e62613
+            if (!md)
e62613
+                goto parse_error;
e62613
+            rhash = hex2bin_m(value, &rhashlen);
e62613
+            if (!rhash || rhashlen != M_EVP_MD_size(md))
e62613
+                goto parse_error;
e62613
+            ec_output_Zhash(out, exout, group, ix, iy, id, cx, cy,
e62613
+                            md, rhash, rhashlen);
e62613
+        }
e62613
+    }
e62613
+    rv = 0;
e62613
+ parse_error:
e62613
+    if (id)
e62613
+        BN_free(id);
e62613
+    if (ix)
e62613
+        BN_free(ix);
e62613
+    if (iy)
e62613
+        BN_free(iy);
e62613
+    if (cx)
e62613
+        BN_free(cx);
e62613
+    if (cy)
e62613
+        BN_free(cy);
e62613
+    if (group)
e62613
+        EC_GROUP_free(group);
e62613
+    if (in && in != stdin)
e62613
+        fclose(in);
e62613
+    if (out && out != stdout)
e62613
+        fclose(out);
e62613
+    if (rv)
e62613
+        fprintf(stderr, "Error Parsing request file\n");
e62613
+    return rv;
e62613
+}
e62613
+
e62613
+#endif
e62613
diff -up openssl-1.0.2a/crypto/fips/cavs/fips_ecdsavs.c.fips-ec openssl-1.0.2a/crypto/fips/cavs/fips_ecdsavs.c
e62613
--- openssl-1.0.2a/crypto/fips/cavs/fips_ecdsavs.c.fips-ec	2015-04-22 19:00:19.723884560 +0200
e62613
+++ openssl-1.0.2a/crypto/fips/cavs/fips_ecdsavs.c	2015-04-22 19:00:19.723884560 +0200
e62613
@@ -0,0 +1,486 @@
e62613
+/* fips/ecdsa/fips_ecdsavs.c */
e62613
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
e62613
+ * project.
e62613
+ */
e62613
+/* ====================================================================
e62613
+ * Copyright (c) 2011 The OpenSSL Project.  All rights reserved.
e62613
+ *
e62613
+ * Redistribution and use in source and binary forms, with or without
e62613
+ * modification, are permitted provided that the following conditions
e62613
+ * are met:
e62613
+ *
e62613
+ * 1. Redistributions of source code must retain the above copyright
e62613
+ *    notice, this list of conditions and the following disclaimer. 
e62613
+ *
e62613
+ * 2. Redistributions in binary form must reproduce the above copyright
e62613
+ *    notice, this list of conditions and the following disclaimer in
e62613
+ *    the documentation and/or other materials provided with the
e62613
+ *    distribution.
e62613
+ *
e62613
+ * 3. All advertising materials mentioning features or use of this
e62613
+ *    software must display the following acknowledgment:
e62613
+ *    "This product includes software developed by the OpenSSL Project
e62613
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
e62613
+ *
e62613
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
e62613
+ *    endorse or promote products derived from this software without
e62613
+ *    prior written permission. For written permission, please contact
e62613
+ *    licensing@OpenSSL.org.
e62613
+ *
e62613
+ * 5. Products derived from this software may not be called "OpenSSL"
e62613
+ *    nor may "OpenSSL" appear in their names without prior written
e62613
+ *    permission of the OpenSSL Project.
e62613
+ *
e62613
+ * 6. Redistributions of any form whatsoever must retain the following
e62613
+ *    acknowledgment:
e62613
+ *    "This product includes software developed by the OpenSSL Project
e62613
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
e62613
+ *
e62613
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
e62613
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e62613
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
e62613
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
e62613
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
e62613
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
e62613
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
e62613
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
e62613
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
e62613
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
e62613
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
e62613
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
e62613
+ * ====================================================================
e62613
+ */
e62613
+
e62613
+#define OPENSSL_FIPSAPI
e62613
+#include <openssl/opensslconf.h>
e62613
+#include <stdio.h>
e62613
+
e62613
+#ifndef OPENSSL_FIPS
e62613
+
e62613
+int main(int argc, char **argv)
e62613
+{
e62613
+    printf("No FIPS ECDSA support\n");
e62613
+    return (0);
e62613
+}
e62613
+#else
e62613
+
e62613
+# include <string.h>
e62613
+# include <ctype.h>
e62613
+# include <openssl/err.h>
e62613
+# include <openssl/bn.h>
e62613
+# include <openssl/ecdsa.h>
e62613
+# include <openssl/evp.h>
e62613
+# include "fips_utl.h"
e62613
+
e62613
+# include <openssl/objects.h>
e62613
+
e62613
+static int elookup_curve(char *in, char *curve_name, const EVP_MD **pmd)
e62613
+{
e62613
+    char *cname, *p;
e62613
+    /* Copy buffer as we will change it */
e62613
+    strcpy(curve_name, in);
e62613
+    cname = curve_name + 1;
e62613
+    p = strchr(cname, ']');
e62613
+    if (!p) {
e62613
+        fprintf(stderr, "Parse error: missing ]\n");
e62613
+        return NID_undef;
e62613
+    }
e62613
+    *p = 0;
e62613
+    p = strchr(cname, ',');
e62613
+    if (p) {
e62613
+        if (!pmd) {
e62613
+            fprintf(stderr, "Parse error: unexpected digest\n");
e62613
+            return NID_undef;
e62613
+        }
e62613
+        *p = 0;
e62613
+        p++;
e62613
+
e62613
+        if (!strcmp(p, "SHA-1"))
e62613
+            *pmd = EVP_sha1();
e62613
+        else if (!strcmp(p, "SHA-224"))
e62613
+            *pmd = EVP_sha224();
e62613
+        else if (!strcmp(p, "SHA-256"))
e62613
+            *pmd = EVP_sha256();
e62613
+        else if (!strcmp(p, "SHA-384"))
e62613
+            *pmd = EVP_sha384();
e62613
+        else if (!strcmp(p, "SHA-512"))
e62613
+            *pmd = EVP_sha512();
e62613
+        else {
e62613
+            fprintf(stderr, "Unknown digest %s\n", p);
e62613
+            return NID_undef;
e62613
+        }
e62613
+    } else if (pmd)
e62613
+        *pmd = EVP_sha1();
e62613
+
e62613
+    if (!strcmp(cname, "B-163"))
e62613
+        return NID_sect163r2;
e62613
+    if (!strcmp(cname, "B-233"))
e62613
+        return NID_sect233r1;
e62613
+    if (!strcmp(cname, "B-283"))
e62613
+        return NID_sect283r1;
e62613
+    if (!strcmp(cname, "B-409"))
e62613
+        return NID_sect409r1;
e62613
+    if (!strcmp(cname, "B-571"))
e62613
+        return NID_sect571r1;
e62613
+    if (!strcmp(cname, "K-163"))
e62613
+        return NID_sect163k1;
e62613
+    if (!strcmp(cname, "K-233"))
e62613
+        return NID_sect233k1;
e62613
+    if (!strcmp(cname, "K-283"))
e62613
+        return NID_sect283k1;
e62613
+    if (!strcmp(cname, "K-409"))
e62613
+        return NID_sect409k1;
e62613
+    if (!strcmp(cname, "K-571"))
e62613
+        return NID_sect571k1;
e62613
+    if (!strcmp(cname, "P-192"))
e62613
+        return NID_X9_62_prime192v1;
e62613
+    if (!strcmp(cname, "P-224"))
e62613
+        return NID_secp224r1;
e62613
+    if (!strcmp(cname, "P-256"))
e62613
+        return NID_X9_62_prime256v1;
e62613
+    if (!strcmp(cname, "P-384"))
e62613
+        return NID_secp384r1;
e62613
+    if (!strcmp(cname, "P-521"))
e62613
+        return NID_secp521r1;
e62613
+
e62613
+    fprintf(stderr, "Unknown Curve name %s\n", cname);
e62613
+    return NID_undef;
e62613
+}
e62613
+
e62613
+static int ec_get_pubkey(EC_KEY *key, BIGNUM *x, BIGNUM *y)
e62613
+{
e62613
+    const EC_POINT *pt;
e62613
+    const EC_GROUP *grp;
e62613
+    const EC_METHOD *meth;
e62613
+    int rv;
e62613
+    BN_CTX *ctx;
e62613
+    ctx = BN_CTX_new();
e62613
+    if (!ctx)
e62613
+        return 0;
e62613
+    grp = EC_KEY_get0_group(key);
e62613
+    pt = EC_KEY_get0_public_key(key);
e62613
+    meth = EC_GROUP_method_of(grp);
e62613
+    if (EC_METHOD_get_field_type(meth) == NID_X9_62_prime_field)
e62613
+        rv = EC_POINT_get_affine_coordinates_GFp(grp, pt, x, y, ctx);
e62613
+    else
e62613
+# ifdef OPENSSL_NO_EC2M
e62613
+    {
e62613
+        fprintf(stderr, "ERROR: GF2m not supported\n");
e62613
+        exit(1);
e62613
+    }
e62613
+# else
e62613
+        rv = EC_POINT_get_affine_coordinates_GF2m(grp, pt, x, y, ctx);
e62613
+# endif
e62613
+
e62613
+    BN_CTX_free(ctx);
e62613
+
e62613
+    return rv;
e62613
+
e62613
+}
e62613
+
e62613
+static int KeyPair(FILE *in, FILE *out)
e62613
+{
e62613
+    char buf[2048], lbuf[2048];
e62613
+    char *keyword, *value;
e62613
+    int curve_nid = NID_undef;
e62613
+    int i, count;
e62613
+    BIGNUM *Qx = NULL, *Qy = NULL;
e62613
+    const BIGNUM *d = NULL;
e62613
+    EC_KEY *key = NULL;
e62613
+    Qx = BN_new();
e62613
+    Qy = BN_new();
e62613
+    while (fgets(buf, sizeof buf, in) != NULL) {
e62613
+        if (*buf == '[' && buf[2] == '-') {
e62613
+            if (buf[2] == '-')
e62613
+                curve_nid = elookup_curve(buf, lbuf, NULL);
e62613
+            fputs(buf, out);
e62613
+            continue;
e62613
+        }
e62613
+        if (!parse_line(&keyword, &value, lbuf, buf)) {
e62613
+            fputs(buf, out);
e62613
+            continue;
e62613
+        }
e62613
+        if (!strcmp(keyword, "N")) {
e62613
+            count = atoi(value);
e62613
+
e62613
+            for (i = 0; i < count; i++) {
e62613
+
e62613
+                key = EC_KEY_new_by_curve_name(curve_nid);
e62613
+                if (!EC_KEY_generate_key(key)) {
e62613
+                    fprintf(stderr, "Error generating key\n");
e62613
+                    return 0;
e62613
+                }
e62613
+
e62613
+                if (!ec_get_pubkey(key, Qx, Qy)) {
e62613
+                    fprintf(stderr, "Error getting public key\n");
e62613
+                    return 0;
e62613
+                }
e62613
+
e62613
+                d = EC_KEY_get0_private_key(key);
e62613
+
e62613
+                do_bn_print_name(out, "d", d);
e62613
+                do_bn_print_name(out, "Qx", Qx);
e62613
+                do_bn_print_name(out, "Qy", Qy);
e62613
+                fputs(RESP_EOL, out);
e62613
+                EC_KEY_free(key);
e62613
+
e62613
+            }
e62613
+
e62613
+        }
e62613
+
e62613
+    }
e62613
+    BN_free(Qx);
e62613
+    BN_free(Qy);
e62613
+    return 1;
e62613
+}
e62613
+
e62613
+static int PKV(FILE *in, FILE *out)
e62613
+{
e62613
+
e62613
+    char buf[2048], lbuf[2048];
e62613
+    char *keyword, *value;
e62613
+    int curve_nid = NID_undef;
e62613
+    BIGNUM *Qx = NULL, *Qy = NULL;
e62613
+    EC_KEY *key = NULL;
e62613
+    while (fgets(buf, sizeof buf, in) != NULL) {
e62613
+        fputs(buf, out);
e62613
+        if (*buf == '[' && buf[2] == '-') {
e62613
+            curve_nid = elookup_curve(buf, lbuf, NULL);
e62613
+            if (curve_nid == NID_undef)
e62613
+                return 0;
e62613
+
e62613
+        }
e62613
+        if (!parse_line(&keyword, &value, lbuf, buf))
e62613
+            continue;
e62613
+        if (!strcmp(keyword, "Qx")) {
e62613
+            if (!do_hex2bn(&Qx, value)) {
e62613
+                fprintf(stderr, "Invalid Qx value\n");
e62613
+                return 0;
e62613
+            }
e62613
+        }
e62613
+        if (!strcmp(keyword, "Qy")) {
e62613
+            int rv;
e62613
+            if (!do_hex2bn(&Qy, value)) {
e62613
+                fprintf(stderr, "Invalid Qy value\n");
e62613
+                return 0;
e62613
+            }
e62613
+            key = EC_KEY_new_by_curve_name(curve_nid);
e62613
+            no_err = 1;
e62613
+            rv = EC_KEY_set_public_key_affine_coordinates(key, Qx, Qy);
e62613
+            no_err = 0;
e62613
+            EC_KEY_free(key);
e62613
+            fprintf(out, "Result = %s" RESP_EOL, rv ? "P" : "F");
e62613
+        }
e62613
+
e62613
+    }
e62613
+    BN_free(Qx);
e62613
+    BN_free(Qy);
e62613
+    return 1;
e62613
+}
e62613
+
e62613
+static int SigGen(FILE *in, FILE *out)
e62613
+{
e62613
+    char buf[2048], lbuf[2048];
e62613
+    char *keyword, *value;
e62613
+    unsigned char *msg;
e62613
+    int curve_nid = NID_undef;
e62613
+    long mlen;
e62613
+    BIGNUM *Qx = NULL, *Qy = NULL;
e62613
+    EC_KEY *key = NULL;
e62613
+    ECDSA_SIG *sig = NULL;
e62613
+    const EVP_MD *digest = NULL;
e62613
+    Qx = BN_new();
e62613
+    Qy = BN_new();
e62613
+    while (fgets(buf, sizeof buf, in) != NULL) {
e62613
+        fputs(buf, out);
e62613
+        if (*buf == '[') {
e62613
+            curve_nid = elookup_curve(buf, lbuf, &digest);
e62613
+            if (curve_nid == NID_undef)
e62613
+                return 0;
e62613
+        }
e62613
+        if (!parse_line(&keyword, &value, lbuf, buf))
e62613
+            continue;
e62613
+        if (!strcmp(keyword, "Msg")) {
e62613
+            msg = hex2bin_m(value, &mlen);
e62613
+            if (!msg) {
e62613
+                fprintf(stderr, "Invalid Message\n");
e62613
+                return 0;
e62613
+            }
e62613
+
e62613
+            key = EC_KEY_new_by_curve_name(curve_nid);
e62613
+            if (!EC_KEY_generate_key(key)) {
e62613
+                fprintf(stderr, "Error generating key\n");
e62613
+                return 0;
e62613
+            }
e62613
+
e62613
+            if (!ec_get_pubkey(key, Qx, Qy)) {
e62613
+                fprintf(stderr, "Error getting public key\n");
e62613
+                return 0;
e62613
+            }
e62613
+
e62613
+            sig = FIPS_ecdsa_sign(key, msg, mlen, digest);
e62613
+
e62613
+            if (!sig) {
e62613
+                fprintf(stderr, "Error signing message\n");
e62613
+                return 0;
e62613
+            }
e62613
+
e62613
+            do_bn_print_name(out, "Qx", Qx);
e62613
+            do_bn_print_name(out, "Qy", Qy);
e62613
+            do_bn_print_name(out, "R", sig->r);
e62613
+            do_bn_print_name(out, "S", sig->s);
e62613
+
e62613
+            EC_KEY_free(key);
e62613
+            OPENSSL_free(msg);
e62613
+            FIPS_ecdsa_sig_free(sig);
e62613
+
e62613
+        }
e62613
+
e62613
+    }
e62613
+    BN_free(Qx);
e62613
+    BN_free(Qy);
e62613
+    return 1;
e62613
+}
e62613
+
e62613
+static int SigVer(FILE *in, FILE *out)
e62613
+{
e62613
+    char buf[2048], lbuf[2048];
e62613
+    char *keyword, *value;
e62613
+    unsigned char *msg = NULL;
e62613
+    int curve_nid = NID_undef;
e62613
+    long mlen;
e62613
+    BIGNUM *Qx = NULL, *Qy = NULL;
e62613
+    EC_KEY *key = NULL;
e62613
+    ECDSA_SIG sg, *sig = &sg;
e62613
+    const EVP_MD *digest = NULL;
e62613
+    sig->r = NULL;
e62613
+    sig->s = NULL;
e62613
+    while (fgets(buf, sizeof buf, in) != NULL) {
e62613
+        fputs(buf, out);
e62613
+        if (*buf == '[') {
e62613
+            curve_nid = elookup_curve(buf, lbuf, &digest);
e62613
+            if (curve_nid == NID_undef)
e62613
+                return 0;
e62613
+        }
e62613
+        if (!parse_line(&keyword, &value, lbuf, buf))
e62613
+            continue;
e62613
+        if (!strcmp(keyword, "Msg")) {
e62613
+            msg = hex2bin_m(value, &mlen);
e62613
+            if (!msg) {
e62613
+                fprintf(stderr, "Invalid Message\n");
e62613
+                return 0;
e62613
+            }
e62613
+        }
e62613
+
e62613
+        if (!strcmp(keyword, "Qx")) {
e62613
+            if (!do_hex2bn(&Qx, value)) {
e62613
+                fprintf(stderr, "Invalid Qx value\n");
e62613
+                return 0;
e62613
+            }
e62613
+        }
e62613
+        if (!strcmp(keyword, "Qy")) {
e62613
+            if (!do_hex2bn(&Qy, value)) {
e62613
+                fprintf(stderr, "Invalid Qy value\n");
e62613
+                return 0;
e62613
+            }
e62613
+        }
e62613
+        if (!strcmp(keyword, "R")) {
e62613
+            if (!do_hex2bn(&sig->r, value)) {
e62613
+                fprintf(stderr, "Invalid R value\n");
e62613
+                return 0;
e62613
+            }
e62613
+        }
e62613
+        if (!strcmp(keyword, "S")) {
e62613
+            int rv;
e62613
+            if (!do_hex2bn(&sig->s, value)) {
e62613
+                fprintf(stderr, "Invalid S value\n");
e62613
+                return 0;
e62613
+            }
e62613
+            key = EC_KEY_new_by_curve_name(curve_nid);
e62613
+            rv = EC_KEY_set_public_key_affine_coordinates(key, Qx, Qy);
e62613
+
e62613
+            if (rv != 1) {
e62613
+                fprintf(stderr, "Error setting public key\n");
e62613
+                return 0;
e62613
+            }
e62613
+
e62613
+            no_err = 1;
e62613
+            rv = FIPS_ecdsa_verify(key, msg, mlen, digest, sig);
e62613
+            EC_KEY_free(key);
e62613
+            if (msg)
e62613
+                OPENSSL_free(msg);
e62613
+            no_err = 0;
e62613
+
e62613
+            fprintf(out, "Result = %s" RESP_EOL, rv ? "P" : "F");
e62613
+        }
e62613
+
e62613
+    }
e62613
+    if (sig->r)
e62613
+        BN_free(sig->r);
e62613
+    if (sig->s)
e62613
+        BN_free(sig->s);
e62613
+    if (Qx)
e62613
+        BN_free(Qx);
e62613
+    if (Qy)
e62613
+        BN_free(Qy);
e62613
+    return 1;
e62613
+}
e62613
+
e62613
+# ifdef FIPS_ALGVS
e62613
+int fips_ecdsavs_main(int argc, char **argv)
e62613
+# else
e62613
+int main(int argc, char **argv)
e62613
+# endif
e62613
+{
e62613
+    FILE *in = NULL, *out = NULL;
e62613
+    const char *cmd = argv[1];
e62613
+    int rv = 0;
e62613
+    fips_algtest_init();
e62613
+
e62613
+    if (argc == 4) {
e62613
+        in = fopen(argv[2], "r");
e62613
+        if (!in) {
e62613
+            fprintf(stderr, "Error opening input file\n");
e62613
+            exit(1);
e62613
+        }
e62613
+        out = fopen(argv[3], "w");
e62613
+        if (!out) {
e62613
+            fprintf(stderr, "Error opening output file\n");
e62613
+            exit(1);
e62613
+        }
e62613
+    } else if (argc == 2) {
e62613
+        in = stdin;
e62613
+        out = stdout;
e62613
+    }
e62613
+
e62613
+    if (!cmd) {
e62613
+        fprintf(stderr, "fips_ecdsavs [KeyPair|PKV|SigGen|SigVer]\n");
e62613
+        return 1;
e62613
+    }
e62613
+    if (!strcmp(cmd, "KeyPair"))
e62613
+        rv = KeyPair(in, out);
e62613
+    else if (!strcmp(cmd, "PKV"))
e62613
+        rv = PKV(in, out);
e62613
+    else if (!strcmp(cmd, "SigVer"))
e62613
+        rv = SigVer(in, out);
e62613
+    else if (!strcmp(cmd, "SigGen"))
e62613
+        rv = SigGen(in, out);
e62613
+    else {
e62613
+        fprintf(stderr, "Unknown command %s\n", cmd);
e62613
+        return 1;
e62613
+    }
e62613
+
e62613
+    if (argc == 4) {
e62613
+        fclose(in);
e62613
+        fclose(out);
e62613
+    }
e62613
+
e62613
+    if (rv <= 0) {
e62613
+        fprintf(stderr, "Error running %s\n", cmd);
e62613
+        return 1;
e62613
+    }
e62613
+
e62613
+    return 0;
e62613
+}
e62613
+
e62613
+#endif
e62613
diff -up openssl-1.0.2a/crypto/fips/fips_ecdh_selftest.c.fips-ec openssl-1.0.2a/crypto/fips/fips_ecdh_selftest.c
e62613
--- openssl-1.0.2a/crypto/fips/fips_ecdh_selftest.c.fips-ec	2015-04-22 19:00:19.724884583 +0200
e62613
+++ openssl-1.0.2a/crypto/fips/fips_ecdh_selftest.c	2015-04-22 19:00:19.724884583 +0200
e62613
@@ -0,0 +1,242 @@
e62613
+/* fips/ecdh/fips_ecdh_selftest.c */
e62613
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
e62613
+ * project 2011.
e62613
+ */
e62613
+/* ====================================================================
e62613
+ * Copyright (c) 2011 The OpenSSL Project.  All rights reserved.
e62613
+ *
e62613
+ * Redistribution and use in source and binary forms, with or without
e62613
+ * modification, are permitted provided that the following conditions
e62613
+ * are met:
e62613
+ *
e62613
+ * 1. Redistributions of source code must retain the above copyright
e62613
+ *    notice, this list of conditions and the following disclaimer. 
e62613
+ *
e62613
+ * 2. Redistributions in binary form must reproduce the above copyright
e62613
+ *    notice, this list of conditions and the following disclaimer in
e62613
+ *    the documentation and/or other materials provided with the
e62613
+ *    distribution.
e62613
+ *
e62613
+ * 3. All advertising materials mentioning features or use of this
e62613
+ *    software must display the following acknowledgment:
e62613
+ *    "This product includes software developed by the OpenSSL Project
e62613
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
e62613
+ *
e62613
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
e62613
+ *    endorse or promote products derived from this software without
e62613
+ *    prior written permission. For written permission, please contact
e62613
+ *    licensing@OpenSSL.org.
e62613
+ *
e62613
+ * 5. Products derived from this software may not be called "OpenSSL"
e62613
+ *    nor may "OpenSSL" appear in their names without prior written
e62613
+ *    permission of the OpenSSL Project.
e62613
+ *
e62613
+ * 6. Redistributions of any form whatsoever must retain the following
e62613
+ *    acknowledgment:
e62613
+ *    "This product includes software developed by the OpenSSL Project
e62613
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
e62613
+ *
e62613
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
e62613
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e62613
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
e62613
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
e62613
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
e62613
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
e62613
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
e62613
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
e62613
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
e62613
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
e62613
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
e62613
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
e62613
+ * ====================================================================
e62613
+ *
e62613
+ */
e62613
+
e62613
+#define OPENSSL_FIPSAPI
e62613
+
e62613
+#include <string.h>
e62613
+#include <openssl/crypto.h>
e62613
+#include <openssl/ec.h>
e62613
+#include <openssl/ecdh.h>
e62613
+#include <openssl/fips.h>
e62613
+#include <openssl/err.h>
e62613
+#include <openssl/evp.h>
e62613
+#include <openssl/bn.h>
e62613
+
e62613
+#ifdef OPENSSL_FIPS
e62613
+
e62613
+# include "fips_locl.h"
e62613
+
e62613
+static const unsigned char p256_qcavsx[] = {
e62613
+    0x52, 0xc6, 0xa5, 0x75, 0xf3, 0x04, 0x98, 0xb3, 0x29, 0x66, 0x0c, 0x62,
e62613
+    0x18, 0x60, 0x55, 0x41, 0x59, 0xd4, 0x60, 0x85, 0x99, 0xc1, 0x51, 0x13,
e62613
+    0x6f, 0x97, 0x85, 0x93, 0x33, 0x34, 0x07, 0x50
e62613
+};
e62613
+
e62613
+static const unsigned char p256_qcavsy[] = {
e62613
+    0x6f, 0x69, 0x24, 0xeb, 0xe9, 0x3b, 0xa7, 0xcc, 0x47, 0x17, 0xaa, 0x3f,
e62613
+    0x70, 0xfc, 0x10, 0x73, 0x0a, 0xcd, 0x21, 0xee, 0x29, 0x19, 0x1f, 0xaf,
e62613
+    0xb4, 0x1c, 0x1e, 0xc2, 0x8e, 0x97, 0x81, 0x6e
e62613
+};
e62613
+
e62613
+static const unsigned char p256_qiutx[] = {
e62613
+    0x71, 0x46, 0x88, 0x08, 0x92, 0x21, 0x1b, 0x10, 0x21, 0x74, 0xff, 0x0c,
e62613
+    0x94, 0xde, 0x34, 0x7c, 0x86, 0x74, 0xbe, 0x67, 0x41, 0x68, 0xd4, 0xc1,
e62613
+    0xe5, 0x75, 0x63, 0x9c, 0xa7, 0x46, 0x93, 0x6f
e62613
+};
e62613
+
e62613
+static const unsigned char p256_qiuty[] = {
e62613
+    0x33, 0x40, 0xa9, 0x6a, 0xf5, 0x20, 0xb5, 0x9e, 0xfc, 0x60, 0x1a, 0xae,
e62613
+    0x3d, 0xf8, 0x21, 0xd2, 0xa7, 0xca, 0x52, 0x34, 0xb9, 0x5f, 0x27, 0x75,
e62613
+    0x6c, 0x81, 0xbe, 0x32, 0x4d, 0xba, 0xbb, 0xf8
e62613
+};
e62613
+
e62613
+static const unsigned char p256_qiutd[] = {
e62613
+    0x1a, 0x48, 0x55, 0x6b, 0x11, 0xbe, 0x92, 0xd4, 0x1c, 0xd7, 0x45, 0xc3,
e62613
+    0x82, 0x81, 0x51, 0xf1, 0x23, 0x40, 0xb7, 0x83, 0xfd, 0x01, 0x6d, 0xbc,
e62613
+    0xa1, 0x66, 0xaf, 0x0a, 0x03, 0x23, 0xcd, 0xc8
e62613
+};
e62613
+
e62613
+static const unsigned char p256_ziut[] = {
e62613
+    0x77, 0x2a, 0x1e, 0x37, 0xee, 0xe6, 0x51, 0x02, 0x71, 0x40, 0xf8, 0x6a,
e62613
+    0x36, 0xf8, 0x65, 0x61, 0x2b, 0x18, 0x71, 0x82, 0x23, 0xe6, 0xf2, 0x77,
e62613
+    0xce, 0xec, 0xb8, 0x49, 0xc7, 0xbf, 0x36, 0x4f
e62613
+};
e62613
+
e62613
+typedef struct {
e62613
+    int curve;
e62613
+    const unsigned char *x1;
e62613
+    size_t x1len;
e62613
+    const unsigned char *y1;
e62613
+    size_t y1len;
e62613
+    const unsigned char *d1;
e62613
+    size_t d1len;
e62613
+    const unsigned char *x2;
e62613
+    size_t x2len;
e62613
+    const unsigned char *y2;
e62613
+    size_t y2len;
e62613
+    const unsigned char *z;
e62613
+    size_t zlen;
e62613
+} ECDH_SELFTEST_DATA;
e62613
+
e62613
+# define make_ecdh_test(nid, pr) { nid, \
e62613
+                                pr##_qiutx, sizeof(pr##_qiutx), \
e62613
+                                pr##_qiuty, sizeof(pr##_qiuty), \
e62613
+                                pr##_qiutd, sizeof(pr##_qiutd), \
e62613
+                                pr##_qcavsx, sizeof(pr##_qcavsx), \
e62613
+                                pr##_qcavsy, sizeof(pr##_qcavsy), \
e62613
+                                pr##_ziut, sizeof(pr##_ziut) }
e62613
+
e62613
+static ECDH_SELFTEST_DATA test_ecdh_data[] = {
e62613
+    make_ecdh_test(NID_X9_62_prime256v1, p256),
e62613
+};
e62613
+
e62613
+int FIPS_selftest_ecdh(void)
e62613
+{
e62613
+    EC_KEY *ec1 = NULL, *ec2 = NULL;
e62613
+    const EC_POINT *ecp = NULL;
e62613
+    BIGNUM *x = NULL, *y = NULL, *d = NULL;
e62613
+    unsigned char *ztmp = NULL;
e62613
+    int rv = 1;
e62613
+    size_t i;
e62613
+
e62613
+    for (i = 0; i < sizeof(test_ecdh_data) / sizeof(ECDH_SELFTEST_DATA); i++) {
e62613
+        ECDH_SELFTEST_DATA *ecd = test_ecdh_data + i;
e62613
+        if (!fips_post_started(FIPS_TEST_ECDH, ecd->curve, 0))
e62613
+            continue;
e62613
+        ztmp = OPENSSL_malloc(ecd->zlen);
e62613
+
e62613
+        x = BN_bin2bn(ecd->x1, ecd->x1len, x);
e62613
+        y = BN_bin2bn(ecd->y1, ecd->y1len, y);
e62613
+        d = BN_bin2bn(ecd->d1, ecd->d1len, d);
e62613
+
e62613
+        if (!x || !y || !d || !ztmp) {
e62613
+            rv = -1;
e62613
+            goto err;
e62613
+        }
e62613
+
e62613
+        ec1 = EC_KEY_new_by_curve_name(ecd->curve);
e62613
+        if (!ec1) {
e62613
+            rv = -1;
e62613
+            goto err;
e62613
+        }
e62613
+        EC_KEY_set_flags(ec1, EC_FLAG_COFACTOR_ECDH);
e62613
+
e62613
+        if (!EC_KEY_set_public_key_affine_coordinates(ec1, x, y)) {
e62613
+            rv = -1;
e62613
+            goto err;
e62613
+        }
e62613
+
e62613
+        if (!EC_KEY_set_private_key(ec1, d)) {
e62613
+            rv = -1;
e62613
+            goto err;
e62613
+        }
e62613
+
e62613
+        x = BN_bin2bn(ecd->x2, ecd->x2len, x);
e62613
+        y = BN_bin2bn(ecd->y2, ecd->y2len, y);
e62613
+
e62613
+        if (!x || !y) {
e62613
+            rv = -1;
e62613
+            goto err;
e62613
+        }
e62613
+
e62613
+        ec2 = EC_KEY_new_by_curve_name(ecd->curve);
e62613
+        if (!ec2) {
e62613
+            rv = -1;
e62613
+            goto err;
e62613
+        }
e62613
+        EC_KEY_set_flags(ec1, EC_FLAG_COFACTOR_ECDH);
e62613
+
e62613
+        if (!EC_KEY_set_public_key_affine_coordinates(ec2, x, y)) {
e62613
+            rv = -1;
e62613
+            goto err;
e62613
+        }
e62613
+
e62613
+        ecp = EC_KEY_get0_public_key(ec2);
e62613
+        if (!ecp) {
e62613
+            rv = -1;
e62613
+            goto err;
e62613
+        }
e62613
+
e62613
+        if (!ECDH_compute_key(ztmp, ecd->zlen, ecp, ec1, 0)) {
e62613
+            rv = -1;
e62613
+            goto err;
e62613
+        }
e62613
+
e62613
+        if (!fips_post_corrupt(FIPS_TEST_ECDH, ecd->curve, NULL))
e62613
+            ztmp[0] ^= 0x1;
e62613
+
e62613
+        if (memcmp(ztmp, ecd->z, ecd->zlen)) {
e62613
+            fips_post_failed(FIPS_TEST_ECDH, ecd->curve, 0);
e62613
+            rv = 0;
e62613
+        } else if (!fips_post_success(FIPS_TEST_ECDH, ecd->curve, 0))
e62613
+            goto err;
e62613
+
e62613
+        EC_KEY_free(ec1);
e62613
+        ec1 = NULL;
e62613
+        EC_KEY_free(ec2);
e62613
+        ec2 = NULL;
e62613
+        OPENSSL_free(ztmp);
e62613
+        ztmp = NULL;
e62613
+    }
e62613
+
e62613
+ err:
e62613
+
e62613
+    if (x)
e62613
+        BN_clear_free(x);
e62613
+    if (y)
e62613
+        BN_clear_free(y);
e62613
+    if (d)
e62613
+        BN_clear_free(d);
e62613
+    if (ec1)
e62613
+        EC_KEY_free(ec1);
e62613
+    if (ec2)
e62613
+        EC_KEY_free(ec2);
e62613
+    if (ztmp)
e62613
+        OPENSSL_free(ztmp);
e62613
+
e62613
+    return rv;
e62613
+
e62613
+}
e62613
+
e62613
+#endif
e62613
diff -up openssl-1.0.2a/crypto/fips/fips_ecdsa_selftest.c.fips-ec openssl-1.0.2a/crypto/fips/fips_ecdsa_selftest.c
e62613
--- openssl-1.0.2a/crypto/fips/fips_ecdsa_selftest.c.fips-ec	2015-04-22 19:00:19.724884583 +0200
e62613
+++ openssl-1.0.2a/crypto/fips/fips_ecdsa_selftest.c	2015-04-22 19:00:19.724884583 +0200
e62613
@@ -0,0 +1,165 @@
e62613
+/* fips/ecdsa/fips_ecdsa_selftest.c */
e62613
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
e62613
+ * project 2011.
e62613
+ */
e62613
+/* ====================================================================
e62613
+ * Copyright (c) 2011 The OpenSSL Project.  All rights reserved.
e62613
+ *
e62613
+ * Redistribution and use in source and binary forms, with or without
e62613
+ * modification, are permitted provided that the following conditions
e62613
+ * are met:
e62613
+ *
e62613
+ * 1. Redistributions of source code must retain the above copyright
e62613
+ *    notice, this list of conditions and the following disclaimer. 
e62613
+ *
e62613
+ * 2. Redistributions in binary form must reproduce the above copyright
e62613
+ *    notice, this list of conditions and the following disclaimer in
e62613
+ *    the documentation and/or other materials provided with the
e62613
+ *    distribution.
e62613
+ *
e62613
+ * 3. All advertising materials mentioning features or use of this
e62613
+ *    software must display the following acknowledgment:
e62613
+ *    "This product includes software developed by the OpenSSL Project
e62613
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
e62613
+ *
e62613
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
e62613
+ *    endorse or promote products derived from this software without
e62613
+ *    prior written permission. For written permission, please contact
e62613
+ *    licensing@OpenSSL.org.
e62613
+ *
e62613
+ * 5. Products derived from this software may not be called "OpenSSL"
e62613
+ *    nor may "OpenSSL" appear in their names without prior written
e62613
+ *    permission of the OpenSSL Project.
e62613
+ *
e62613
+ * 6. Redistributions of any form whatsoever must retain the following
e62613
+ *    acknowledgment:
e62613
+ *    "This product includes software developed by the OpenSSL Project
e62613
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
e62613
+ *
e62613
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
e62613
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e62613
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
e62613
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
e62613
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
e62613
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
e62613
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
e62613
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
e62613
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
e62613
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
e62613
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
e62613
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
e62613
+ * ====================================================================
e62613
+ *
e62613
+ */
e62613
+
e62613
+#define OPENSSL_FIPSAPI
e62613
+
e62613
+#include <string.h>
e62613
+#include <openssl/crypto.h>
e62613
+#include <openssl/ec.h>
e62613
+#include <openssl/ecdsa.h>
e62613
+#include <openssl/fips.h>
e62613
+#include <openssl/err.h>
e62613
+#include <openssl/evp.h>
e62613
+#include <openssl/bn.h>
e62613
+
e62613
+#ifdef OPENSSL_FIPS
e62613
+
e62613
+static const char P_256_name[] = "ECDSA P-256";
e62613
+
e62613
+static const unsigned char P_256_d[] = {
e62613
+    0x51, 0xbd, 0x06, 0xa1, 0x1c, 0xda, 0xe2, 0x12, 0x99, 0xc9, 0x52, 0x3f,
e62613
+    0xea, 0xa4, 0xd2, 0xd1, 0xf4, 0x7f, 0xd4, 0x3e, 0xbd, 0xf8, 0xfc, 0x87,
e62613
+    0xdc, 0x82, 0x53, 0x21, 0xee, 0xa0, 0xdc, 0x64
e62613
+};
e62613
+
e62613
+static const unsigned char P_256_qx[] = {
e62613
+    0x23, 0x89, 0xe0, 0xf4, 0x69, 0xe0, 0x49, 0xe5, 0xc7, 0xe5, 0x40, 0x6e,
e62613
+    0x8f, 0x25, 0xdd, 0xad, 0x11, 0x16, 0x14, 0x9b, 0xab, 0x44, 0x06, 0x31,
e62613
+    0xbf, 0x5e, 0xa6, 0x44, 0xac, 0x86, 0x00, 0x07
e62613
+};
e62613
+
e62613
+static const unsigned char P_256_qy[] = {
e62613
+    0xb3, 0x05, 0x0d, 0xd0, 0xdc, 0xf7, 0x40, 0xe6, 0xf9, 0xd8, 0x6d, 0x7b,
e62613
+    0x63, 0xca, 0x97, 0xe6, 0x12, 0xf9, 0xd4, 0x18, 0x59, 0xbe, 0xb2, 0x5e,
e62613
+    0x4a, 0x6a, 0x77, 0x23, 0xf4, 0x11, 0x9d, 0xeb
e62613
+};
e62613
+
e62613
+typedef struct {
e62613
+    int curve;
e62613
+    const char *name;
e62613
+    const unsigned char *x;
e62613
+    size_t xlen;
e62613
+    const unsigned char *y;
e62613
+    size_t ylen;
e62613
+    const unsigned char *d;
e62613
+    size_t dlen;
e62613
+} EC_SELFTEST_DATA;
e62613
+
e62613
+# define make_ecdsa_test(nid, pr) { nid, pr##_name, \
e62613
+                                pr##_qx, sizeof(pr##_qx), \
e62613
+                                pr##_qy, sizeof(pr##_qy), \
e62613
+                                pr##_d, sizeof(pr##_d)}
e62613
+
e62613
+static EC_SELFTEST_DATA test_ec_data[] = {
e62613
+    make_ecdsa_test(NID_X9_62_prime256v1, P_256),
e62613
+};
e62613
+
e62613
+int FIPS_selftest_ecdsa()
e62613
+{
e62613
+    EC_KEY *ec = NULL;
e62613
+    BIGNUM *x = NULL, *y = NULL, *d = NULL;
e62613
+    EVP_PKEY *pk = NULL;
e62613
+    int rv = 0;
e62613
+    size_t i;
e62613
+
e62613
+    for (i = 0; i < sizeof(test_ec_data) / sizeof(EC_SELFTEST_DATA); i++) {
e62613
+        EC_SELFTEST_DATA *ecd = test_ec_data + i;
e62613
+
e62613
+        x = BN_bin2bn(ecd->x, ecd->xlen, x);
e62613
+        y = BN_bin2bn(ecd->y, ecd->ylen, y);
e62613
+        d = BN_bin2bn(ecd->d, ecd->dlen, d);
e62613
+
e62613
+        if (!x || !y || !d)
e62613
+            goto err;
e62613
+
e62613
+        ec = EC_KEY_new_by_curve_name(ecd->curve);
e62613
+        if (!ec)
e62613
+            goto err;
e62613
+
e62613
+        if (!EC_KEY_set_public_key_affine_coordinates(ec, x, y))
e62613
+            goto err;
e62613
+
e62613
+        if (!EC_KEY_set_private_key(ec, d))
e62613
+            goto err;
e62613
+
e62613
+        if ((pk = EVP_PKEY_new()) == NULL)
e62613
+            goto err;
e62613
+
e62613
+        EVP_PKEY_assign_EC_KEY(pk, ec);
e62613
+
e62613
+        if (!fips_pkey_signature_test(pk, NULL, 0,
e62613
+                                      NULL, 0, EVP_sha256(), 0, ecd->name))
e62613
+            goto err;
e62613
+    }
e62613
+
e62613
+    rv = 1;
e62613
+
e62613
+ err:
e62613
+
e62613
+    if (x)
e62613
+        BN_clear_free(x);
e62613
+    if (y)
e62613
+        BN_clear_free(y);
e62613
+    if (d)
e62613
+        BN_clear_free(d);
e62613
+    if (pk)
e62613
+        EVP_PKEY_free(pk);
e62613
+    else if (ec)
e62613
+        EC_KEY_free(ec);
e62613
+
e62613
+    return rv;
e62613
+
e62613
+}
e62613
+
e62613
+#endif
e62613
diff -up openssl-1.0.2a/crypto/fips/fips.h.fips-ec openssl-1.0.2a/crypto/fips/fips.h
e62613
--- openssl-1.0.2a/crypto/fips/fips.h.fips-ec	2015-04-22 19:00:19.688883733 +0200
e62613
+++ openssl-1.0.2a/crypto/fips/fips.h	2015-04-22 19:00:19.724884583 +0200
e62613
@@ -93,6 +93,8 @@ extern "C" {
e62613
     void FIPS_corrupt_dsa(void);
e62613
     void FIPS_corrupt_dsa_keygen(void);
e62613
     int FIPS_selftest_dsa(void);
e62613
+    int FIPS_selftest_ecdsa(void);
e62613
+    int FIPS_selftest_ecdh(void);
e62613
     void FIPS_corrupt_rng(void);
e62613
     void FIPS_rng_stick(void);
e62613
     void FIPS_x931_stick(int onoff);
e62613
diff -up openssl-1.0.2a/crypto/fips/fips_post.c.fips-ec openssl-1.0.2a/crypto/fips/fips_post.c
e62613
--- openssl-1.0.2a/crypto/fips/fips_post.c.fips-ec	2015-04-22 19:00:19.688883733 +0200
e62613
+++ openssl-1.0.2a/crypto/fips/fips_post.c	2015-04-22 19:00:19.724884583 +0200
e62613
@@ -95,8 +95,12 @@ int FIPS_selftest(void)
e62613
         rv = 0;
e62613
     if (!FIPS_selftest_rsa())
e62613
         rv = 0;
e62613
+    if (!FIPS_selftest_ecdsa())
e62613
+        rv = 0;
e62613
     if (!FIPS_selftest_dsa())
e62613
         rv = 0;
e62613
+    if (!FIPS_selftest_ecdh())
e62613
+        rv = 0;
e62613
     return rv;
e62613
 }
e62613
 
e62613
diff -up openssl-1.0.2a/crypto/fips/Makefile.fips-ec openssl-1.0.2a/crypto/fips/Makefile
e62613
--- openssl-1.0.2a/crypto/fips/Makefile.fips-ec	2015-04-22 19:00:19.691883805 +0200
e62613
+++ openssl-1.0.2a/crypto/fips/Makefile	2015-04-22 19:00:19.724884583 +0200
e62613
@@ -24,13 +24,13 @@ LIBSRC=fips_aes_selftest.c fips_des_self
e62613
     fips_rsa_selftest.c fips_sha_selftest.c fips.c fips_dsa_selftest.c  fips_rand.c \
e62613
     fips_rsa_x931g.c fips_post.c fips_drbg_ctr.c fips_drbg_hash.c fips_drbg_hmac.c \
e62613
     fips_drbg_lib.c fips_drbg_rand.c fips_drbg_selftest.c fips_rand_lib.c \
e62613
-    fips_cmac_selftest.c fips_enc.c fips_md.c
e62613
+    fips_cmac_selftest.c fips_ecdh_selftest.c fips_ecdsa_selftest.c fips_enc.c fips_md.c
e62613
 
e62613
 LIBOBJ=fips_aes_selftest.o fips_des_selftest.o fips_hmac_selftest.o fips_rand_selftest.o \
e62613
     fips_rsa_selftest.o fips_sha_selftest.o fips.o fips_dsa_selftest.o  fips_rand.o \
e62613
     fips_rsa_x931g.o fips_post.o fips_drbg_ctr.o fips_drbg_hash.o fips_drbg_hmac.o \
e62613
     fips_drbg_lib.o fips_drbg_rand.o fips_drbg_selftest.o fips_rand_lib.o \
e62613
-    fips_cmac_selftest.o fips_enc.o fips_md.o
e62613
+    fips_cmac_selftest.o fips_ecdh_selftest.o fips_ecdsa_selftest.o fips_enc.o fips_md.o
e62613
 
e62613
 LIBCRYPTO=-L.. -lcrypto
e62613
 
e62613
@@ -119,6 +119,21 @@ fips_aes_selftest.o: ../../include/opens
e62613
 fips_aes_selftest.o: ../../include/openssl/safestack.h
e62613
 fips_aes_selftest.o: ../../include/openssl/stack.h
e62613
 fips_aes_selftest.o: ../../include/openssl/symhacks.h fips_aes_selftest.c
e62613
+fips_cmac_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/cmac.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/crypto.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/lhash.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/obj_mac.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/objects.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/opensslconf.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/opensslv.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/ossl_typ.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/safestack.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/stack.h
e62613
+fips_cmac_selftest.o: ../../include/openssl/symhacks.h fips_cmac_selftest.c
e62613
+fips_cmac_selftest.o: fips_locl.h
e62613
 fips_des_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
e62613
 fips_des_selftest.o: ../../include/openssl/crypto.h
e62613
 fips_des_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
e62613
@@ -232,6 +247,46 @@ fips_dsa_selftest.o: ../../include/opens
e62613
 fips_dsa_selftest.o: ../../include/openssl/stack.h
e62613
 fips_dsa_selftest.o: ../../include/openssl/symhacks.h fips_dsa_selftest.c
e62613
 fips_dsa_selftest.o: fips_locl.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/ecdh.h ../../include/openssl/err.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/lhash.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/obj_mac.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/objects.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/opensslconf.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/opensslv.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/ossl_typ.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/safestack.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/stack.h
e62613
+fips_ecdh_selftest.o: ../../include/openssl/symhacks.h fips_ecdh_selftest.c
e62613
+fips_ecdh_selftest.o: fips_locl.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/bn.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/crypto.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/ecdsa.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/fips.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/lhash.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/obj_mac.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/objects.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/opensslconf.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/opensslv.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/ossl_typ.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/safestack.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/stack.h
e62613
+fips_ecdsa_selftest.o: ../../include/openssl/symhacks.h fips_ecdsa_selftest.c
e62613
+fips_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
e62613
+fips_enc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
e62613
+fips_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
e62613
+fips_enc.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
e62613
+fips_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
e62613
+fips_enc.o: ../../include/openssl/opensslconf.h
e62613
+fips_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
e62613
+fips_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
e62613
+fips_enc.o: ../../include/openssl/symhacks.h fips_enc.c
e62613
 fips_hmac_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
e62613
 fips_hmac_selftest.o: ../../include/openssl/crypto.h
e62613
 fips_hmac_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
e62613
@@ -246,6 +301,15 @@ fips_hmac_selftest.o: ../../include/open
e62613
 fips_hmac_selftest.o: ../../include/openssl/safestack.h
e62613
 fips_hmac_selftest.o: ../../include/openssl/stack.h
e62613
 fips_hmac_selftest.o: ../../include/openssl/symhacks.h fips_hmac_selftest.c
e62613
+fips_md.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
e62613
+fips_md.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
e62613
+fips_md.o: ../../include/openssl/err.h ../../include/openssl/evp.h
e62613
+fips_md.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
e62613
+fips_md.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
e62613
+fips_md.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
e62613
+fips_md.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
e62613
+fips_md.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
e62613
+fips_md.o: fips_md.c
e62613
 fips_post.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
e62613
 fips_post.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
e62613
 fips_post.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
e62613
diff -up openssl-1.0.2a/version.map.fips-ec openssl-1.0.2a/version.map
e62613
--- openssl-1.0.2a/version.map.fips-ec	2015-04-22 19:00:19.704884111 +0200
e62613
+++ openssl-1.0.2a/version.map	2015-04-22 19:00:19.724884583 +0200
e62613
@@ -6,6 +6,10 @@ OPENSSL_1.0.1 {
e62613
 	    _original*;
e62613
 	    _current*;
e62613
 };
e62613
+OPENSSL_1.0.1_EC {
e62613
+    global:
e62613
+            EC*;
e62613
+};
e62613
 OPENSSL_1.0.2 {
e62613
     global:
e62613
 	    SSLeay;