Have all algorithm test programs call fips_algtest_init() at startup:
authorDr. Stephen Henson <steve@openssl.org>
Fri, 25 Mar 2011 16:36:46 +0000 (16:36 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Fri, 25 Mar 2011 16:36:46 +0000 (16:36 +0000)
this will perform all standalone operations such as setting error
callbacks, entering FIPS mode etc.

18 files changed:
fips/aes/fips_aesavs.c
fips/aes/fips_gcmtest.c
fips/cmac/fips_cmactest.c
fips/des/fips_desmovs.c
fips/dh/fips_dhvs.c
fips/dsa/fips_dsatest.c
fips/dsa/fips_dssvs.c
fips/ecdh/fips_ecdhvs.c
fips/ecdsa/fips_ecdsavs.c
fips/fips_utl.h
fips/hmac/fips_hmactest.c
fips/rand/fips_drbgvs.c
fips/rand/fips_randtest.c
fips/rand/fips_rngvs.c
fips/rsa/fips_rsagtest.c
fips/rsa/fips_rsastest.c
fips/rsa/fips_rsavtest.c
fips/sha/fips_shatest.c

index c9e2ce3b94b9b3845c40a85393263578f9cd892d..72c2d0967ca6dcf84c99ada668caba42e8547844 100644 (file)
@@ -867,12 +867,8 @@ int main(int argc, char **argv)
     FILE *fp = NULL;
     char fn[250] = "", rfn[256] = "";
     int f_opt = 0, d_opt = 1;
-    fips_set_error_print();
+    fips_algtest_init();
 
-#ifdef OPENSSL_FIPS
-    if(!FIPS_mode_set(1))
-       EXIT(1);
-#endif
     if (argc > 1)
        {
        if (strcasecmp(argv[1], "-d") == 0)
index 5eb7e7f9679dd645e370f73acddcd20ee930c766..7c9efe7d6d324f0cff56d58527739181077896c1 100644 (file)
@@ -292,9 +292,7 @@ int main(int argc,char **argv)
                fprintf(stderr,"%s [-encrypt|-decrypt]\n",argv[0]);
                exit(1);
                }
-       fips_set_error_print();
-       if(!FIPS_mode_set(1))
-               exit(1);
+       fips_algtest_init();
        if(!strcmp(argv[1],"-encrypt"))
                encrypt = 1;
        else if(!strcmp(argv[1],"-encryptIVext"))
index cc07265370b2b349f3f7efdfa77d60552e3293c0..c2da660c678cbd6770d454b3055a4ed0046970ad 100644 (file)
@@ -102,9 +102,7 @@ int main(int argc, char **argv)
        int known_keylen = 0;   /* Only set when Klen_counts_keys = 1 */
        const EVP_CIPHER *cipher = 0;
        int ret = 1;
-       fips_set_error_print();
-       if(!FIPS_mode_set(1))
-               goto end;
+       fips_algtest_init();
 
        while (argc > 1 && argv[1][0] == '-')
                {
index 16b8dc1936aee5983f76b6afe9d9842283affe45..88c306370f9fa6053b21508746b76f2264e0629e 100644 (file)
@@ -633,11 +633,7 @@ int main(int argc, char **argv)
     char fn[250] = "", rfn[256] = "";
     int f_opt = 0, d_opt = 1;
 
-#ifdef OPENSSL_FIPS
-    fips_set_error_print();
-    if(!FIPS_mode_set(1))
-       EXIT(1);
-#endif
+    fips_algtest_init();
     if (argc > 1)
        {
        if (strcasecmp(argv[1], "-d") == 0)
index dc6a95ca40a734b4f7891aa620b4b72146f97f1f..ad760c8aaaa516eec95182ba6c9d51dd22be5eb0 100644 (file)
@@ -160,9 +160,7 @@ int main(int argc,char **argv)
        char *keyword = NULL, *value = NULL;
        int do_verify = -1, exout = 0;
 
-       fips_set_error_print();
-       if(!FIPS_mode_set(1))
-               exit(1);
+       fips_algtest_init();
 
        if (argn && !strcmp(*args, "dhver"))
                {
index 678e089a428fe65d84107dc401a5f29f303766e5..c5dd088fe5776b5b5147dc7f5f1f1089970d1235 100644 (file)
@@ -156,9 +156,7 @@ int main(int argc, char **argv)
        BN_GENCB_set(&cb, dsa_cb, stderr);
        FIPS_md_ctx_init(&mctx);
 
-       fips_set_error_print();
-       if(!FIPS_mode_set(1))
-           EXIT(1);
+       fips_algtest_init();
 
        fprintf(stderr,"test generation of DSA parameters\n");
 
index ff97808ee25ce0c4ecbfe53c926aac99c35f96b9..c5a580507129c99835c9fd9a3f7b83b06cc752a4 100644 (file)
@@ -626,9 +626,7 @@ int main(int argc,char **argv)
        fprintf(stderr,"%s [prime|pqg|pqgver|keypair|keyver|siggen|sigver]\n",argv[0]);
        exit(1);
        }
-    fips_set_error_print();
-    if(!FIPS_mode_set(1))
-       exit(1);
+    fips_algtest_init();
     if(!strcmp(argv[1],"prime"))
        primes(in, out);
     else if(!strcmp(argv[1],"pqg"))
index 38178f5eeac0289041be93f7ea9e2f9a9db7eeac..c3ee1743691e414ca596bd8ee318a55b893c7e1c 100644 (file)
@@ -291,9 +291,7 @@ int main(int argc,char **argv)
        int curve_nids[5] = {0,0,0,0,0};
        int param_set = -1;
 
-       fips_set_error_print();
-       if(!FIPS_mode_set(1))
-               exit(1);
+       fips_algtest_init();
 
        if (argn && !strcmp(*args, "ecdhver"))
                {
index 2492ee42c08fcc01866bd518ec384860faf067d6..1245f854e71520d639ecbe8d095b76a879aec02a 100644 (file)
@@ -463,9 +463,7 @@ int main(int argc, char **argv)
        FILE *in = NULL, *out = NULL;
        const char *cmd = argv[1];
        int rv = 0;
-       fips_set_error_print();
-       if (!FIPS_mode_set(1))
-               exit(1);
+       fips_algtest_init();
 
        if (argc == 4)
                {
index 71147a2a31e75064469852aee46172d20f76a93d..3deb406cf419eb8ee9912c93d61f238dfe48e0a3 100644 (file)
@@ -63,6 +63,7 @@ int bint2bin(const char *in, int len, unsigned char *out);
 int bin2bint(const unsigned char *in,int len,char *out);
 void PrintValue(char *tag, unsigned char *val, int len);
 void OutputValue(char *tag, unsigned char *val, int len, FILE *rfp,int bitmode);
+void fips_algtest_init(void);
 
 static int no_err;
 
@@ -97,6 +98,16 @@ static void fips_set_error_print(void)
        FIPS_set_error_callbacks(put_err_cb, add_err_cb);
        }
 
+void fips_algtest_init(void)
+       {
+       fips_set_error_print();
+       if (!FIPS_mode_set(1))
+               {
+               fprintf(stderr, "Error entering FIPS mode\n");
+               exit(1);
+               }
+       }
+
 int hex2bin(const char *in, unsigned char *out)
     {
     int n1, n2, isodd = 0;
index d1f0b4c1caf92d31c25234ae143b6624f3da9851..58e4a35a5ba742a8efd8a779994abf6e986a9306 100644 (file)
@@ -90,9 +90,7 @@ int main(int argc, char **argv)
        FILE *in = NULL, *out = NULL;
 
        int ret = 1;
-       fips_set_error_print();
-       if(!FIPS_mode_set(1))
-               goto end;
+       fips_algtest_init();
 
        if (argc == 1)
                in = stdin;
index 53d4439342ced245b95a3fabbc53111bd8dbbcc1..d3b47a0954ea15d63e3adc740ed265444c1926cf 100644 (file)
@@ -172,7 +172,7 @@ int main(int argc,char **argv)
 
        int gen = 0;
 
-       fips_set_error_print();
+       fips_algtest_init();
 
        if (argc == 3)
                {
index b211a039c085f7cc7c2bb53ae245623de28ece31..3465bc3029d61581b0722e6d115ab5ed8a3cf44f 100644 (file)
@@ -241,7 +241,7 @@ static void run_test(unsigned char *key, int keylen, AES_PRNG_MCT *tv)
 
 int main()
        {
-       fips_set_error_print();
+       fips_algtest_init();
        run_test(aes_128_mct_key, 16, &aes_128_mct_tv);
        printf("FIPS PRNG test 1 done\n");
        run_test(aes_192_mct_key, 24, &aes_192_mct_tv);
index 786f5420b436c7e5cc0d4e5e0153a18e249a9c60..f858b6d2e926eaaf046b4c6c25f178939723875d 100644 (file)
@@ -226,9 +226,7 @@ int main(int argc,char **argv)
        fprintf(stderr,"%s [mct|vst]\n",argv[0]);
        exit(1);
        }
-    fips_set_error_print();
-    if(!FIPS_mode_set(1))
-       exit(1);
+    fips_algtest_init();
     FIPS_rand_reset();
     if (!FIPS_rand_test_mode())
        {
index 434d332b92f18153bcf77c771e4a42c9c5f8c886..78b45313987f7cd5e8fc0532d93f3aeca2116cee 100644 (file)
@@ -94,9 +94,7 @@ int main(int argc, char **argv)
 
        int ret = 1;
 
-       fips_set_error_print();
-       if(!FIPS_mode_set(1))
-               goto end;
+       fips_algtest_init();
 
        if (argc == 1)
                in = stdin;
index 2d66d92116f2700e3c92bdc395d5d7c1ecd93db1..7a3dd31cbba6e3c2260a33d75c367cfde1096a89 100644 (file)
@@ -91,9 +91,7 @@ int main(int argc, char **argv)
 
        int ret = 1, Saltlen = -1;
 
-       fips_set_error_print();
-       if(!FIPS_mode_set(1))
-               goto end;
+       fips_algtest_init();
 
        if ((argc > 2) && !strcmp("-saltlen", argv[1]))
                {
index 5886a19b031e710c067b867b1f9178443f0ee6ac..dbf73bee881223b8ef840da5d57ffcbbc89d0590 100644 (file)
@@ -96,9 +96,7 @@ int main(int argc, char **argv)
        int ret = 1;
        int Saltlen = -1;
 
-       fips_set_error_print();
-       if(!FIPS_mode_set(1))
-               goto end;
+       fips_algtest_init();
 
        if ((argc > 2) && !strcmp("-saltlen", argv[1]))
                {
index e6d1a9519acf131bf9fe929741f551dcfa819610..cdbf7193b6fbff0539906c14e3a56989bb5685e9 100644 (file)
@@ -91,9 +91,7 @@ int main(int argc, char **argv)
        FILE *in = NULL, *out = NULL;
 
        int ret = 1;
-       fips_set_error_print();
-       if(!FIPS_mode_set(1))
-               goto end;
+       fips_algtest_init();
 
        if (argc == 1)
                in = stdin;