diff --git a/configure.ac b/configure.ac index e725b311a..836d02299 100644 --- a/configure.ac +++ b/configure.ac @@ -2110,7 +2110,7 @@ AM_CONDITIONAL([BUILD_SHA224], [test "x$ENABLED_SHA224" = "xyes"]) SHA3_DEFAULT=no if test "$host_cpu" = "x86_64" || test "$host_cpu" = "aarch64" then - if test "x$ENABLED_FIPS" = "xno" + if test "x$ENABLED_FIPS" = "xno" || test "x$FIPS_VERSION" = "xv2" then SHA3_DEFAULT=yes fi diff --git a/src/include.am b/src/include.am index 67fc6b610..fa400a411 100644 --- a/src/include.am +++ b/src/include.am @@ -60,6 +60,10 @@ if BUILD_SHA512 src_libwolfssl_la_SOURCES += ctaocrypt/src/sha512.c endif +if BUILD_FIPS_V2 +src_libwolfssl_la_SOURCES += wolfcrypt/src/sha3.c +endif + src_libwolfssl_la_SOURCES += ctaocrypt/src/fips.c src_libwolfssl_la_SOURCES += wolfcrypt/src/fipsv2.c src_libwolfssl_la_SOURCES += ctaocrypt/src/fips_test.c @@ -150,9 +154,11 @@ if BUILD_SHA512 src_libwolfssl_la_SOURCES += wolfcrypt/src/sha512.c endif +if !BUILD_FIPS_V2 if BUILD_SHA3 src_libwolfssl_la_SOURCES += wolfcrypt/src/sha3.c endif +endif src_libwolfssl_la_SOURCES += \ wolfcrypt/src/logging.c \ diff --git a/wolfcrypt/src/sha3.c b/wolfcrypt/src/sha3.c index 3cf7bb157..82305c903 100644 --- a/wolfcrypt/src/sha3.c +++ b/wolfcrypt/src/sha3.c @@ -31,128 +31,6 @@ #include #include -/* fips wrapper calls, user can call direct */ -#ifdef HAVE_FIPS - - int wc_InitSha3_224(wc_Sha3* sha, void* heap, int devId) - { - (void)heap; - (void)devId; - if (sha == NULL) { - return BAD_FUNC_ARG; - } - return InitSha3_224_fips(sha); - } - int wc_Sha3_224_Update(wc_Sha3* sha, const byte* data, word32 len) - { - if (sha == NULL || (data == NULL && len > 0)) { - return BAD_FUNC_ARG; - } - return Sha3_224_Update_fips(sha, data, len); - } - int wc_Sha3_224_Final(wc_Sha3* sha, byte* out) - { - if (sha == NULL || out == NULL) { - return BAD_FUNC_ARG; - } - return Sha3_224_Final_fips(sha, out); - } - void wc_Sha3_224_Free(wc_Sha3* sha) - { - (void)sha; - /* Not supported in FIPS */ - } - - int wc_InitSha3_256(wc_Sha3* sha, void* heap, int devId) - { - (void)heap; - (void)devId; - if (sha == NULL) { - return BAD_FUNC_ARG; - } - return InitSha3_256_fips(sha); - } - int wc_Sha3_256_Update(wc_Sha3* sha, const byte* data, word32 len) - { - if (sha == NULL || (data == NULL && len > 0)) { - return BAD_FUNC_ARG; - } - return Sha3_256_Update_fips(sha, data, len); - } - int wc_Sha3_256_Final(wc_Sha3* sha, byte* out) - { - if (sha == NULL || out == NULL) { - return BAD_FUNC_ARG; - } - return Sha3_256_Final_fips(sha, out); - } - void wc_Sha3_256_Free(wc_Sha3* sha) - { - (void)sha; - /* Not supported in FIPS */ - } - - int wc_InitSha3_384(wc_Sha3* sha, void* heap, int devId) - { - (void)heap; - (void)devId; - if (sha == NULL) { - return BAD_FUNC_ARG; - } - return InitSha3_384_fips(sha); - } - int wc_Sha3_384_Update(wc_Sha3* sha, const byte* data, word32 len) - { - if (sha == NULL || (data == NULL && len > 0)) { - return BAD_FUNC_ARG; - } - return Sha3_384_Update_fips(sha, data, len); - } - int wc_Sha3_384_Final(wc_Sha3* sha, byte* out) - { - if (sha == NULL || out == NULL) { - return BAD_FUNC_ARG; - } - return Sha3_384_Final_fips(sha, out); - } - void wc_Sha3_384_Free(wc_Sha3* sha) - { - (void)sha; - /* Not supported in FIPS */ - } - - int wc_InitSha3_512(wc_Sha3* sha, void* heap, int devId) - { - (void)heap; - (void)devId; - if (sha == NULL) { - return BAD_FUNC_ARG; - } - return InitSha3_512_fips(sha); - } - int wc_Sha3_512_Update(wc_Sha3* sha, const byte* data, word32 len) - { - if (sha == NULL || (data == NULL && len > 0)) { - return BAD_FUNC_ARG; - } - return Sha3_512_Update_fips(sha, data, len); - } - int wc_Sha3_512_Final(wc_Sha3* sha, byte* out) - { - if (sha == NULL || out == NULL) { - return BAD_FUNC_ARG; - } - return Sha3_512_Final_fips(sha, out); - } - void wc_Sha3_512_Free(wc_Sha3* sha) - { - (void)sha; - /* Not supported in FIPS */ - } - -#else /* else build without fips */ - - #ifdef NO_INLINE #include #else @@ -870,7 +748,7 @@ static void wc_Sha3Free(wc_Sha3* sha3) wolfAsync_DevCtxFree(&sha3->asyncDev, WOLFSSL_ASYNC_MARKER_SHA3); #endif /* WOLFSSL_ASYNC_CRYPT */ } -#endif /* HAVE_FIPS */ + /* Copy the state of the SHA3 operation. * diff --git a/wolfssl/wolfcrypt/sha3.h b/wolfssl/wolfcrypt/sha3.h index 7f725e670..39c950960 100644 --- a/wolfssl/wolfcrypt/sha3.h +++ b/wolfssl/wolfcrypt/sha3.h @@ -29,15 +29,13 @@ #ifdef HAVE_FIPS /* for fips @wc_fips */ - #include + #include #endif #ifdef __cplusplus extern "C" { #endif -#ifndef HAVE_FIPS /* avoid redefinition of structs */ - #ifdef WOLFSSL_ASYNC_CRYPT #include #endif @@ -100,7 +98,7 @@ typedef struct Sha3 { #endif /* WOLFSSL_ASYNC_CRYPT */ } wc_Sha3; #endif -#endif /* HAVE_FIPS */ + WOLFSSL_API int wc_InitSha3_224(wc_Sha3*, void*, int); WOLFSSL_API int wc_Sha3_224_Update(wc_Sha3*, const byte*, word32);