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

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