From 89c85a89668b0797225d1b16346c44d11e94bec1 Mon Sep 17 00:00:00 2001 From: David Garske Date: Mon, 4 Dec 2023 12:57:56 -0800 Subject: [PATCH] Fix compiler warnings from mingw. --- src/internal.c | 35 +++++++++++++++++------------------ tests/pkcs11mtt.c | 2 ++ tests/pkcs11str.c | 2 ++ tests/pkcs11test.c | 2 ++ 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/internal.c b/src/internal.c index 01f4635..714f423 100644 --- a/src/internal.c +++ b/src/internal.c @@ -53,6 +53,11 @@ #endif #endif +#if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ + (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) +#define WOLFPKCS11_NEED_RSA_RNG +#endif + /* Size of hash calculated from PIN. */ #define PIN_HASH_SZ 32 /* Size of seed used when calculating hash from PIN. */ @@ -6503,26 +6508,23 @@ int WP11_RsaPkcs15_PrivateDecrypt(unsigned char* in, word32 inLen, WP11_Object* priv, WP11_Slot* slot) { int ret = 0; -#if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) +#ifdef WOLFPKCS11_NEED_RSA_RNG WC_RNG rng; #endif /* A random number generator is needed for blinding. */ if (priv->onToken) WP11_Lock_LockRW(priv->lock); -#if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) +#ifdef WOLFPKCS11_NEED_RSA_RNG ret = Rng_New(&slot->token.rng, &slot->token.rngLock, &rng); - if (ret == 0) { - priv->data.rsaKey.rng = &rng; - } #endif if (ret == 0) { + #ifdef WOLFPKCS11_NEED_RSA_RNG + priv->data.rsaKey.rng = &rng; + #endif ret = wc_RsaPrivateDecrypt_ex(in, inLen, out, *outLen, &priv->data.rsaKey, WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0); - #if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) + #ifdef WOLFPKCS11_NEED_RSA_RNG priv->data.rsaKey.rng = NULL; Rng_Free(&rng); #endif @@ -6607,28 +6609,25 @@ int WP11_RsaOaep_PrivateDecrypt(unsigned char* in, word32 inLen, int ret = 0; WP11_OaepParams* oaep = &session->params.oaep; WP11_Slot* slot = WP11_Session_GetSlot(session); -#if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) +#ifdef WOLFPKCS11_NEED_RSA_RNG WC_RNG rng; #endif /* A random number generator is needed for blinding. */ if (priv->onToken) WP11_Lock_LockRW(priv->lock); -#if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) +#ifdef WOLFPKCS11_NEED_RSA_RNG ret = Rng_New(&slot->token.rng, &slot->token.rngLock, &rng); - if (ret == 0) { - priv->data.rsaKey.rng = &rng; - } #endif if (ret == 0) { + #ifdef WOLFPKCS11_NEED_RSA_RNG + priv->data.rsaKey.rng = &rng; + #endif ret = wc_RsaPrivateDecrypt_ex(in, inLen, out, *outLen, &priv->data.rsaKey, WC_RSA_OAEP_PAD, oaep->hashType, oaep->mgf, oaep->label, oaep->labelSz); - #if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) + #ifdef WOLFPKCS11_NEED_RSA_RNG priv->data.rsaKey.rng = NULL; Rng_Free(&rng); #endif diff --git a/tests/pkcs11mtt.c b/tests/pkcs11mtt.c index 97c31e0..71d37eb 100644 --- a/tests/pkcs11mtt.c +++ b/tests/pkcs11mtt.c @@ -40,6 +40,8 @@ #include "unit.h" #include "testdata.h" +#include /* setenv/getenv */ + #define PKCS11MTT_CASE(func) \ TEST_CASE(func, 0, pkcs11_open_session, pkcs11_close_session, \ sizeof(CK_SESSION_HANDLE)) diff --git a/tests/pkcs11str.c b/tests/pkcs11str.c index 2b3c9a5..7fc3995 100644 --- a/tests/pkcs11str.c +++ b/tests/pkcs11str.c @@ -35,6 +35,8 @@ #include "testdata.h" +#include /* setenv/getenv */ + int verbose = 0; #ifdef DEBUG_WOLFPKCS11 diff --git a/tests/pkcs11test.c b/tests/pkcs11test.c index f05bfbc..aa1963f 100644 --- a/tests/pkcs11test.c +++ b/tests/pkcs11test.c @@ -36,6 +36,8 @@ #include "unit.h" #include "testdata.h" +#include /* setenv/getenv */ + #define TEST_FLAG_INIT 0x01 #define TEST_FLAG_TOKEN 0x02