From fdfc177254046cbfff46017264c7cce20666cf4b Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Thu, 10 Nov 2016 15:52:26 +1000 Subject: [PATCH 1/6] SHA224 implementation added Added SHA24 implementation and tetss. Added HMAC-SHA224 implementation and tests. Added RSA-SHA224 and ECDSA-SHA224. Added MGF1-SHA224 Added OpenSSL APIs for SHA224 Configuration option to enable SHA224 and it is on by default for x86_64 --- configure.ac | 23 ++++ src/ssl.c | 69 +++++++++++- tests/hash.c | 187 +++++++++++++++++++++++++++----- wolfcrypt/benchmark/benchmark.c | 49 +++++++++ wolfcrypt/src/asn.c | 50 ++++++++- wolfcrypt/src/hash.c | 66 +++++++++++ wolfcrypt/src/hmac.c | 80 +++++++++++++- wolfcrypt/src/misc.c | 9 ++ wolfcrypt/src/rsa.c | 5 + wolfcrypt/src/sha256.c | 86 ++++++++++++++- wolfcrypt/test/test.c | 161 +++++++++++++++++++++++++++ wolfssl/openssl/evp.h | 5 + wolfssl/openssl/sha.h | 33 +++++- wolfssl/wolfcrypt/asn.h | 1 + wolfssl/wolfcrypt/asn_public.h | 2 + wolfssl/wolfcrypt/hash.h | 9 ++ wolfssl/wolfcrypt/hmac.h | 11 +- wolfssl/wolfcrypt/integer.h | 2 + wolfssl/wolfcrypt/rsa.h | 1 + wolfssl/wolfcrypt/sha256.h | 20 ++++ 20 files changed, 828 insertions(+), 41 deletions(-) diff --git a/configure.ac b/configure.ac index 9d9afb3dd..d5a88098a 100644 --- a/configure.ac +++ b/configure.ac @@ -747,6 +747,28 @@ fi AM_CONDITIONAL([BUILD_SHA512], [test "x$ENABLED_SHA512" = "xyes"]) +# set sha224 default +SHA224_DEFAULT=no +if test "$host_cpu" = "x86_64" +then +SHA224_DEFAULT=yes +fi + +# SHA224 +AC_ARG_ENABLE([sha224], + [AS_HELP_STRING([--enable-sha224],[Enable wolfSSL SHA-224 support (default: enabled on x86_64)])], + [ ENABLED_SHA224=$enableval ], + [ ENABLED_SHA224=$SHA224_DEFAULT ] + ) + +if test "$ENABLED_SHA224" = "yes" +then + AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SHA224" +fi + +AM_CONDITIONAL([BUILD_SHA224], [test "x$ENABLED_SHA224" = "xyes"]) + + # SESSION CERTS AC_ARG_ENABLE([sessioncerts], [ --enable-sessioncerts Enable session cert storing (default: disabled)], @@ -3220,6 +3242,7 @@ echo " * NULL Cipher: $ENABLED_NULL_CIPHER" echo " * MD5: $ENABLED_MD5" echo " * RIPEMD: $ENABLED_RIPEMD" echo " * SHA: $ENABLED_SHA" +echo " * SHA-224: $ENABLED_SHA224" echo " * SHA-512: $ENABLED_SHA512" echo " * BLAKE2: $ENABLED_BLAKE2" echo " * CMAC: $ENABLED_CMAC" diff --git a/src/ssl.c b/src/ssl.c index 4401c20a3..4f8037d4c 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -699,6 +699,9 @@ int wolfSSL_GetObjectSize(void) #ifndef NO_SHA printf(" sizeof SHA = %lu\n", sizeof(Sha)); #endif +#ifdef WOLFSSL_SHA224 + printf(" sizeof SHA224 = %lu\n", sizeof(Sha224)); +#endif #ifndef NO_SHA256 printf(" sizeof SHA256 = %lu\n", sizeof(Sha256)); #endif @@ -9614,6 +9617,36 @@ int wolfSSL_set_compression(WOLFSSL* ssl) } #endif /* NO_SHA */ + #ifdef WOLFSSL_SHA224 + + void wolfSSL_SHA224_Init(WOLFSSL_SHA224_CTX* sha) + { + typedef char sha_test[sizeof(SHA224_CTX) >= sizeof(Sha224) ? 1 : -1]; + (void)sizeof(sha_test); + + WOLFSSL_ENTER("SHA224_Init"); + wc_InitSha224((Sha224*)sha); /* OpenSSL compat, no error */ + } + + + void wolfSSL_SHA224_Update(WOLFSSL_SHA224_CTX* sha, const void* input, + unsigned long sz) + { + WOLFSSL_ENTER("SHA224_Update"); + wc_Sha224Update((Sha224*)sha, (const byte*)input, (word32)sz); + /* OpenSSL compat, no error */ + } + + + void wolfSSL_SHA224_Final(byte* input, WOLFSSL_SHA224_CTX* sha) + { + WOLFSSL_ENTER("SHA224_Final"); + wc_Sha224Final((Sha224*)sha, input); + /* OpenSSL compat, no error */ + } + + #endif /* WOLFSSL_SHA224 */ + void wolfSSL_SHA256_Init(WOLFSSL_SHA256_CTX* sha256) { @@ -9725,6 +9758,17 @@ int wolfSSL_set_compression(WOLFSSL* ssl) } #endif /* NO_SHA */ + #ifdef WOLFSSL_SHA224 + + const WOLFSSL_EVP_MD* wolfSSL_EVP_sha224(void) + { + static const char* type = "SHA224"; + WOLFSSL_ENTER("EVP_sha224"); + return type; + } + + #endif /* WOLFSSL_SHA224 */ + const WOLFSSL_EVP_MD* wolfSSL_EVP_sha256(void) { @@ -10364,6 +10408,12 @@ int wolfSSL_set_compression(WOLFSSL* ssl) ctx->macType = SHA256; wolfSSL_SHA256_Init((SHA256_CTX*)&ctx->hash); } + #ifdef WOLFSSL_SHA224 + else if (XSTRNCMP(type, "SHA224", 6) == 0) { + ctx->macType = SHA224; + wolfSSL_SHA224_Init((SHA224_CTX*)&ctx->hash); + } + #endif #ifdef WOLFSSL_SHA384 else if (XSTRNCMP(type, "SHA384", 6) == 0) { ctx->macType = SHA384; @@ -10383,7 +10433,7 @@ int wolfSSL_set_compression(WOLFSSL* ssl) } #endif #ifndef NO_SHA - /* has to be last since would pick or 256, 384, or 512 too */ + /* has to be last since would pick or 224, 256, 384, or 512 too */ else if (XSTRNCMP(type, "SHA", 3) == 0) { ctx->macType = SHA; wolfSSL_SHA_Init((SHA_CTX*)&ctx->hash); @@ -10415,6 +10465,12 @@ int wolfSSL_set_compression(WOLFSSL* ssl) (unsigned long)sz); break; #endif +#ifdef WOLFSSL_SHA224 + case SHA224: + wolfSSL_SHA224_Update((SHA224_CTX*)&ctx->hash, data, + (unsigned long)sz); + break; +#endif #ifndef NO_SHA256 case SHA256: wolfSSL_SHA256_Update((SHA256_CTX*)&ctx->hash, data, @@ -10459,6 +10515,12 @@ int wolfSSL_set_compression(WOLFSSL* ssl) if (s) *s = SHA_DIGEST_SIZE; break; #endif +#ifdef WOLFSSL_SHA224 + case SHA224: + wolfSSL_SHA224_Final(md, (SHA224_CTX*)&ctx->hash); + if (s) *s = SHA224_DIGEST_SIZE; + break; +#endif #ifndef NO_SHA256 case SHA256: wolfSSL_SHA256_Final(md, (SHA256_CTX*)&ctx->hash); @@ -15909,6 +15971,11 @@ int wolfSSL_EVP_MD_size(const WOLFSSL_EVP_MD* type) return MD5_DIGEST_SIZE; } #endif +#ifdef WOLFSSL_SHA224 + else if (XSTRNCMP(type, "SHA224", 6) == 0) { + return SHA224_DIGEST_SIZE; + } +#endif #ifdef WOLFSSL_SHA384 else if (XSTRNCMP(type, "SHA384", 6) == 0) { return SHA384_DIGEST_SIZE; diff --git a/tests/hash.c b/tests/hash.c index 1e45bbdff..9167cda16 100644 --- a/tests/hash.c +++ b/tests/hash.c @@ -40,7 +40,7 @@ typedef struct testVector { const char* input; - const char* output; + const char* output; size_t inLen; size_t outLen; } testVector; @@ -48,12 +48,14 @@ typedef struct testVector { int md4_test(void); int md5_test(void); int sha_test(void); +int sha224_test(void); int sha256_test(void); int sha512_test(void); int sha384_test(void); int ripemd_test(void); int hmac_md5_test(void); int hmac_sha_test(void); +int hmac_sha224_test(void); int hmac_sha256_test(void); int hmac_sha384_test(void); @@ -66,7 +68,7 @@ int HashTest(void) #ifndef NO_MD4 if ( (ret = md4_test()) ) { printf( " MD4 test failed!\n"); - return ret; + return ret; } else printf( " MD4 test passed!\n"); #endif @@ -74,23 +76,31 @@ int HashTest(void) #ifndef NO_MD5 if ( (ret = md5_test()) ) { printf( " MD5 test failed!\n"); - return ret; + return ret; } else printf( " MD5 test passed!\n"); #endif - + #ifndef NO_SHA if ( (ret = sha_test()) ) { printf( " SHA test failed!\n"); - return ret; + return ret; } else printf( " SHA test passed!\n"); #endif - + +#ifdef WOLFSSL_SHA224 + if ( (ret = sha224_test()) ) { + printf( " SHA-224 test failed!\n"); + return ret; + } else + printf( " SHA-224 test passed!\n"); +#endif + #ifndef NO_SHA256 if ( (ret = sha256_test()) ) { printf( " SHA-256 test failed!\n"); - return ret; + return ret; } else printf( " SHA-256 test passed!\n"); #endif @@ -98,7 +108,7 @@ int HashTest(void) #ifdef WOLFSSL_SHA512 if ( (ret = sha512_test()) ) { printf( " SHA-512 test failed!\n"); - return ret; + return ret; } else printf( " SHA-512 test passed!\n"); #endif @@ -106,7 +116,7 @@ int HashTest(void) #ifdef WOLFSSL_SHA384 if ( (ret = sha384_test()) ) { printf( " SHA-384 test failed!\n"); - return ret; + return ret; } else printf( " SHA-384 test passed!\n"); #endif @@ -114,7 +124,7 @@ int HashTest(void) #ifdef WOLFSSL_RIPEMD if ( (ret = ripemd_test()) ) { printf( " RIPEMD test failed!\n"); - return ret; + return ret; } else printf( " RIPEMD test passed!\n"); #endif @@ -123,27 +133,34 @@ int HashTest(void) #ifndef NO_MD5 if ( (ret = hmac_md5_test()) ) { printf( " HMAC-MD5 test failed!\n"); - return ret; + return ret; } else printf( " HMAC-MD5 test passed!\n"); #endif #ifndef NO_SHA - if ( (ret = hmac_sha_test()) ) + if ( (ret = hmac_sha_test()) ) printf( " HMAC-SHA test failed!\n"); else printf( " HMAC-SHA test passed!\n"); #endif + #ifdef WOLFSSL_SHA224 + if ( (ret = hmac_sha224_test()) ) + printf( " HMAC-SHA224 test failed!\n"); + else + printf( " HMAC-SHA224 test passed!\n"); + #endif + #ifndef NO_SHA256 - if ( (ret = hmac_sha256_test()) ) + if ( (ret = hmac_sha256_test()) ) printf( " HMAC-SHA256 test failed!\n"); else printf( " HMAC-SHA256 test passed!\n"); #endif #ifdef WOLFSSL_SHA384 - if ( (ret = hmac_sha384_test()) ) + if ( (ret = hmac_sha384_test()) ) printf( " HMAC-SHA384 test failed!\n"); else printf( " HMAC-SHA384 test passed!\n"); @@ -151,7 +168,7 @@ int HashTest(void) #endif printf(" End HASH Tests\n"); - + return 0; } @@ -167,45 +184,45 @@ int md4_test(void) int times = sizeof(test_md4) / sizeof(testVector), i; a.input = ""; - a.output = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89" + a.output = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89" "\xc0"; a.inLen = XSTRLEN(a.input); a.outLen = XSTRLEN(a.output); b.input = "a"; - b.output = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb" + b.output = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb" "\x24"; b.inLen = XSTRLEN(b.input); b.outLen = XSTRLEN(b.output); c.input = "abc"; - c.output = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72" + c.output = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72" "\x9d"; c.inLen = XSTRLEN(c.input); c.outLen = XSTRLEN(c.output); d.input = "message digest"; - d.output = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01" + d.output = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01" "\x4b"; d.inLen = XSTRLEN(d.input); d.outLen = XSTRLEN(d.output); e.input = "abcdefghijklmnopqrstuvwxyz"; - e.output = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d" + e.output = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d" "\xa9"; e.inLen = XSTRLEN(e.input); e.outLen = XSTRLEN(e.output); f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345" "6789"; - f.output = "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0" + f.output = "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0" "\xe4"; f.inLen = XSTRLEN(f.input); f.outLen = XSTRLEN(f.output); g.input = "1234567890123456789012345678901234567890123456789012345678" "9012345678901234567890"; - g.output = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05" + g.output = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05" "\x36"; g.inLen = XSTRLEN(g.input); g.outLen = XSTRLEN(g.output); @@ -356,6 +373,52 @@ int sha_test(void) } #endif /* NO_SHA */ +#ifdef WOLFSSL_SHA224 +int sha224_test(void) +{ + Sha224 sha; + byte hash[SHA224_DIGEST_SIZE]; + + testVector a, b; + testVector test_sha[2]; + int ret; + int times = sizeof(test_sha) / sizeof(struct testVector), i; + + a.input = "abc"; + a.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2\x55" + "\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7"; + a.inLen = XSTRLEN(a.input); + a.outLen = SHA224_DIGEST_SIZE; + + b.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; + b.output = "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01" + "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25"; + b.inLen = XSTRLEN(b.input); + b.outLen = SHA224_DIGEST_SIZE; + + test_sha[0] = a; + test_sha[1] = b; + + ret = wc_InitSha224(&sha); + if (ret != 0) + return -4005; + + for (i = 0; i < times; ++i) { + ret = wc_Sha224Update(&sha, (byte*)test_sha[i].input,(word32)test_sha[i].inLen); + if (ret != 0) + return ret; + ret = wc_Sha224Final(&sha, hash); + if (ret != 0) + return ret; + + if (XMEMCMP(hash, test_sha[i].output, SHA224_DIGEST_SIZE) != 0) + return -10 - i; + } + + return 0; +} +#endif + #ifndef NO_SHA256 int sha256_test(void) { @@ -431,7 +494,7 @@ int sha512_test(void) "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88" "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4" "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b" - "\x87\x4b\xe9\x09"; + "\x87\x4b\xe9\x09"; b.inLen = XSTRLEN(b.input); b.outLen = XSTRLEN(b.output); @@ -533,7 +596,7 @@ int ripemd_test(void) b.inLen = XSTRLEN(b.input); b.outLen = XSTRLEN(b.output); - c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; + c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; c.output = "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05\xa0\x6c\x27\xdc" "\xf4\x9a\xda\x62\xeb\x2b"; c.inLen = XSTRLEN(c.input); @@ -542,7 +605,7 @@ int ripemd_test(void) d.input = "12345678901234567890123456789012345678901234567890123456" "789012345678901234567890"; d.output = "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb\xd3\x32\x3c\xab" - "\x82\xbf\x63\x32\x6b\xfb"; + "\x82\xbf\x63\x32\x6b\xfb"; d.inLen = XSTRLEN(d.input); d.outLen = XSTRLEN(d.output); @@ -704,6 +767,80 @@ int hmac_sha_test(void) } #endif +#if !defined(NO_HMAC) && defined(WOLFSSL_SHA224) +int hmac_sha224_test(void) +{ + Hmac hmac; + byte hash[SHA224_DIGEST_SIZE]; + + const char* keys[]= + { + "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" + "\x0b\x0b\x0b", + "Jefe", + "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA" + "\xAA\xAA\xAA" + }; + + testVector a, b, c; + testVector test_hmac[3]; + + int ret; + int times = sizeof(test_hmac) / sizeof(testVector), i; + + a.input = "Hi There"; + a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3" + "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22"; + a.inLen = XSTRLEN(a.input); + a.outLen = SHA224_DIGEST_SIZE; + + b.input = "what do ya want for nothing?"; + b.output = "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d" + "\x0f\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44"; + b.inLen = XSTRLEN(b.input); + b.outLen = SHA224_DIGEST_SIZE; + + c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" + "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" + "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" + "\xDD\xDD\xDD\xDD\xDD\xDD"; + c.output = "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2" + "\x64\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea"; + c.inLen = XSTRLEN(c.input); + c.outLen = SHA224_DIGEST_SIZE; + + test_hmac[0] = a; + test_hmac[1] = b; + test_hmac[2] = c; + + for (i = 0; i < times; ++i) { +#if defined(HAVE_FIPS) || defined(HAVE_CAVIUM) + if (i == 1) + continue; /* cavium can't handle short keys, fips not allowed */ +#endif + ret = wc_HmacSetKey(&hmac, SHA224, (byte*)keys[i],(word32)XSTRLEN(keys[i])); + if (ret != 0) + return -4021; + ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input, + (word32)test_hmac[i].inLen); + if (ret != 0) + return -4022; + ret = wc_HmacFinal(&hmac, hash); + if (ret != 0) + return -4023; + + if (XMEMCMP(hash, test_hmac[i].output, SHA224_DIGEST_SIZE) != 0) + return -20 - i; +#ifdef WOLFSSL_ASYNC_CRYPT + wc_HmacAsyncFree(&hmac); +#endif + } + + return 0; +} +#endif + + #if !defined(NO_HMAC) && !defined(NO_SHA256) int hmac_sha256_test(void) { diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 9f9455afc..87f92c720 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -191,6 +191,7 @@ void bench_camellia(void); void bench_md5(void); void bench_sha(void); +void bench_sha224(void); void bench_sha256(void); void bench_sha384(void); void bench_sha512(void); @@ -397,6 +398,9 @@ int benchmark_test(void *args) #ifndef NO_SHA bench_sha(); #endif +#ifdef WOLFSSL_SHA224 + bench_sha224(); +#endif #ifndef NO_SHA256 bench_sha256(); #endif @@ -1163,6 +1167,51 @@ void bench_sha(void) #endif /* NO_SHA */ +#ifdef WOLFSSL_SHA224 +void bench_sha224(void) +{ + Sha224 hash; + byte digest[SHA224_DIGEST_SIZE]; + double start, total, persec; + int i, ret; + + ret = wc_InitSha224(&hash); + if (ret != 0) { + printf("InitSha224 failed, ret = %d\n", ret); + return; + } + start = current_time(1); + BEGIN_INTEL_CYCLES + + for(i = 0; i < numBlocks; i++) { + ret = wc_Sha224Update(&hash, plain, sizeof(plain)); + if (ret != 0) { + printf("Sha224Update failed, ret = %d\n", ret); + return; + } + } + + ret = wc_Sha224Final(&hash, digest); + if (ret != 0) { + printf("Sha224Final failed, ret = %d\n", ret); + return; + } + + END_INTEL_CYCLES + total = current_time(0) - start; + persec = 1 / total * numBlocks; +#ifdef BENCH_EMBEDDED + /* since using kB, convert to MB/s */ + persec = persec / 1024; +#endif + + printf("SHA-224 %d %s took %5.3f seconds, %8.3f MB/s", numBlocks, + blockType, total, persec); + SHOW_INTEL_CYCLES + printf("\n"); +} +#endif + #ifndef NO_SHA256 void bench_sha256(void) { diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 30acdf711..2c6d92f24 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -750,6 +750,7 @@ static int GetIntRsa(RsaKey* key, mp_int* mpi, const byte* input, static const byte hashMd2hOid[] = {42, 134, 72, 134, 247, 13, 2, 2}; static const byte hashMd5hOid[] = {42, 134, 72, 134, 247, 13, 2, 5}; static const byte hashSha1hOid[] = {43, 14, 3, 2, 26}; +static const byte hashSha224hOid[] = {96, 134, 72, 1, 101, 3, 4, 2, 4}; static const byte hashSha256hOid[] = {96, 134, 72, 1, 101, 3, 4, 2, 1}; static const byte hashSha384hOid[] = {96, 134, 72, 1, 101, 3, 4, 2, 2}; static const byte hashSha512hOid[] = {96, 134, 72, 1, 101, 3, 4, 2, 3}; @@ -762,12 +763,14 @@ static const byte hashSha512hOid[] = {96, 134, 72, 1, 101, 3, 4, 2, 3}; static const byte sigMd2wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1, 2}; static const byte sigMd5wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1, 4}; static const byte sigSha1wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1, 5}; + static const byte sigSha224wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1,14}; static const byte sigSha256wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1,11}; static const byte sigSha384wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1,12}; static const byte sigSha512wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1,13}; #endif /* NO_RSA */ #ifdef HAVE_ECC static const byte sigSha1wEcdsaOid[] = {42, 134, 72, 206, 61, 4, 1}; + static const byte sigSha224wEcdsaOid[] = {42, 134, 72, 206, 61, 4, 3, 1}; static const byte sigSha256wEcdsaOid[] = {42, 134, 72, 206, 61, 4, 3, 2}; static const byte sigSha384wEcdsaOid[] = {42, 134, 72, 206, 61, 4, 3, 3}; static const byte sigSha512wEcdsaOid[] = {42, 134, 72, 206, 61, 4, 3, 4}; @@ -859,6 +862,10 @@ static const byte* OidFromId(word32 id, word32 type, word32* oidSz) oid = hashSha1hOid; *oidSz = sizeof(hashSha1hOid); break; + case SHA224h: + oid = hashSha224hOid; + *oidSz = sizeof(hashSha224hOid); + break; case SHA256h: oid = hashSha256hOid; *oidSz = sizeof(hashSha256hOid); @@ -895,6 +902,10 @@ static const byte* OidFromId(word32 id, word32 type, word32* oidSz) oid = sigSha1wRsaOid; *oidSz = sizeof(sigSha1wRsaOid); break; + case CTC_SHA224wRSA: + oid = sigSha224wRsaOid; + *oidSz = sizeof(sigSha224wRsaOid); + break; case CTC_SHA256wRSA: oid = sigSha256wRsaOid; *oidSz = sizeof(sigSha256wRsaOid); @@ -913,6 +924,10 @@ static const byte* OidFromId(word32 id, word32 type, word32* oidSz) oid = sigSha1wEcdsaOid; *oidSz = sizeof(sigSha1wEcdsaOid); break; + case CTC_SHA224wECDSA: + oid = sigSha224wEcdsaOid; + *oidSz = sizeof(sigSha224wEcdsaOid); + break; case CTC_SHA256wECDSA: oid = sigSha256wEcdsaOid; *oidSz = sizeof(sigSha256wEcdsaOid); @@ -3785,6 +3800,10 @@ int wc_GetCTC_HashOID(int type) case SHA: return SHAh; #endif +#ifdef WOLFSSL_SHA224 + case SHA224: + return SHA224h; +#endif #ifndef NO_SHA256 case SHA256: return SHA256h; @@ -3855,6 +3874,15 @@ static int ConfirmSignature(const byte* buf, word32 bufSz, } break; #endif + #ifdef WOLFSSL_SHA224 + case CTC_SHA224wRSA: + case CTC_SHA224wECDSA: + if (wc_Sha224Hash(buf, bufSz, digest) == 0) { + typeH = SHA224h; + digestSz = SHA224_DIGEST_SIZE; + } + break; + #endif #ifndef NO_SHA256 case CTC_SHA256wRSA: case CTC_SHA256wECDSA: @@ -7613,6 +7641,15 @@ static int MakeSignature(const byte* buffer, int sz, byte* sig, int sigSz, } break; #endif + #ifdef WOLFSSL_SHA224 + case CTC_SHA224wRSA: + case CTC_SHA224wECDSA: + if ((ret = wc_Sha224Hash(buffer, sz, digest)) == 0) { + typeH = SHA224h; + digestSz = SHA224_DIGEST_SIZE; + } + break; + #endif #ifndef NO_SHA256 case CTC_SHA256wRSA: case CTC_SHA256wECDSA: @@ -7622,12 +7659,21 @@ static int MakeSignature(const byte* buffer, int sz, byte* sig, int sigSz, } break; #endif + #ifdef WOLFSSL_SHA384 + case CTC_SHA384wRSA: + case CTC_SHA384wECDSA: + if ((ret = wc_Sha384Hash(buffer, sz, digest)) == 0) { + typeH = SHA384h; + digestSz = SHA384_DIGEST_SIZE; + } + break; + #endif #ifdef WOLFSSL_SHA512 case CTC_SHA512wRSA: case CTC_SHA512wECDSA: if ((ret = wc_Sha512Hash(buffer, sz, digest)) == 0) { - typeH = SHA256h; - digestSz = SHA256_DIGEST_SIZE; + typeH = SHA512h; + digestSz = SHA512_DIGEST_SIZE; } break; #endif diff --git a/wolfcrypt/src/hash.c b/wolfcrypt/src/hash.c index 7cda03024..d06ad59e5 100644 --- a/wolfcrypt/src/hash.c +++ b/wolfcrypt/src/hash.c @@ -41,6 +41,7 @@ enum Hash_Sum { MD2h = 646, MD5h = 649, SHAh = 88, + SHA224h = 417, SHA256h = 414, SHA384h = 415, SHA512h = 416 @@ -68,6 +69,11 @@ int wc_HashGetOID(enum wc_HashType hash_type) oid = SHAh; #endif break; + case WC_HASH_TYPE_SHA224: + #if defined(WOLFSSL_SHA224) + oid = SHA224h; + #endif + break; case WC_HASH_TYPE_SHA256: #ifndef NO_SHA256 oid = SHA256h; @@ -109,6 +115,11 @@ int wc_HashGetDigestSize(enum wc_HashType hash_type) case WC_HASH_TYPE_SHA: #ifndef NO_SHA dig_size = SHA_DIGEST_SIZE; +#endif + break; + case WC_HASH_TYPE_SHA224: +#ifdef WOLFSSL_SHA224 + dig_size = SHA224_DIGEST_SIZE; #endif break; case WC_HASH_TYPE_SHA256: @@ -172,6 +183,11 @@ int wc_Hash(enum wc_HashType hash_type, const byte* data, case WC_HASH_TYPE_SHA: #ifndef NO_SHA ret = wc_ShaHash(data, data_len, hash); +#endif + break; + case WC_HASH_TYPE_SHA224: +#ifdef WOLFSSL_SHA512 + ret = wc_Sha224Hash(data, data_len, hash); #endif break; case WC_HASH_TYPE_SHA256: @@ -273,6 +289,56 @@ int wc_ShaHash(const byte* data, word32 len, byte* hash) #endif /* !defined(NO_SHA) */ +#if defined(WOLFSSL_SHA224) +int wc_Sha224GetHash(Sha224* sha224, byte* hash) +{ + int ret; + Sha224 save; + + if (sha224 == NULL || hash == NULL) + return BAD_FUNC_ARG; + + save= *sha224; + ret = wc_Sha224Final(sha224, hash); + *sha224 = save; + + return ret; +} + +int wc_Sha224Hash(const byte* data, word32 len, byte* hash) +{ + int ret = 0; +#ifdef WOLFSSL_SMALL_STACK + Sha224* sha224; +#else + Sha224 sha224[1]; +#endif + +#ifdef WOLFSSL_SMALL_STACK + sha224 = (Sha224*)XMALLOC(sizeof(Sha224), NULL, DYNAMIC_TYPE_TMP_BUFFER); + if (sha224 == NULL) + return MEMORY_E; +#endif + + if ((ret = wc_InitSha224(sha224)) != 0) { + WOLFSSL_MSG("InitSha224 failed"); + } + else if ((ret = wc_Sha224Update(sha224, data, len)) != 0) { + WOLFSSL_MSG("Sha224Update failed"); + } + else if ((ret = wc_Sha224Final(sha224, hash)) != 0) { + WOLFSSL_MSG("Sha224Final failed"); + } + +#ifdef WOLFSSL_SMALL_STACK + XFREE(sha224, NULL, DYNAMIC_TYPE_TMP_BUFFER); +#endif + + return ret; +} + +#endif /* defined(WOLFSSL_SHA224) */ + #if !defined(NO_SHA256) int wc_Sha256GetHash(Sha256* sha256, byte* hash) { diff --git a/wolfcrypt/src/hmac.c b/wolfcrypt/src/hmac.c index 5312b2860..7e4070ef2 100644 --- a/wolfcrypt/src/hmac.c +++ b/wolfcrypt/src/hmac.c @@ -108,7 +108,8 @@ int wc_HKDF(int type, const byte* inKey, word32 inKeySz, int wc_HmacSizeByType(int type) { if (!(type == MD5 || type == SHA || type == SHA256 || type == SHA384 - || type == SHA512 || type == BLAKE2B_ID)) { + || type == SHA512 || type == BLAKE2B_ID) + || type == SHA224) { return BAD_FUNC_ARG; } @@ -123,6 +124,11 @@ int wc_HmacSizeByType(int type) return SHA_DIGEST_SIZE; #endif + #ifndef WOLF_SHA224 + case SHA224: + return SHA224_DIGEST_SIZE; + #endif + #ifndef NO_SHA256 case SHA256: return SHA256_DIGEST_SIZE; @@ -156,7 +162,8 @@ static int InitHmac(Hmac* hmac, int type) hmac->macType = (byte)type; if (!(type == MD5 || type == SHA || type == SHA256 || type == SHA384 - || type == SHA512 || type == BLAKE2B_ID)) + || type == SHA512 || type == BLAKE2B_ID + || type == SHA224)) return BAD_FUNC_ARG; switch (type) { @@ -172,6 +179,12 @@ static int InitHmac(Hmac* hmac, int type) break; #endif + #ifdef WOLFSSL_SHA224 + case SHA224: + ret = wc_InitSha224(&hmac->hash.sha224); + break; + #endif + #ifndef NO_SHA256 case SHA256: ret = wc_InitSha256(&hmac->hash.sha256); @@ -259,6 +272,28 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length) break; #endif + #ifdef WOLFSSL_SHA224 + case SHA224: + { + hmac_block_size = SHA224_BLOCK_SIZE; + if (length <= SHA224_BLOCK_SIZE) { + XMEMCPY(ip, key, length); + } + else { + ret = wc_Sha224Update(&hmac->hash.sha224, key, length); + if (ret != 0) + return ret; + + ret = wc_Sha224Final(&hmac->hash.sha224, ip); + if (ret != 0) + return ret; + + length = SHA224_DIGEST_SIZE; + } + } + break; + #endif + #ifndef NO_SHA256 case SHA256: { @@ -378,6 +413,15 @@ static int HmacKeyInnerHash(Hmac* hmac) break; #endif + #ifdef WOLFSSL_SHA224 + case SHA224: + ret = wc_Sha224Update(&hmac->hash.sha224, + (byte*) hmac->ipad, SHA224_BLOCK_SIZE); + if (ret != 0) + return ret; + break; + #endif + #ifndef NO_SHA256 case SHA256: ret = wc_Sha256Update(&hmac->hash.sha256, @@ -453,6 +497,14 @@ int wc_HmacUpdate(Hmac* hmac, const byte* msg, word32 length) break; #endif + #ifdef WOLFSSL_SHA224 + case SHA224: + ret = wc_Sha224Update(&hmac->hash.sha224, msg, length); + if (ret != 0) + return ret; + break; + #endif + #ifndef NO_SHA256 case SHA256: ret = wc_Sha256Update(&hmac->hash.sha256, msg, length); @@ -538,6 +590,30 @@ int wc_HmacFinal(Hmac* hmac, byte* hash) break; #endif + #ifdef WOLFSSL_SHA224 + case SHA224: + { + ret = wc_Sha224Final(&hmac->hash.sha224, (byte*) hmac->innerHash); + if (ret != 0) + return ret; + + ret = wc_Sha224Update(&hmac->hash.sha224, + (byte*) hmac->opad, SHA224_BLOCK_SIZE); + if (ret != 0) + return ret; + + ret = wc_Sha224Update(&hmac->hash.sha224, + (byte*) hmac->innerHash, SHA224_DIGEST_SIZE); + if (ret != 0) + return ret; + + ret = wc_Sha224Final(&hmac->hash.sha224, hash); + if (ret != 0) + return ret; + } + break; + #endif + #ifndef NO_SHA256 case SHA256: { diff --git a/wolfcrypt/src/misc.c b/wolfcrypt/src/misc.c index 99dc2abeb..0dcf50536 100644 --- a/wolfcrypt/src/misc.c +++ b/wolfcrypt/src/misc.c @@ -183,9 +183,18 @@ STATIC INLINE void xorbuf(void* buf, const void* mask, word32 count) /* Make sure compiler doesn't skip */ STATIC INLINE void ForceZero(const void* mem, word32 len) { +#ifdef WOLFCRYPT_FORCEZERO_BYTE volatile byte* z = (volatile byte*)mem; while (len--) *z++ = 0; +#else + volatile word64 *z = (volatile word64 *)mem; + volatile byte *b; + + while (len >= sizeof(word64)) { *z++ = 0; len -= sizeof(word64); } + b = (volatile byte *)z; + while (len--) *b++ = 0; +#endif } diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index d64a8936b..c28183778 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -371,6 +371,11 @@ static int RsaMGF(int type, byte* seed, word32 seedSz, byte* out, break; #endif #ifndef NO_SHA256 + #ifdef WOLFSSL_SHA224 + case WC_MGF1SHA224: + ret = RsaMGF1(WC_HASH_TYPE_SHA224, seed, seedSz, out, outSz, heap); + break; + #endif case WC_MGF1SHA256: ret = RsaMGF1(WC_HASH_TYPE_SHA256, seed, seedSz, out, outSz, heap); break; diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index 04ce8e0cb..462d001a2 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -49,7 +49,27 @@ int wc_Sha256Final(Sha256* sha, byte* out) return Sha256Final_fips(sha, out); } +#if defined(WOLFSSL_SHA224) +int wc_InitSha224(Sha224* sha) +{ + return InitSha224_fips(sha); +} + + +int wc_Sha224Update(Sha224* sha, const byte* data, word32 len) +{ + return Sha224Update_fips(sha, data, len); +} + + +int wc_Sha224Final(Sha224* sha, byte* out) +{ + return Sha224Final_fips(sha, out); +} + + +#endif /* WOLFSSL_SHA224 */ #else /* else build without fips */ #if !defined(NO_SHA256) && defined(WOLFSSL_TI_HASH) @@ -219,7 +239,7 @@ static int set_cpuid_flags(void) { } -/* #if defined(HAVE_INTEL_AVX1/2) at the tail of sha512 */ +/* #if defined(HAVE_INTEL_AVX1/2) at the tail of sha256 */ static int Transform(Sha256* sha256); #if defined(HAVE_INTEL_AVX1) @@ -441,7 +461,7 @@ static INLINE void AddLength(Sha256* sha256, word32 len) sha256->hiLen++; /* carry low to high */ } -int wc_Sha256Update(Sha256* sha256, const byte* data, word32 len) +static INLINE int Sha256Update(Sha256* sha256, const byte* data, word32 len) { /* do block size increments */ @@ -479,7 +499,12 @@ int wc_Sha256Update(Sha256* sha256, const byte* data, word32 len) return 0; } -int wc_Sha256Final(Sha256* sha256, byte* hash) +int wc_Sha256Update(Sha256* sha256, const byte* data, word32 len) +{ + return Sha256Update(sha256, data, len); +} + +static INLINE int Sha256Final(Sha256* sha256) { byte* local = (byte*)sha256->buffer; int ret; @@ -537,7 +562,14 @@ int wc_Sha256Final(Sha256* sha256, byte* hash) 2 * sizeof(word32)); #endif - ret = XTRANSFORM(sha256, local); + return XTRANSFORM(sha256, local); +} + +int wc_Sha256Final(Sha256* sha256, byte* hash) +{ + int ret; + + ret = Sha256Final(sha256); if (ret != 0) return ret; @@ -550,8 +582,6 @@ int wc_Sha256Final(Sha256* sha256, byte* hash) } - - #if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2) #define _DigestToReg(S_0, S_1, S_2, S_3, S_4, S_5, S_6, S_7 )\ @@ -1733,6 +1763,50 @@ static int Transform_AVX2(Sha256* sha256) #endif /* HAVE_INTEL_AVX2 */ +#ifdef WOLFSSL_SHA224 +int wc_InitSha224(Sha224* sha224) +{ + sha224->digest[0] = 0xc1059ed8; + sha224->digest[1] = 0x367cd507; + sha224->digest[2] = 0x3070dd17; + sha224->digest[3] = 0xf70e5939; + sha224->digest[4] = 0xffc00b31; + sha224->digest[5] = 0x68581511; + sha224->digest[6] = 0x64f98fa7; + sha224->digest[7] = 0xbefa4fa4; + + sha224->buffLen = 0; + sha224->loLen = 0; + sha224->hiLen = 0; + +#if defined(HAVE_INTEL_AVX1)|| defined(HAVE_INTEL_AVX2) + set_Transform() ; +#endif + + return 0; +} + +int wc_Sha224Update(Sha224* sha224, const byte* data, word32 len) +{ + return Sha256Update((Sha256 *)sha224, data, len); +} + + +int wc_Sha224Final(Sha224* sha224, byte* hash) +{ + int ret = Sha256Final((Sha256 *)sha224); + if (ret != 0) + return ret; + + #if defined(LITTLE_ENDIAN_ORDER) + ByteReverseWords(sha224->digest, sha224->digest, SHA224_DIGEST_SIZE); + #endif + XMEMCPY(hash, sha224->digest, SHA224_DIGEST_SIZE); + + return wc_InitSha224(sha224); /* reset state */ +} +#endif /* WOLFSSL_SHA224 */ + #endif /* HAVE_FIPS */ #endif /* WOLFSSL_TI_HAHS */ diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index f610bb722..8b83b75fb 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -173,11 +173,13 @@ int md2_test(void); int md5_test(void); int md4_test(void); int sha_test(void); +int sha224_test(void); int sha256_test(void); int sha512_test(void); int sha384_test(void); int hmac_md5_test(void); int hmac_sha_test(void); +int hmac_sha224_test(void); int hmac_sha256_test(void); int hmac_sha384_test(void); int hmac_sha512_test(void); @@ -371,6 +373,13 @@ int wolfcrypt_test(void* args) printf( "SHA test passed!\n"); #endif +#ifdef WOLFSSL_SHA224 + if ( (ret = sha224_test()) != 0) + return err_sys("SHA-224 test failed!\n", ret); + else + printf( "SHA-224 test passed!\n"); +#endif + #ifndef NO_SHA256 if ( (ret = sha256_test()) != 0) return err_sys("SHA-256 test failed!\n", ret); @@ -421,6 +430,13 @@ int wolfcrypt_test(void* args) printf( "HMAC-SHA test passed!\n"); #endif + #ifdef WOLFSSL_SHA224 + if ( (ret = hmac_sha224_test()) != 0) + return err_sys("HMAC-SHA224 test failed!\n", ret); + else + printf( "HMAC-SHA224 test passed!\n"); + #endif + #ifndef NO_SHA256 if ( (ret = hmac_sha256_test()) != 0) return err_sys("HMAC-SHA256 test failed!\n", ret); @@ -1127,6 +1143,53 @@ int blake2b_test(void) #endif /* HAVE_BLAKE2 */ +#ifdef WOLFSSL_SHA224 +int sha224_test(void) +{ + Sha224 sha; + byte hash[SHA224_DIGEST_SIZE]; + + testVector a, b; + testVector test_sha[2]; + int ret; + int times = sizeof(test_sha) / sizeof(struct testVector), i; + + a.input = "abc"; + a.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2\x55" + "\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7"; + a.inLen = XSTRLEN(a.input); + a.outLen = SHA224_DIGEST_SIZE; + + b.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; + b.output = "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01" + "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25"; + b.inLen = XSTRLEN(b.input); + b.outLen = SHA224_DIGEST_SIZE; + + test_sha[0] = a; + test_sha[1] = b; + + ret = wc_InitSha224(&sha); + if (ret != 0) + return -4005; + + for (i = 0; i < times; ++i) { + ret = wc_Sha224Update(&sha, (byte*)test_sha[i].input,(word32)test_sha[i].inLen); + if (ret != 0) + return -4006; + ret = wc_Sha224Final(&sha, hash); + if (ret != 0) + return -4007; + + if (XMEMCMP(hash, test_sha[i].output, SHA224_DIGEST_SIZE) != 0) + return -10 - i; + } + + return 0; +} +#endif + + #ifndef NO_SHA256 int sha256_test(void) { @@ -1442,6 +1505,84 @@ int hmac_sha_test(void) #endif +#if !defined(NO_HMAC) && defined(WOLFSSL_SHA224) +int hmac_sha224_test(void) +{ + Hmac hmac; + byte hash[SHA224_DIGEST_SIZE]; + + const char* keys[]= + { + "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" + "\x0b\x0b\x0b", + "Jefe", + "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA" + "\xAA\xAA\xAA" + }; + + testVector a, b, c; + testVector test_hmac[3]; + + int ret; + int times = sizeof(test_hmac) / sizeof(testVector), i; + + a.input = "Hi There"; + a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3" + "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22"; + a.inLen = XSTRLEN(a.input); + a.outLen = SHA224_DIGEST_SIZE; + + b.input = "what do ya want for nothing?"; + b.output = "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d" + "\x0f\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44"; + b.inLen = XSTRLEN(b.input); + b.outLen = SHA224_DIGEST_SIZE; + + c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" + "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" + "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" + "\xDD\xDD\xDD\xDD\xDD\xDD"; + c.output = "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2" + "\x64\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea"; + c.inLen = XSTRLEN(c.input); + c.outLen = SHA224_DIGEST_SIZE; + + test_hmac[0] = a; + test_hmac[1] = b; + test_hmac[2] = c; + + for (i = 0; i < times; ++i) { +#if defined(HAVE_FIPS) || defined(HAVE_CAVIUM) + if (i == 1) + continue; /* cavium can't handle short keys, fips not allowed */ +#endif +#ifdef WOLFSSL_ASYNC_CRYPT + if (wc_HmacAsyncInit(&hmac, devId) != 0) + return -20011; +#endif + ret = wc_HmacSetKey(&hmac, SHA224, (byte*)keys[i],(word32)XSTRLEN(keys[i])); + if (ret != 0) + return -4021; + ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input, + (word32)test_hmac[i].inLen); + if (ret != 0) + return -4022; + ret = wc_HmacFinal(&hmac, hash); + if (ret != 0) + return -4023; + + if (XMEMCMP(hash, test_hmac[i].output, SHA224_DIGEST_SIZE) != 0) + return -20 - i; +#ifdef WOLFSSL_ASYNC_CRYPT + wc_HmacAsyncFree(&hmac); +#endif + } + + return 0; +} +#endif + + #if !defined(NO_HMAC) && !defined(NO_SHA256) int hmac_sha256_test(void) { @@ -6352,6 +6493,26 @@ int openssl_test(void) #endif /* NO_SHA */ +#ifdef WOLFSSL_SHA224 + + e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi" + "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; + e.output = "\xc9\x7c\xa9\xa5\x59\x85\x0c\xe9\x7a\x04\xa9\x6d\xef\x6d\x99" + "\xa9\xe0\xe0\xe2\xab\x14\xe6\xb8\xdf\x26\x5f\xc0\xb3"; + e.inLen = XSTRLEN(e.input); + e.outLen = SHA224_DIGEST_SIZE; + + EVP_MD_CTX_init(&md_ctx); + EVP_DigestInit(&md_ctx, EVP_sha224()); + + EVP_DigestUpdate(&md_ctx, e.input, (unsigned long)e.inLen); + EVP_DigestFinal(&md_ctx, hash, 0); + + if (XMEMCMP(hash, e.output, SHA224_DIGEST_SIZE) != 0) + return -79; + +#endif /* WOLFSSL_SHA224 */ + d.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; d.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60" diff --git a/wolfssl/openssl/evp.h b/wolfssl/openssl/evp.h index f972d2594..e13e60ed1 100644 --- a/wolfssl/openssl/evp.h +++ b/wolfssl/openssl/evp.h @@ -60,6 +60,7 @@ typedef char WOLFSSL_EVP_CIPHER; WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_md5(void); #endif WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha1(void); +WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha224(void); WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha256(void); WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha384(void); WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha512(void); @@ -83,6 +84,9 @@ typedef union { WOLFSSL_MD5_CTX md5; #endif WOLFSSL_SHA_CTX sha; + #ifdef WOLFSSL_SHA224 + WOLFSSL_SHA224_CTX sha224; + #endif WOLFSSL_SHA256_CTX sha256; #ifdef WOLFSSL_SHA384 WOLFSSL_SHA384_CTX sha384; @@ -217,6 +221,7 @@ typedef WOLFSSL_EVP_CIPHER_CTX EVP_CIPHER_CTX; #define EVP_md5 wolfSSL_EVP_md5 #endif #define EVP_sha1 wolfSSL_EVP_sha1 +#define EVP_sha224 wolfSSL_EVP_sha224 #define EVP_sha256 wolfSSL_EVP_sha256 #define EVP_sha384 wolfSSL_EVP_sha384 #define EVP_sha512 wolfSSL_EVP_sha512 diff --git a/wolfssl/openssl/sha.h b/wolfssl/openssl/sha.h index 7f8b0ebd6..a881a0bd0 100644 --- a/wolfssl/openssl/sha.h +++ b/wolfssl/openssl/sha.h @@ -44,6 +44,31 @@ typedef WOLFSSL_SHA_CTX SHA_CTX; #define SHA1_Final wolfSSL_SHA1_Final +#ifdef WOLFSSL_SHA224 + +typedef struct WOLFSSL_SHA224_CTX { + long long holder[28]; /* big enough, but check on init */ +} WOLFSSL_SHA224_CTX; + +WOLFSSL_API void wolfSSL_SHA224_Init(WOLFSSL_SHA224_CTX*); +WOLFSSL_API void wolfSSL_SHA224_Update(WOLFSSL_SHA224_CTX*, const void*, + unsigned long); +WOLFSSL_API void wolfSSL_SHA224_Final(unsigned char*, WOLFSSL_SHA224_CTX*); + +enum { + SHA224_DIGEST_LENGTH = 28 +}; + + +typedef WOLFSSL_SHA224_CTX SHA224_CTX; + +#define SHA224_Init wolfSSL_SHA224_Init +#define SHA224_Update wolfSSL_SHA224_Update +#define SHA224_Final wolfSSL_SHA224_Final + +#endif /* WOLFSSL_SHA224 */ + + typedef struct WOLFSSL_SHA256_CTX { int holder[28]; /* big enough to hold wolfcrypt sha, but check on init */ } WOLFSSL_SHA256_CTX; @@ -54,7 +79,7 @@ WOLFSSL_API void wolfSSL_SHA256_Update(WOLFSSL_SHA256_CTX*, const void*, WOLFSSL_API void wolfSSL_SHA256_Final(unsigned char*, WOLFSSL_SHA256_CTX*); enum { - SHA256_DIGEST_LENGTH = 32 + SHA256_DIGEST_LENGTH = 32 }; @@ -77,7 +102,7 @@ WOLFSSL_API void wolfSSL_SHA384_Update(WOLFSSL_SHA384_CTX*, const void*, WOLFSSL_API void wolfSSL_SHA384_Final(unsigned char*, WOLFSSL_SHA384_CTX*); enum { - SHA384_DIGEST_LENGTH = 48 + SHA384_DIGEST_LENGTH = 48 }; @@ -101,7 +126,7 @@ WOLFSSL_API void wolfSSL_SHA512_Update(WOLFSSL_SHA512_CTX*, const void*, WOLFSSL_API void wolfSSL_SHA512_Final(unsigned char*, WOLFSSL_SHA512_CTX*); enum { - SHA512_DIGEST_LENGTH = 64 + SHA512_DIGEST_LENGTH = 64 }; @@ -117,7 +142,7 @@ typedef WOLFSSL_SHA512_CTX SHA512_CTX; #ifdef __cplusplus - } /* extern "C" */ + } /* extern "C" */ #endif diff --git a/wolfssl/wolfcrypt/asn.h b/wolfssl/wolfcrypt/asn.h index 53ca27f55..d628211a7 100644 --- a/wolfssl/wolfcrypt/asn.h +++ b/wolfssl/wolfcrypt/asn.h @@ -221,6 +221,7 @@ enum Hash_Sum { MD2h = 646, MD5h = 649, SHAh = 88, + SHA224h = 417, SHA256h = 414, SHA384h = 415, SHA512h = 416 diff --git a/wolfssl/wolfcrypt/asn_public.h b/wolfssl/wolfcrypt/asn_public.h index 1a38aa01d..c9d95459d 100644 --- a/wolfssl/wolfcrypt/asn_public.h +++ b/wolfssl/wolfcrypt/asn_public.h @@ -63,6 +63,8 @@ enum Ctc_SigType { CTC_MD5wRSA = 648, CTC_SHAwRSA = 649, CTC_SHAwECDSA = 520, + CTC_SHA224wRSA = 658, + CTC_SHA224wECDSA = 527, CTC_SHA256wRSA = 655, CTC_SHA256wECDSA = 524, CTC_SHA384wRSA = 656, diff --git a/wolfssl/wolfcrypt/hash.h b/wolfssl/wolfcrypt/hash.h index 1296c56f5..4c06ea7ea 100644 --- a/wolfssl/wolfcrypt/hash.h +++ b/wolfssl/wolfcrypt/hash.h @@ -36,6 +36,7 @@ enum wc_HashType { WC_HASH_TYPE_MD4 = 2, WC_HASH_TYPE_MD5 = 3, WC_HASH_TYPE_SHA = 4, /* SHA-1 (not old SHA-0) */ + WC_HASH_TYPE_SHA224 = 9, WC_HASH_TYPE_SHA256 = 5, WC_HASH_TYPE_SHA384 = 6, WC_HASH_TYPE_SHA512 = 7, @@ -50,6 +51,8 @@ enum wc_HashType { #define WC_MAX_DIGEST_SIZE SHA384_DIGEST_SIZE #elif !defined(NO_SHA256) #define WC_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE +#elif defined(WOLFSSL_SHA224) + #define WC_MAX_DIGEST_SIZE SHA224_DIGEST_SIZE #elif !defined(NO_SHA) #define WC_MAX_DIGEST_SIZE SHA_DIGEST_SIZE #elif !defined(NO_MD5) @@ -101,6 +104,12 @@ WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*); #else #define wc_Sha256Free(d) #endif + + #if defined(WOLFSSL_SHA224) + WOLFSSL_API int wc_Sha224GetHash(Sha224*, byte*); + WOLFSSL_API int wc_Sha224Hash(const byte*, word32, byte*); + #define wc_Sha224Free(d) + #endif /* defined(WOLFSSL_SHA224) */ #endif #ifdef WOLFSSL_SHA512 diff --git a/wolfssl/wolfcrypt/hmac.h b/wolfssl/wolfcrypt/hmac.h index 46f0b6079..2a71d2689 100644 --- a/wolfssl/wolfcrypt/hmac.h +++ b/wolfssl/wolfcrypt/hmac.h @@ -36,7 +36,7 @@ #include #endif -#ifndef NO_SHA256 +#if !defined(NO_SHA256) || defined(WOLFSSL_SHA224) #include #endif @@ -88,6 +88,9 @@ enum { #ifndef HAVE_BLAKE2 BLAKE2B_ID = 7, #endif +#ifndef WOLFSSL_SHA384 + SHA256 = 8, +#endif /* Select the largest available hash for the buffer size. */ #if defined(WOLFSSL_SHA512) @@ -102,6 +105,9 @@ enum { #elif !defined(NO_SHA256) MAX_DIGEST_SIZE = SHA256_DIGEST_SIZE, HMAC_BLOCK_SIZE = SHA256_BLOCK_SIZE +#elif defined(WOLFSSL_SHA224) + MAX_DIGEST_SIZE = SHA224_DIGEST_SIZE, + HMAC_BLOCK_SIZE = SHA224_BLOCK_SIZE #elif !defined(NO_SHA) MAX_DIGEST_SIZE = SHA_DIGEST_SIZE, HMAC_BLOCK_SIZE = SHA_BLOCK_SIZE @@ -122,6 +128,9 @@ typedef union { #ifndef NO_SHA Sha sha; #endif + #ifdef WOLFSSL_SHA224 + Sha224 sha224; + #endif #ifndef NO_SHA256 Sha256 sha256; #endif diff --git a/wolfssl/wolfcrypt/integer.h b/wolfssl/wolfcrypt/integer.h index 3aa808b88..c965330ea 100644 --- a/wolfssl/wolfcrypt/integer.h +++ b/wolfssl/wolfcrypt/integer.h @@ -199,6 +199,8 @@ typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat); /* ---> Basic Manipulations <--- */ #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO) +#define mp_isone(a) \ + (((((a)->used == 1)) && ((a)->dp[0] == 1u)) ? MP_YES : MP_NO) #define mp_iseven(a) \ (((a)->used > 0 && (((a)->dp[0] & 1u) == 0u)) ? MP_YES : MP_NO) #define mp_isodd(a) \ diff --git a/wolfssl/wolfcrypt/rsa.h b/wolfssl/wolfcrypt/rsa.h index 79b787014..9db159ce0 100644 --- a/wolfssl/wolfcrypt/rsa.h +++ b/wolfssl/wolfcrypt/rsa.h @@ -135,6 +135,7 @@ WOLFSSL_API int wc_RsaSetRNG(RsaKey* key, WC_RNG* rng); /* Mask Generation Function Identifiers */ #define WC_MGF1NONE 0 #define WC_MGF1SHA1 26 +#define WC_MGF1SHA224 4 #define WC_MGF1SHA256 1 #define WC_MGF1SHA384 2 #define WC_MGF1SHA512 3 diff --git a/wolfssl/wolfcrypt/sha256.h b/wolfssl/wolfcrypt/sha256.h index 503db7f2a..f460a6e26 100644 --- a/wolfssl/wolfcrypt/sha256.h +++ b/wolfssl/wolfcrypt/sha256.h @@ -76,6 +76,26 @@ WOLFSSL_API int wc_InitSha256(Sha256*); WOLFSSL_API int wc_Sha256Update(Sha256*, const byte*, word32); WOLFSSL_API int wc_Sha256Final(Sha256*, byte*); +#if defined(WOLFSSL_SHA224) + +#ifndef HAVE_FIPS /* avoid redefinition of structs */ +/* in bytes */ +enum { + SHA224 = 8, /* hash type unique */ + SHA224_BLOCK_SIZE = SHA256_BLOCK_SIZE, + SHA224_DIGEST_SIZE = 28, + SHA224_PAD_SIZE = SHA256_PAD_SIZE +}; + +typedef Sha256 Sha224; +#endif /* HAVE_FIPS */ + +WOLFSSL_API int wc_InitSha224(Sha224*); +WOLFSSL_API int wc_Sha224Update(Sha224*, const byte*, word32); +WOLFSSL_API int wc_Sha224Final(Sha224*, byte*); + +#endif /* WOLFSSL_SHA224 */ + #ifdef __cplusplus } /* extern "C" */ #endif From 45983c3b3223fd82209020376095c043d3648491 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Fri, 11 Nov 2016 12:17:32 +1000 Subject: [PATCH 2/6] Fix SHA224 enum in HMAC code --- wolfssl/wolfcrypt/hmac.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wolfssl/wolfcrypt/hmac.h b/wolfssl/wolfcrypt/hmac.h index 2a71d2689..1d4930664 100644 --- a/wolfssl/wolfcrypt/hmac.h +++ b/wolfssl/wolfcrypt/hmac.h @@ -88,8 +88,8 @@ enum { #ifndef HAVE_BLAKE2 BLAKE2B_ID = 7, #endif -#ifndef WOLFSSL_SHA384 - SHA256 = 8, +#ifndef WOLFSSL_SHA224 + SHA224 = 8, #endif /* Select the largest available hash for the buffer size. */ From 9e81261f1e9c58f744149c276c833a73a62d26bf Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Fri, 11 Nov 2016 16:11:16 +1000 Subject: [PATCH 3/6] Fixes --- cyassl/ctaocrypt/sha256.h | 7 +++++++ wolfssl/wolfcrypt/sha256.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cyassl/ctaocrypt/sha256.h b/cyassl/ctaocrypt/sha256.h index d875e3138..8f9f40f5e 100644 --- a/cyassl/ctaocrypt/sha256.h +++ b/cyassl/ctaocrypt/sha256.h @@ -35,6 +35,13 @@ #define Sha256Final wc_Sha256Final #define Sha256Hash wc_Sha256Hash +#ifdef WOLFSSL_SHA224 + #define InitSha224 wc_InitSha224 + #define Sha224Update wc_Sha224Update + #define Sha224Final wc_Sha224Final + #define Sha224Hash wc_Sha224Hash +#endif + #endif /* CTAO_CRYPT_SHA256_H */ #endif /* NO_SHA256 */ diff --git a/wolfssl/wolfcrypt/sha256.h b/wolfssl/wolfcrypt/sha256.h index f460a6e26..f0109c4ea 100644 --- a/wolfssl/wolfcrypt/sha256.h +++ b/wolfssl/wolfcrypt/sha256.h @@ -76,7 +76,7 @@ WOLFSSL_API int wc_InitSha256(Sha256*); WOLFSSL_API int wc_Sha256Update(Sha256*, const byte*, word32); WOLFSSL_API int wc_Sha256Final(Sha256*, byte*); -#if defined(WOLFSSL_SHA224) +#ifdef WOLFSSL_SHA224 #ifndef HAVE_FIPS /* avoid redefinition of structs */ /* in bytes */ From abcd6af512b9d3a6be012b05ce9eac8eec31452f Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Fri, 11 Nov 2016 16:29:34 +1000 Subject: [PATCH 4/6] Disable SHA-224 in FIPS --- configure.ac | 45 ++++++++++++++++++++++---------------------- wolfcrypt/src/hash.c | 2 +- wolfcrypt/src/hmac.c | 2 +- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/configure.ac b/configure.ac index d5a88098a..f8ea63ab6 100644 --- a/configure.ac +++ b/configure.ac @@ -747,28 +747,6 @@ fi AM_CONDITIONAL([BUILD_SHA512], [test "x$ENABLED_SHA512" = "xyes"]) -# set sha224 default -SHA224_DEFAULT=no -if test "$host_cpu" = "x86_64" -then -SHA224_DEFAULT=yes -fi - -# SHA224 -AC_ARG_ENABLE([sha224], - [AS_HELP_STRING([--enable-sha224],[Enable wolfSSL SHA-224 support (default: enabled on x86_64)])], - [ ENABLED_SHA224=$enableval ], - [ ENABLED_SHA224=$SHA224_DEFAULT ] - ) - -if test "$ENABLED_SHA224" = "yes" -then - AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SHA224" -fi - -AM_CONDITIONAL([BUILD_SHA224], [test "x$ENABLED_SHA224" = "xyes"]) - - # SESSION CERTS AC_ARG_ENABLE([sessioncerts], [ --enable-sessioncerts Enable session cert storing (default: disabled)], @@ -1547,6 +1525,29 @@ fi AM_CONDITIONAL([BUILD_FIPS], [test "x$ENABLED_FIPS" = "xyes"]) +# set sha224 default +SHA224_DEFAULT=no +if test "$host_cpu" = "x86_64" +then + SHA224_DEFAULT=yes +fi +SHA224_DEFAULT=$ENABLED_FIPS + +# SHA224 +AC_ARG_ENABLE([sha224], + [AS_HELP_STRING([--enable-sha224],[Enable wolfSSL SHA-224 support (default: enabled on x86_64)])], + [ ENABLED_SHA224=$enableval ], + [ ENABLED_SHA224=$SHA224_DEFAULT ] + ) + +if test "$ENABLED_SHA224" = "yes" +then + AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SHA224" +fi + +AM_CONDITIONAL([BUILD_SHA224], [test "x$ENABLED_SHA224" = "xyes"]) + + # set POLY1305 default POLY1305_DEFAULT=yes diff --git a/wolfcrypt/src/hash.c b/wolfcrypt/src/hash.c index d06ad59e5..62d9468a6 100644 --- a/wolfcrypt/src/hash.c +++ b/wolfcrypt/src/hash.c @@ -186,7 +186,7 @@ int wc_Hash(enum wc_HashType hash_type, const byte* data, #endif break; case WC_HASH_TYPE_SHA224: -#ifdef WOLFSSL_SHA512 +#ifdef WOLFSSL_SHA224 ret = wc_Sha224Hash(data, data_len, hash); #endif break; diff --git a/wolfcrypt/src/hmac.c b/wolfcrypt/src/hmac.c index 7e4070ef2..7c42977c3 100644 --- a/wolfcrypt/src/hmac.c +++ b/wolfcrypt/src/hmac.c @@ -124,7 +124,7 @@ int wc_HmacSizeByType(int type) return SHA_DIGEST_SIZE; #endif - #ifndef WOLF_SHA224 + #ifdef WOLF_SHA224 case SHA224: return SHA224_DIGEST_SIZE; #endif From 478f279b3cadbf3ee9598520c2ca2baa58c0e389 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Fri, 11 Nov 2016 16:38:28 +1000 Subject: [PATCH 5/6] Fix logic --- configure.ac | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index f8ea63ab6..ee8d9822c 100644 --- a/configure.ac +++ b/configure.ac @@ -1529,9 +1529,11 @@ AM_CONDITIONAL([BUILD_FIPS], [test "x$ENABLED_FIPS" = "xyes"]) SHA224_DEFAULT=no if test "$host_cpu" = "x86_64" then - SHA224_DEFAULT=yes + if test "x$ENABLED_FIPS" = "xno" + then + SHA224_DEFAULT=yes + fi fi -SHA224_DEFAULT=$ENABLED_FIPS # SHA224 AC_ARG_ENABLE([sha224], From 9b0d53ba5058c7429e08d9750e7423f2c6bb284b Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Sat, 12 Nov 2016 09:52:07 +1000 Subject: [PATCH 6/6] Fixes from review Remove ForceZero changes (better version in another pull request) Remove SHA-224 APIs for FIPS (algorithm not avaialable in FIPS. --- wolfcrypt/src/misc.c | 9 --------- wolfcrypt/src/sha256.c | 21 --------------------- 2 files changed, 30 deletions(-) diff --git a/wolfcrypt/src/misc.c b/wolfcrypt/src/misc.c index 0dcf50536..99dc2abeb 100644 --- a/wolfcrypt/src/misc.c +++ b/wolfcrypt/src/misc.c @@ -183,18 +183,9 @@ STATIC INLINE void xorbuf(void* buf, const void* mask, word32 count) /* Make sure compiler doesn't skip */ STATIC INLINE void ForceZero(const void* mem, word32 len) { -#ifdef WOLFCRYPT_FORCEZERO_BYTE volatile byte* z = (volatile byte*)mem; while (len--) *z++ = 0; -#else - volatile word64 *z = (volatile word64 *)mem; - volatile byte *b; - - while (len >= sizeof(word64)) { *z++ = 0; len -= sizeof(word64); } - b = (volatile byte *)z; - while (len--) *b++ = 0; -#endif } diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index 462d001a2..715b97176 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -49,27 +49,6 @@ int wc_Sha256Final(Sha256* sha, byte* out) return Sha256Final_fips(sha, out); } -#if defined(WOLFSSL_SHA224) - -int wc_InitSha224(Sha224* sha) -{ - return InitSha224_fips(sha); -} - - -int wc_Sha224Update(Sha224* sha, const byte* data, word32 len) -{ - return Sha224Update_fips(sha, data, len); -} - - -int wc_Sha224Final(Sha224* sha, byte* out) -{ - return Sha224Final_fips(sha, out); -} - - -#endif /* WOLFSSL_SHA224 */ #else /* else build without fips */ #if !defined(NO_SHA256) && defined(WOLFSSL_TI_HASH)