Add algorithm selection command-line option to fips_hmactest
authorAndy Polyakov <appro@openssl.org>
Mon, 9 May 2005 22:35:35 +0000 (22:35 +0000)
committerAndy Polyakov <appro@openssl.org>
Mon, 9 May 2005 22:35:35 +0000 (22:35 +0000)
[and fix typo in fips.h].

fips/fips.h
fips/fipshashes.c
fips/hmac/fips_hmactest.c

index 86030f43c9d54dc45efd3542e18a6e7ce0be456d..d76b0de95562da8ef568d7e136d198267323b97b 100644 (file)
@@ -73,7 +73,7 @@ int FIPS_selftest_rsa(void);
 void FIPS_corrupt_dsa(void);
 int FIPS_selftest_dsa(void);
 int FIPS_selftest_rng(void);
-int FIPS_selfrest_hmac(void);
+int FIPS_selftest_hmac(void);
 
 /* The following lines are auto generated by the script mkerr.pl. Any changes
  * made after this point may be overwritten when the script is next run.
index 9d8722adab129f65eaf4db323f840f69f9d6d724..c817e8a9bc6f34596b4235585e2e430b5cc0dc83 100644 (file)
@@ -1,7 +1,7 @@
 const char * const FIPS_source_hashes[] = {
 "HMAC-SHA1(fips.c)= 7cbbda3b9e8aec46ee31797179cb72faeef80712",
 "HMAC-SHA1(fips_err_wrapper.c)= d3e2be316062510312269e98f964cb87e7577898",
-"HMAC-SHA1(fips.h)= eb5bfe9c3078345e2e0cdab8a815b33942f8e79f",
+"HMAC-SHA1(fips.h)= b36e2f13c0c1ede4dd94f0dbb9f89354b53681d8",
 "HMAC-SHA1(fips_err.h)= d356c4436362dba2974f767e06c6be1c90dbfe9f",
 "HMAC-SHA1(aes/fips_aes_core.c)= b70bbbd675efe0613da0d57055310926a0104d55",
 "HMAC-SHA1(aes/asm/fips-ax86-elf.s)= f797b524a79196e7f59458a5b223432fcfd4a868",
index 1a716ad99b28b7ae7adaff866049d6aa2f6be94b..4a7cbd5a2a5c09268fa51dcc6506f48c20a2ef23 100644 (file)
@@ -75,8 +75,8 @@ int main(int argc, char *argv[])
 
 #else
 
-static int hmac_test(BIO *err, BIO *out, BIO *in);
-static int print_hmac(BIO *err, BIO *out,
+static int hmac_test(BIO *err, const EVP_MD *md, BIO *out, BIO *in);
+static int print_hmac(BIO *err, const EVP_MD *md, BIO *out,
                unsigned char *Key, int Klen,
                unsigned char *Msg, int Msglen, int Tlen);
 
@@ -85,6 +85,8 @@ int main(int argc, char **argv)
        BIO *in = NULL, *out = NULL, *err = NULL;
 
        int ret = 1;
+       const EVP_MD *md=EVP_sha1();
+
        ERR_load_crypto_strings();
 
        err = BIO_new_fp(stderr, BIO_NOCLOSE);
@@ -101,6 +103,19 @@ int main(int argc, char **argv)
                goto end;
                }
 
+       if (argc>1 && *argv[1]=='-')
+               {
+               if (!strcasecmp(argv[1],"-sha1"))       md=EVP_sha1();
+               else if (!strcasecmp(argv[1],"-sha224"))md=EVP_sha224();
+               else if (!strcasecmp(argv[1],"-sha256"))md=EVP_sha256();
+               else if (!strcasecmp(argv[1],"-sha384"))md=EVP_sha384();
+               else if (!strcasecmp(argv[1],"-sha512"))md=EVP_sha512();
+               else    {
+                       BIO_printf(err,"Usage: %s [-sha[1|224|256|384|512]] [input [output]]\n");
+                       return 1;
+                       }
+               argc--, argv++;
+               }
        if (argc == 1)
                in = BIO_new_fp(stdin, BIO_NOCLOSE);
        else
@@ -123,7 +138,7 @@ int main(int argc, char **argv)
                goto end;
                }
 
-       if (!hmac_test(err, out, in))
+       if (!hmac_test(err, md, out, in))
                {
                fprintf(stderr, "FATAL hmac file processing error\n");
                goto end;
@@ -149,7 +164,7 @@ int main(int argc, char **argv)
 
 #define HMAC_TEST_MAXLINELEN   1024
 
-int hmac_test(BIO *err, BIO *out, BIO *in)
+int hmac_test(BIO *err, const EVP_MD *md, BIO *out, BIO *in)
        {
        char *linebuf, *olinebuf, *p, *q;
        char *keyword, *value;
@@ -253,7 +268,7 @@ int hmac_test(BIO *err, BIO *out, BIO *in)
 
                if (Key && Msg && (Tlen > 0) && (Klen > 0))
                        {
-                       if (!print_hmac(err, out, Key, Klen, Msg, Msglen, Tlen))
+                       if (!print_hmac(err, md, out, Key, Klen, Msg, Msglen, Tlen))
                                goto error;
                        OPENSSL_free(Key);
                        Key = NULL;
@@ -291,13 +306,13 @@ int hmac_test(BIO *err, BIO *out, BIO *in)
 
        }
 
-static int print_hmac(BIO *err, BIO *out,
+static int print_hmac(BIO *err, const EVP_MD *emd, BIO *out,
                unsigned char *Key, int Klen,
                unsigned char *Msg, int Msglen, int Tlen)
        {
        int i, mdlen;
        unsigned char md[EVP_MAX_MD_SIZE];
-       if (!HMAC(EVP_sha1(), Key, Klen, Msg, Msglen, md,
+       if (!HMAC(emd, Key, Klen, Msg, Msglen, md,
                                                (unsigned int *)&mdlen))
                {
                BIO_puts(err, "Error calculating HMAC\n");