diff --git a/configure.ac b/configure.ac index 9a527a235..f55fb1592 100644 --- a/configure.ac +++ b/configure.ac @@ -2049,7 +2049,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 4a57f52d0..d5a6913c0 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 49a225088..afea56c69 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(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(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(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(Sha3* sha) - { - (void)sha; - /* Not supported in FIPS */ - } - - int wc_InitSha3_256(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(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(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(Sha3* sha) - { - (void)sha; - /* Not supported in FIPS */ - } - - int wc_InitSha3_384(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(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(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(Sha3* sha) - { - (void)sha; - /* Not supported in FIPS */ - } - - int wc_InitSha3_512(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(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(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(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(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 b6eb7dd3d..2575bb08b 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 @@ -75,7 +73,7 @@ enum { #include "wolfssl/wolfcrypt/port/xilinx/xil-sha3.h" #else /* Sha3 digest */ -typedef struct Sha3 { +struct Sha3 { /* State data that is processed for each block. */ word64 s[25]; /* Unprocessed message data. */ @@ -88,9 +86,13 @@ typedef struct Sha3 { #ifdef WOLFSSL_ASYNC_CRYPT WC_ASYNC_DEV asyncDev; #endif /* WOLFSSL_ASYNC_CRYPT */ -} Sha3; +}; #endif -#endif /* HAVE_FIPS */ +#ifndef WC_SHA3_TYPE_DEFINED + typedef struct Sha3 Sha3; + #define WC_SHA3_TYPE_DEFINED +#endif + WOLFSSL_API int wc_InitSha3_224(Sha3*, void*, int); WOLFSSL_API int wc_Sha3_224_Update(Sha3*, const byte*, word32);