From cdbeb9970c8c45b20f7dcae5f79b6665f242163a Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Mon, 20 Oct 2025 14:31:34 -0700 Subject: [PATCH] Add pre-compiler checks for different config options --- include/wolfprovider/settings.h | 10 +++++----- src/wp_aes_stream.c | 4 ++++ test/test_dh.c | 4 ++++ test/test_rsa.c | 6 ++++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/include/wolfprovider/settings.h b/include/wolfprovider/settings.h index a98f0487..3fec9821 100644 --- a/include/wolfprovider/settings.h +++ b/include/wolfprovider/settings.h @@ -127,19 +127,19 @@ #ifdef HAVE_ECC #define WP_HAVE_ECC #ifndef NO_ECC_SECP - #if defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES) + #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192 #define WP_HAVE_EC_P192 #endif - #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES) + #if (defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224 #define WP_HAVE_EC_P224 #endif - #if defined(HAVE_ECC256) || defined(HAVE_ALL_CURVES) + #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256 #define WP_HAVE_EC_P256 #endif - #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES) + #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384 #define WP_HAVE_EC_P384 #endif - #if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES) + #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521 #define WP_HAVE_EC_P521 #endif #endif diff --git a/src/wp_aes_stream.c b/src/wp_aes_stream.c index 549ba4d7..f07214d9 100644 --- a/src/wp_aes_stream.c +++ b/src/wp_aes_stream.c @@ -331,7 +331,11 @@ static int wp_aes_stream_init(wp_AesStreamCtx *ctx, const unsigned char *key, /* TODO: don't reach in under the covers. * Setting the key will reset this. */ +#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \ + defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS) || \ + defined(WOLFSSL_AES_CTS) ctx->aes.left = 0; +#endif } if (ok) { diff --git a/test/test_dh.c b/test/test_dh.c index bc9fce29..42dcb459 100644 --- a/test/test_dh.c +++ b/test/test_dh.c @@ -555,10 +555,12 @@ static int test_dh_krb5_keygen_ex(OSSL_LIB_CTX *libCtx) OSSL_DECODER_CTX *dctx = NULL; const unsigned char *inptr = dh_2048; size_t inlen = sizeof(dh_2048); +#ifdef WOLFSSL_DH_EXTRA unsigned char *spki = NULL; size_t spki_len = 0; unsigned char *der = NULL; size_t der_len; +#endif /* WOLFSSL_DH_EXTRA */ PRINT_MSG("Testing DH key generation with krb5 parameters"); @@ -584,6 +586,7 @@ static int test_dh_krb5_keygen_ex(OSSL_LIB_CTX *libCtx) err = EVP_PKEY_keygen(ctx, &key) != 1; } +#ifdef WOLFSSL_DH_EXTRA if (err == 0) { /* Get the size of the encoded public key */ err = i2d_PUBKEY(key, NULL) <= 0; @@ -618,6 +621,7 @@ static int test_dh_krb5_keygen_ex(OSSL_LIB_CTX *libCtx) if (spki) { OPENSSL_free(spki); } +#endif /* WOLFSSL_DH_EXTRA */ EVP_PKEY_free(key); EVP_PKEY_free(params); EVP_PKEY_CTX_free(ctx); diff --git a/test/test_rsa.c b/test/test_rsa.c index f84638f5..c7042121 100644 --- a/test/test_rsa.c +++ b/test/test_rsa.c @@ -20,6 +20,7 @@ #include "unit.h" #include +#include #include #include @@ -1063,7 +1064,8 @@ int test_rsa_pkey_keygen(void *data) BIGNUM *eCmd = NULL; BIGNUM *n = NULL; BIGNUM *eKey = NULL; -#if defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION) +#if defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION) || \ + (defined(RSA_MIN_SIZE) && RSA_MIN_SIZE >= 2048) /* Generating a 3072-bit key is slow, so only do it if we have to because * we're using wolfCrypt FIPS. Can't do 2048 because that's the default. */ const int newKeySize = 3072; @@ -1096,7 +1098,7 @@ int test_rsa_pkey_keygen(void *data) err = BN_set_word(eCmd, 3) != 1; } if (err == 0) { - PRINT_MSG("Change the public exponent w/ ctrl command"); + PRINT_MSG("Change the public exponent w/ ctrl command"); err = EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, eCmd) <= 0; }