diff --git a/configure.ac b/configure.ac index 11f8dd89c..51120b98f 100644 --- a/configure.ac +++ b/configure.ac @@ -2531,13 +2531,29 @@ AS_IF([test "x$ENABLED_FIPS" = "xyes" && test "x$FIPS_VERSION" != "xrand"], AC_ARG_ENABLE([selftest], [AS_HELP_STRING([--enable-selftest],[Enable selftest, Will NOT work w/o CAVP selftest license (default: disabled)])], [ ENABLED_SELFTEST=$enableval ], - [ ENABLED_SELFTEST=no ] + [ ENABLED_SELFTEST="no" ] ) -if test "x$ENABLED_SELFTEST" = "xyes" -then - AM_CFLAGS="$AM_CFLAGS -DHAVE_SELFTEST" -fi +AS_CASE([$ENABLED_SELFTEST], + ["v2"],[ + # selftest v2 (wolfCrypt 4.1.0) + ENABLED_SELFTEST="yes" + SELFTEST_VERSION="v2" + ], + ["no"],[SELFTEST_VERSION="none"], + [ + # selftest v1 (wolfCrypt 3.14.2) + ENABLED_SELFTEST="yes" + SELFTEST_VERSION="v1" + ]) + +AS_CASE([$SELFTEST_VERSION], + ["v2"],[ + AM_CFLAGS="$AM_CFLAGS -DHAVE_SELFTEST -DHAVE_SELFTEST_VERSION=2" + ], + ["v1"],[ + AM_CFLAGS="$AM_CFLAGS -DHAVE_SELFTEST" + ]) # set sha224 default diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 9201ae576..3ce4173e6 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -128,9 +128,10 @@ extern int wc_InitRsaHw(RsaKey* key); #define ERROR_OUT(err, eLabel) { ret = (err); goto eLabel; } -#if defined(HAVE_SELFTEST) || ( !defined(NO_SKID) && \ - ( !defined(HAVE_FIPS) || \ - !defined(HAVE_FIPS_VERSION) )) +#if !defined(NO_SKID) && (!defined(HAVE_FIPS) || !defined(HAVE_FIPS_VERSION)) + #if !defined(HAVE_SELFTEST) || (defined(HAVE_SELFTEST) && \ + (!defined(HAVE_SELFTEST_VERSION) || \ + HAVE_SELFTEST_VERSION < 2)) #ifndef WOLFSSL_AES_KEY_SIZE_ENUM #define WOLFSSL_AES_KEY_SIZE_ENUM enum Asn_Misc { @@ -140,6 +141,7 @@ extern int wc_InitRsaHw(RsaKey* key); AES_256_KEY_SIZE = 32 }; #endif + #endif /* HAVE_SELFTEST */ #endif #ifdef WOLFSSL_RENESAS_TSIP_TLS void tsip_inform_key_position(const word32 key_n_start, diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index d9e653a30..69ebc6d01 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -11876,7 +11876,8 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) plainSz = ret; TEST_SLEEP(); -#ifdef HAVE_SELFTEST +#if defined(HAVE_SELFTEST) && \ + (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2)) ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz, hash[j], -1); #else @@ -11951,7 +11952,8 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) WC_ASYNC_FLAG_CALL_AGAIN); #endif if (ret >= 0) { -#ifdef HAVE_SELFTEST +#if defined(HAVE_SELFTEST) && \ + (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2)) ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz, hash[0], 0); #else @@ -11980,7 +11982,8 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) plainSz = ret; TEST_SLEEP(); -#ifdef HAVE_SELFTEST +#if defined(HAVE_SELFTEST) && \ + (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2)) ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz, hash[0], 0); #else @@ -12058,7 +12061,8 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) #else len = -3; #endif -#ifdef HAVE_SELFTEST +#if defined(HAVE_SELFTEST) && \ + (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2)) ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz, hash[0], len); #else @@ -12072,7 +12076,8 @@ static int rsa_pss_test(WC_RNG* rng, RsaKey* key) #else len = plainSz - digestSz - 1; #endif -#ifdef HAVE_SELFTEST +#if defined(HAVE_SELFTEST) && \ + (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2)) ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz, hash[0], len); #else diff --git a/wolfssl/internal.h b/wolfssl/internal.h index f1d3a2868..fb48295e8 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -1358,7 +1358,8 @@ enum Misc { #endif #endif -#ifdef HAVE_SELFTEST +#if defined(HAVE_SELFTEST) && \ + (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2)) #ifndef WOLFSSL_AES_KEY_SIZE_ENUM #define WOLFSSL_AES_KEY_SIZE_ENUM AES_IV_SIZE = 16, diff --git a/wolfssl/wolfcrypt/pkcs7.h b/wolfssl/wolfcrypt/pkcs7.h index 0292d1d07..f5ea17764 100644 --- a/wolfssl/wolfcrypt/pkcs7.h +++ b/wolfssl/wolfcrypt/pkcs7.h @@ -154,8 +154,9 @@ enum Pkcs7_Misc { MAX_SEQ_SZ + ASN_NAME_MAX + MAX_SN_SZ + MAX_SEQ_SZ + MAX_ALGO_SZ + 1 + MAX_ENCRYPTED_KEY_SZ, #if (defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \ - (HAVE_FIPS_VERSION >= 2)) || defined(HAVE_SELFTEST) - /* In the event of fips cert 3389 or CAVP selftest build, these enums are + (HAVE_FIPS_VERSION >= 2)) || (defined(HAVE_SELFTEST) && \ + (!defined(HAVE_SELFTEST_VERSION) || HAVE_SELFTEST_VERSION < 2)) + /* In the event of fips cert 3389 or CAVP selftest v1 build, these enums are * not in aes.h for use with pkcs7 so enumerate it here outside the fips * boundary */ GCM_NONCE_MID_SZ = 12, /* The usual default nonce size for AES-GCM. */ diff --git a/wolfssl/wolfcrypt/sha3.h b/wolfssl/wolfcrypt/sha3.h index 47e2e2c9c..e35c9d882 100644 --- a/wolfssl/wolfcrypt/sha3.h +++ b/wolfssl/wolfcrypt/sha3.h @@ -58,7 +58,8 @@ enum { WC_SHA3_512_DIGEST_SIZE = 64, WC_SHA3_512_COUNT = 9, -#ifndef HAVE_SELFTEST +#if !defined(HAVE_SELFTEST) || \ + defined(HAVE_SELFTEST_VERSION) && (HAVE_SELFTEST_VERSION >= 2) /* These values are used for HMAC, not SHA-3 directly. * They come from from FIPS PUB 202. */ WC_SHA3_224_BLOCK_SIZE = 144,