Skip to content

Commit

Permalink
Various cleanups and fixes:
Browse files Browse the repository at this point in the history
* Fix to properly set configure.ac LMS/XMSS enables and build of those code files.
* Remove duplicate aes.c `wc_AesSetKeyLocal` call to `wc_AesSetIV`. Moved earlier in function in commit a10260c.
* Benchmark missing time.h with NO_ASN_TIME.
* Added option to support disabling AES CFB 1/8 `WOLFSSL_NO_AES_CFB_1_8`.
* Fixes for building with combinations of `WOLFSSL_RSA_VERIFY_ONLY` and `WOLFSSL_RSA_PUBLIC_ONLY`.
* Fix for building `--enable-stacksize=verbose` with single threaded.
* Various tab and formatting cleanups.
ZD 18996
  • Loading branch information
dgarske committed Dec 7, 2024
1 parent 1bfbdb6 commit 017f931
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 41 deletions.
12 changes: 6 additions & 6 deletions IDE/GCC-ARM/Source/benchmark_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ int main(void)
{
int ret;
#ifndef NO_CRYPT_BENCHMARK
wolfCrypt_Init();
wolfCrypt_Init();

printf("\nBenchmark Test\n");
benchmark_test(&args);
printf("\nBenchmark Test\n");
benchmark_test(&args);
ret = args.return_code;
printf("Benchmark Test: Return code %d\n", ret);
printf("Benchmark Test: Return code %d\n", ret);

wolfCrypt_Cleanup();
wolfCrypt_Cleanup();
#else
ret = NOT_COMPILED_IN;
#endif
return ret;
return ret;
}
12 changes: 6 additions & 6 deletions IDE/GCC-ARM/Source/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ int main(void)
{
int ret;
#ifndef NO_CRYPT_TEST
wolfCrypt_Init();
wolfCrypt_Init();

printf("\nCrypt Test\n");
wolfcrypt_test(&args);
printf("\nCrypt Test\n");
wolfcrypt_test(&args);
ret = args.return_code;
printf("Crypt Test: Return code %d\n", ret);
printf("Crypt Test: Return code %d\n", ret);

wolfCrypt_Cleanup();
wolfCrypt_Cleanup();
#else
ret = NOT_COMPILED_IN;
#endif
return ret;
return ret;
}
4 changes: 3 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,7 @@ then
fi

# XMSS
ENABLED_WC_XMSS=no
AC_ARG_ENABLE([xmss],
[AS_HELP_STRING([--enable-xmss],[Enable stateful XMSS/XMSS^MT signatures (default: disabled)])],
[ ENABLED_XMSS=$enableval ],
Expand Down Expand Up @@ -1583,6 +1584,7 @@ then
fi

# LMS
ENABLED_WC_LMS=no
AC_ARG_ENABLE([lms],
[AS_HELP_STRING([--enable-lms],[Enable stateful LMS/HSS signatures (default: disabled)])],
[ ENABLED_LMS=$enableval ],
Expand Down Expand Up @@ -4524,7 +4526,7 @@ fi

if test "$ENABLED_STACKSIZE" = "verbose"
then
if test "$thread_ls_on" != "yes"
if test "$thread_ls_on" != "yes" && test "x$ENABLED_SINGLETHREADED" = "xno"
then
AC_MSG_ERROR(stacksize-verbose needs thread-local storage.)
fi
Expand Down
1 change: 1 addition & 0 deletions wolfcrypt/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -14657,6 +14657,7 @@ void bench_sphincsKeySign(byte level, byte optim)

#else

#include <time.h>
#include <sys/time.h>

double current_time(int reset)
Expand Down
8 changes: 4 additions & 4 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4662,8 +4662,6 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
}
#endif

ret = wc_AesSetIV(aes, iv);

#if defined(WOLFSSL_DEVCRYPTO) && \
(defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC))
aes->ctx.cfd = -1;
Expand Down Expand Up @@ -11909,7 +11907,8 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackDecrypt(

/* consume any unused bytes left in aes->tmp */
processed = min(aes->left, sz);
xorbufout(out, in, (byte*)aes->tmp + WC_AES_BLOCK_SIZE - aes->left, processed);
xorbufout(out, in, (byte*)aes->tmp + WC_AES_BLOCK_SIZE - aes->left,
processed);
aes->left -= processed;
out += processed;
in += processed;
Expand Down Expand Up @@ -12003,7 +12002,7 @@ int wc_AesCfbDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
}
#endif /* HAVE_AES_DECRYPT */


#ifndef WOLFSSL_NO_AES_CFB_1_8
/* shift the whole WC_AES_BLOCK_SIZE array left by 8 or 1 bits */
static void shiftLeftArray(byte* ary, byte shift)
{
Expand Down Expand Up @@ -12221,6 +12220,7 @@ int wc_AesCfb8Decrypt(Aes* aes, byte* out, const byte* in, word32 sz)
return wc_AesFeedbackCFB8(aes, out, in, sz, AES_DECRYPTION);
}
#endif /* HAVE_AES_DECRYPT */
#endif /* !WOLFSSL_NO_AES_CFB_1_8 */
#endif /* WOLFSSL_AES_CFB */

#ifdef WOLFSSL_AES_OFB
Expand Down
3 changes: 2 additions & 1 deletion wolfcrypt/src/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -3110,7 +3110,8 @@ int cc310_RsaSSL_Verify(const byte* in, word32 inLen, byte* sig,
#endif /* WOLFSSL_CRYPTOCELL */

#ifndef WOLF_CRYPTO_CB_ONLY_RSA
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(TEST_UNPAD_CONSTANT_TIME) && !defined(NO_RSA_BOUNDS_CHECK)
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(TEST_UNPAD_CONSTANT_TIME) && \
!defined(NO_RSA_BOUNDS_CHECK)
/* Check that 1 < in < n-1. (Requirement of 800-56B.) */
int RsaFunctionCheckIn(const byte* in, word32 inLen, RsaKey* key,
int checkSmallCt)
Expand Down
61 changes: 39 additions & 22 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9926,7 +9926,9 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
return ret;
}

#if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0))
#if !defined(HAVE_SELFTEST) && \
(!defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)) && \
!defined(WOLFSSL_NO_AES_CFB_1_8)
static wc_test_ret_t aescfb1_test(void)
{
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
Expand Down Expand Up @@ -10399,7 +10401,7 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,

return ret;
}
#endif /* !HAVE_SELFTEST && !HAVE_FIPS */
#endif /* !HAVE_SELFTEST && !HAVE_FIPS && !WOLFSSL_NO_AES_CFB_1_8 */
#endif /* WOLFSSL_AES_CFB */

#ifndef HAVE_RENESAS_SYNC
Expand Down Expand Up @@ -14269,7 +14271,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void)
ret = aescfb_test_0();
if (ret != 0)
return ret;
#if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
#if !defined(HAVE_SELFTEST) && \
(!defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)) && \
!defined(WOLFSSL_NO_AES_CFB_1_8)
ret = aescfb1_test();
if (ret != 0)
return ret;
Expand Down Expand Up @@ -21853,8 +21857,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
#endif

#if !defined(WC_NO_RNG) && !defined(WC_NO_RSA_OAEP) && \
((!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
defined(WOLFSSL_PUBLIC_MP)) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
!defined(WOLFSSL_RSA_VERIFY_ONLY) && defined(WOLFSSL_PUBLIC_MP) && \
!defined(WOLF_CRYPTO_CB_ONLY_RSA)
idx = (word32)ret;
XMEMSET(plain, 0, plainSz);
do {
Expand Down Expand Up @@ -54595,17 +54599,20 @@ static wc_test_ret_t mp_test_shift(mp_int* a, mp_int* r1, WC_RNG* rng)
return WC_TEST_RET_ENC_EC(ret);
for (i = 0; i < 4; i++) {
mp_copy(r1, a);
#if !defined(NO_DH) || defined(HAVE_ECC) || (!defined(NO_RSA) && \
defined(WC_RSA_BLINDING) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
ret = mp_lshd(r1, i);
if (ret != MP_OKAY)
return WC_TEST_RET_ENC_EC(ret);
#ifndef WOLFSSL_SP_MATH
#ifndef WOLFSSL_SP_MATH
mp_rshd(r1, i);
#else
#else
mp_rshb(r1, i * SP_WORD_SIZE);
#endif
#endif
ret = mp_cmp(a, r1);
if (ret != MP_EQ)
return WC_TEST_RET_ENC_NC;
#endif
}
#ifndef WOLFSSL_SP_MATH
for (i = 0; i < DIGIT_BIT+1; i++) {
Expand Down Expand Up @@ -54970,7 +54977,7 @@ static wc_test_ret_t mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng)
mp_zero(NULL);

#if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
!defined(WOLFSSL_RSA_VERIFY_ONLY)
!defined(WOLFSSL_RSA_PUBLIC_ONLY)
ret = mp_lshd(NULL, 0);
if (ret != WC_NO_ERR_TRACE(MP_VAL))
return WC_TEST_RET_ENC_EC(ret);
Expand Down Expand Up @@ -55299,7 +55306,8 @@ static wc_test_ret_t mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng)
return WC_TEST_RET_ENC_EC(ret);
#endif

#if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
#if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
ret = mp_invmod(NULL, NULL, NULL);
if (ret != WC_NO_ERR_TRACE(MP_VAL))
Expand Down Expand Up @@ -56002,7 +56010,8 @@ static wc_test_ret_t mp_test_cmp(mp_int* a, mp_int* b)
return 0;
}

#if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
#if !defined(NO_DH) || defined(HAVE_ECC) || (!defined(NO_RSA) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY))
static wc_test_ret_t mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng)
{
wc_test_ret_t ret;
Expand Down Expand Up @@ -56071,9 +56080,8 @@ static wc_test_ret_t mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng)
}
#endif

#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
#if !defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY))
static wc_test_ret_t mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem,
WC_RNG* rng)
{
Expand Down Expand Up @@ -56624,8 +56632,9 @@ static wc_test_ret_t mp_test_mul_sqr(mp_int* a, mp_int* b, mp_int* r1, mp_int* r
return 0;
}

#if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
defined(OPENSSL_EXTRA)
#if (!defined(NO_RSA) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
static wc_test_ret_t mp_test_invmod(mp_int* a, mp_int* m, mp_int* r)
{
wc_test_ret_t ret;
Expand Down Expand Up @@ -57026,7 +57035,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void)
#endif
WOLFSSL_ENTER("mp_test");

#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || !defined(NO_DH) || defined(HAVE_ECC)
ret = mp_init_multi(a, b, r1, r2, NULL, NULL);
#else
ret = mp_init(a);
ret |= mp_init(b);
ret |= mp_init(r1);
ret |= mp_init(r2);
#endif
if (ret != 0)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);

Expand Down Expand Up @@ -57234,17 +57250,17 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void)
#endif
if ((ret = mp_test_cmp(a, r1)) != 0)
goto done;
#if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
#if !defined(NO_DH) || defined(HAVE_ECC) || (!defined(NO_RSA) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY))
if ((ret = mp_test_shbd(a, b, &rng)) != 0)
goto done;
#endif
#if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
if ((ret = mp_test_set_is_bit(a)) != 0)
goto done;
#endif
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
#if !defined(NO_DH) || defined(HAVE_ECC) || \
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY))
if ((ret = mp_test_div(a, b, r1, r2, &rng)) != 0)
goto done;
#endif
Expand All @@ -57269,8 +57285,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void)
#endif
if ((ret = mp_test_mul_sqr(a, b, r1, r2, &rng)) != 0)
goto done;
#if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
defined(OPENSSL_EXTRA)
#if (!defined(NO_RSA) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
if ((ret = mp_test_invmod(a, b, r1)) != 0)
goto done;
#endif
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ typedef struct w64wrapper {
#endif

#ifdef SINGLE_THREADED
#if defined(WC_32BIT_CPU)
#if defined(WC_32BIT_CPU) || defined(HAVE_STACK_SIZE)
typedef void* THREAD_RETURN;
#else
typedef unsigned int THREAD_RETURN;
Expand Down

0 comments on commit 017f931

Please sign in to comment.