From 69488fa929e492fb22b193668297a369b11a5771 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Mon, 9 May 2005 22:35:35 +0000 Subject: [PATCH] Add algorithm selection command-line option to fips_hmactest [and fix typo in fips.h]. --- fips/fips.h | 2 +- fips/fipshashes.c | 2 +- fips/hmac/fips_hmactest.c | 29 ++++++++++++++++++++++------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/fips/fips.h b/fips/fips.h index 86030f43c9..d76b0de955 100644 --- a/fips/fips.h +++ b/fips/fips.h @@ -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. diff --git a/fips/fipshashes.c b/fips/fipshashes.c index 9d8722adab..c817e8a9bc 100644 --- a/fips/fipshashes.c +++ b/fips/fipshashes.c @@ -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", diff --git a/fips/hmac/fips_hmactest.c b/fips/hmac/fips_hmactest.c index 1a716ad99b..4a7cbd5a2a 100644 --- a/fips/hmac/fips_hmactest.c +++ b/fips/hmac/fips_hmactest.c @@ -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"); -- 2.40.0