From d01d25598515feeed356d6dd94d8e5142def76e5 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 10 Jan 2018 09:26:22 -0800 Subject: [PATCH] FIPS Update 1. When configuring FIPSv2, force enable RSA-PSS and ECC. 2. Add more checks for FIPSv2 around the code. --- configure.ac | 11 ++++++++++- wolfcrypt/src/rsa.c | 2 +- wolfcrypt/test/test.c | 6 ++++-- wolfssl/wolfcrypt/asn.h | 3 ++- wolfssl/wolfcrypt/ecc.h | 5 ----- wolfssl/wolfcrypt/rsa.h | 16 ++++++++++++---- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 828b52c40..2185d022a 100644 --- a/configure.ac +++ b/configure.ac @@ -1935,7 +1935,16 @@ then # Add the FIPS flag. AS_IF([test "x$FIPS_VERSION" = "xv2"], [AM_CFLAGS="$AM_CFLAGS -DHAVE_FIPS_VERSION=2 -DWOLFSSL_KEY_GEN" - ENABLED_KEYGEN="yes"]) + ENABLED_KEYGEN="yes" + AS_IF([test "x$ENABLED_RSAPSS" != "xyes"], + [ENABLED_RSAPSS="yes" + AM_CFLAGS="$AM_CFLAGS -DWC_RSA_PSS"]) + AS_IF([test "x$ENABLED_ECC" != "xyes"], + [ENABLED_ECC="yes" + AM_CFLAGS="$AM_CFLAGS -DHAVE_ECC -DTFM_ECC256" + AS_IF([test "x$ENABLED_ECC_SHAMIR" = "xyes"], + [AM_CFLAGS="$AM_CFLAGS -DECC_SHAMIR"])]) + ]) else if test "x$ENABLED_FORTRESS" = "xyes" then diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index a53a36863..cf7f7d3e8 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -186,7 +186,7 @@ int wc_RsaFlattenPublicKey(RsaKey* key, byte* a, word32* aSz, byte* b, * wc_RsaPublicKeyDecode */ -#else /* else build without fips */ +#else /* else build without fips, or for new fips */ #include #include diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 1731a6726..0fdf7f388 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -7248,7 +7248,8 @@ static int rsa_flatten_test(RsaKey* key) * -101 = USER_CRYPTO_ERROR */ if (ret == 0) -#elif defined(HAVE_FIPS) +#elif defined(HAVE_FIPS) && \ + (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2)) if (ret != 0) #else if (ret != RSA_BUFFER_E) @@ -8048,7 +8049,8 @@ int rsa_test(void) #ifndef WC_NO_RSA_OAEP /* OAEP padding testing */ #if !defined(HAVE_FAST_RSA) && !defined(HAVE_USER_RSA) && \ - !defined(HAVE_FIPS) + (!defined(HAVE_FIPS) || \ + (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) #ifndef NO_SHA XMEMSET(plain, 0, plainSz); diff --git a/wolfssl/wolfcrypt/asn.h b/wolfssl/wolfcrypt/asn.h index 7a88482be..798a152bf 100644 --- a/wolfssl/wolfcrypt/asn.h +++ b/wolfssl/wolfcrypt/asn.h @@ -30,7 +30,8 @@ #include /* fips declare of RsaPrivateKeyDecode @wc_fips */ -#if defined(HAVE_FIPS) && !defined(NO_RSA) +#if defined(HAVE_FIPS) && !defined(NO_RSA) && \ + (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2)) #include #endif diff --git a/wolfssl/wolfcrypt/ecc.h b/wolfssl/wolfcrypt/ecc.h index 93506c5d3..9185b9f05 100644 --- a/wolfssl/wolfcrypt/ecc.h +++ b/wolfssl/wolfcrypt/ecc.h @@ -176,8 +176,6 @@ typedef enum ecc_curve_id { #endif } ecc_curve_id; -#if !defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2) - #ifdef HAVE_OID_ENCODING typedef word16 ecc_oid_t; #else @@ -204,7 +202,6 @@ typedef struct ecc_set_type { int cofactor; } ecc_set_type; -#endif #ifdef ALT_ECC_SIZE @@ -265,7 +262,6 @@ typedef struct alt_fp_int { #endif /* ALT_ECC_SIZE */ -#if !defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2) /* A point on an ECC curve, stored in Jacbobian format such that (x,y,z) => (x/z^2, y/z^3, 1) when interpreted as affine */ typedef struct { @@ -323,7 +319,6 @@ struct ecc_key { typedef struct ecc_key ecc_key; #define WC_ECCKEY_TYPE_DEFINED #endif -#endif /* ECC predefined curve sets */ diff --git a/wolfssl/wolfcrypt/rsa.h b/wolfssl/wolfcrypt/rsa.h index 8749a9c8f..47d6dc5ae 100644 --- a/wolfssl/wolfcrypt/rsa.h +++ b/wolfssl/wolfcrypt/rsa.h @@ -39,7 +39,8 @@ #include "user_rsa.h" #else -#ifdef HAVE_FIPS +#if defined(HAVE_FIPS) && \ + (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2)) /* for fips @wc_fips */ #include #if defined(CYASSL_KEY_GEN) && !defined(WOLFSSL_KEY_GEN) @@ -48,7 +49,11 @@ #else #include #include -#endif /* HAVE_FIPS */ +#endif /* HAVE_FIPS && HAVE_FIPS_VERION 1 */ +#if defined(HAVE_FIPS) && \ + defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2) +#include +#endif /* header file needed for OAEP padding */ #include @@ -62,7 +67,8 @@ #endif /* avoid redefinition of structs */ -#if !defined(HAVE_FIPS) +#if !defined(HAVE_FIPS) || \ + (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) #ifdef WOLFSSL_ASYNC_CRYPT #include @@ -180,7 +186,9 @@ WOLFSSL_API int wc_RsaPSS_CheckPadding_ex(const byte* in, word32 inLen, WOLFSSL_API int wc_RsaEncryptSize(RsaKey* key); -#ifndef HAVE_FIPS /* to avoid asn duplicate symbols @wc_fips */ +#if !defined(HAVE_FIPS) || \ + (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) +/* to avoid asn duplicate symbols @wc_fips */ WOLFSSL_API int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey*, word32); WOLFSSL_API int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx,