add ECDSA POST
authorDr. Stephen Henson <steve@openssl.org>
Fri, 18 Feb 2011 17:25:00 +0000 (17:25 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 18 Feb 2011 17:25:00 +0000 (17:25 +0000)
crypto/fips_err.h
fips/ecdsa/Makefile
fips/ecdsa/fips_ecdsa_selftest.c [new file with mode: 0644]
fips/fips.c
fips/fips.h
fips/fips_test_suite.c

index de2f0d525442fc3e0aac496d814789d2c8cc9bc2..683a69cf52e1fe7961e8ff54c45ea13ba24f64ba 100644 (file)
@@ -90,6 +90,7 @@ static ERR_STRING_DATA FIPS_str_functs[]=
 {ERR_FUNC(FIPS_F_FIPS_SELFTEST_AES_GCM),       "FIPS_selftest_aes_gcm"},
 {ERR_FUNC(FIPS_F_FIPS_SELFTEST_DES),   "FIPS_selftest_des"},
 {ERR_FUNC(FIPS_F_FIPS_SELFTEST_DSA),   "FIPS_selftest_dsa"},
+{ERR_FUNC(FIPS_F_FIPS_SELFTEST_ECDSA), "FIPS_selftest_ecdsa"},
 {ERR_FUNC(FIPS_F_FIPS_SELFTEST_HMAC),  "FIPS_selftest_hmac"},
 {ERR_FUNC(FIPS_F_FIPS_SELFTEST_RNG),   "FIPS_selftest_rng"},
 {ERR_FUNC(FIPS_F_FIPS_SELFTEST_SHA1),  "FIPS_selftest_sha1"},
index 77948d08e33fcc28c4b0ec061d1ec884723f7cd4..5e03694bba13321c32b4d35a638f91087d5c4e14 100644 (file)
@@ -22,8 +22,8 @@ TEST= fips_ecdsavs.c
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBSRC= fips_ecdsa_lib.c fips_ecdsa_sign.c
-LIBOBJ= fips_ecdsa_lib.o fips_ecdsa_sign.o
+LIBSRC= fips_ecdsa_lib.c fips_ecdsa_sign.c fips_ecdsa_selftest.c
+LIBOBJ= fips_ecdsa_lib.o fips_ecdsa_sign.o fips_ecdsa_selftest.o
 
 SRC= $(LIBSRC)
 
diff --git a/fips/ecdsa/fips_ecdsa_selftest.c b/fips/ecdsa/fips_ecdsa_selftest.c
new file mode 100644 (file)
index 0000000..50e0a8b
--- /dev/null
@@ -0,0 +1,71 @@
+/* fips/ecdsa/fips_ecdsa_selftest.c */
+
+#define OPENSSL_FIPSAPI
+
+#include <string.h>
+#include <openssl/crypto.h>
+#include <openssl/ec.h>
+#include <openssl/ecdsa.h>
+#include <openssl/fips.h>
+#include <openssl/err.h>
+#include <openssl/evp.h>
+#include <openssl/bn.h>
+
+#ifdef OPENSSL_FIPS
+
+static const unsigned char str1[]="12345678901234567890";
+
+static int corrupt_ecdsa = 0;
+
+void FIPS_corrupt_ecdsa()
+    {
+    corrupt_ecdsa = 1;
+    }
+
+int FIPS_selftest_ecdsa()
+    {
+    EC_KEY *ec=NULL;
+    int ret = 0;
+    EVP_MD_CTX mctx;
+    ECDSA_SIG *esig = NULL;
+
+    FIPS_md_ctx_init(&mctx);
+
+    ec = EC_KEY_new_by_curve_name(NID_secp384r1);
+
+    if(ec == NULL)
+       goto err;
+
+    EC_KEY_generate_key(ec);
+
+    if (!FIPS_digestinit(&mctx, EVP_sha512()))
+       goto err;
+    if (!FIPS_digestupdate(&mctx, str1, 20))
+       goto err;
+    esig = FIPS_ecdsa_sign_ctx(ec, &mctx);
+    if (!esig)
+       goto err;
+
+    if (corrupt_ecdsa)
+       BN_add_word(esig->r, 1);
+
+    if (!FIPS_digestinit(&mctx, EVP_sha512()))
+       goto err;
+    if (!FIPS_digestupdate(&mctx, str1, 20))
+       goto err;
+    if (FIPS_ecdsa_verify_ctx(ec, &mctx, esig) != 1)
+       goto err;
+
+    ret = 1;
+
+    err:
+    FIPS_md_ctx_cleanup(&mctx);
+    if (ec)
+       EC_KEY_free(ec);
+    if (esig)
+       FIPS_ecdsa_sig_free(esig);
+    if (ret == 0)
+           FIPSerr(FIPS_F_FIPS_SELFTEST_ECDSA,FIPS_R_SELFTEST_FAILED);
+    return ret;
+    }
+#endif
index 4b66537342dfbd536d22f386b1639afe2f0325c9..86adc6be515e76bb1eea10efaeff57d30515fa86 100644 (file)
@@ -178,6 +178,7 @@ int FIPS_selftest(void)
        && FIPS_selftest_aes_gcm()
        && FIPS_selftest_des()
        && FIPS_selftest_rsa()
+       && FIPS_selftest_ecdsa()
        && FIPS_selftest_dsa();
     }
 
index dab9bbe45dc7601e5a8fee608e87a36bb7491d9c..4cfb985efa7e6bb9cbceee1f8a852409472c3bf9 100644 (file)
@@ -86,6 +86,8 @@ int FIPS_selftest_rsa(void);
 void FIPS_corrupt_dsa(void);
 void FIPS_corrupt_dsa_keygen(void);
 int FIPS_selftest_dsa(void);
+int FIPS_selftest_ecdsa(void);
+void FIPS_corrupt_ecdsa(void);
 void FIPS_corrupt_ec_keygen(void);
 void FIPS_corrupt_rng(void);
 void FIPS_rng_stick(void);
@@ -195,6 +197,7 @@ void ERR_load_FIPS_strings(void);
 #define FIPS_F_FIPS_SELFTEST_AES_GCM                    130
 #define FIPS_F_FIPS_SELFTEST_DES                        111
 #define FIPS_F_FIPS_SELFTEST_DSA                        112
+#define FIPS_F_FIPS_SELFTEST_ECDSA                      131
 #define FIPS_F_FIPS_SELFTEST_HMAC                       113
 #define FIPS_F_FIPS_SELFTEST_RNG                        114
 #define FIPS_F_FIPS_SELFTEST_SHA1                       115
index 12970abe580431cbbca68f0d83cbef62acbce4fe..1d88b0d00c8b8382bfd479dd8e3510deae14111b 100644 (file)
@@ -490,6 +490,9 @@ int main(int argc,char **argv)
         } else if (!strcmp(argv[1], "dsa")) {
             FIPS_corrupt_dsa();
             printf("DSA key generation and signature validation with corrupted KAT...\n");
+        } else if (!strcmp(argv[1], "ecdsa")) {
+            FIPS_corrupt_ecdsa();
+            printf("ECDSA key generation and signature validation with corrupted KAT...\n");
         } else if (!strcmp(argv[1], "rsa")) {
             FIPS_corrupt_rsa();
             printf("RSA key generation and signature validation with corrupted KAT...\n");