summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2020-12-02 18:30:55 +0100
committerRichard Levitte <levitte@openssl.org>2020-12-16 11:56:38 +0100
commita2e145f8dbf064b56f793fc77b3ccd79f7c67689 (patch)
treeffa00af5cda2df173609fe362f9119092f9842cf
parentc2403f362efc519e473269d183adc7cceddb8c54 (diff)
Add necessary checks of OPENSSL_NO_DH, OPENSSL_NO_DSA and OPENSSL_NO_EC
When OpenSSL is configured with 'no-dh', 'no-dsa' and 'no-ec' combined, some static functions have no use, which the compiler may complain about. We therefore add extra guards to silence it. Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> (Merged from https://github.com/openssl/openssl/pull/13589)
-rw-r--r--providers/implementations/encode_decode/encode_key2any.c7
-rw-r--r--test/endecode_test.c12
-rw-r--r--test/evp_pkey_dparams_test.c32
3 files changed, 30 insertions, 21 deletions
diff --git a/providers/implementations/encode_decode/encode_key2any.c b/providers/implementations/encode_decode/encode_key2any.c
index 30837612cc..ee2930852e 100644
--- a/providers/implementations/encode_decode/encode_key2any.c
+++ b/providers/implementations/encode_decode/encode_key2any.c
@@ -36,6 +36,10 @@
#include "prov/der_rsa.h"
#include "endecoder_local.h"
+#if defined(OPENSSL_NO_DH) && defined(OPENSSL_NO_DSA) && defined(OPENSSL_NO_EC)
+# define OPENSSL_NO_KEYPARAMS
+#endif
+
struct key2any_ctx_st {
PROV_CTX *provctx;
@@ -330,8 +334,7 @@ static int key_to_type_specific_pem_pub_bio(BIO *out, const void *key,
p2s, k2d, ctx, NULL, NULL);
}
-#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA) \
- || !defined(OPENSSL_NO_EC)
+#ifndef OPENSSL_NO_KEYPARAMS
static int key_to_type_specific_pem_param_bio(BIO *out, const void *key,
int key_nid, const char *pemname,
key_to_paramstring_fn *p2s,
diff --git a/test/endecode_test.c b/test/endecode_test.c
index 6e67dd1835..ad76807d4f 100644
--- a/test/endecode_test.c
+++ b/test/endecode_test.c
@@ -25,6 +25,10 @@
#include "helpers/predefined_dhparams.h"
#include "testutil.h"
+#if defined(OPENSSL_NO_DH) && defined(OPENSSL_NO_DSA) && defined(OPENSSL_NO_EC)
+# define OPENSSL_NO_KEYPARAMS
+#endif
+
#ifndef OPENSSL_NO_EC
static BN_CTX *bnctx = NULL;
static OSSL_PARAM_BLD *bld_prime_nc = NULL;
@@ -40,8 +44,7 @@ static OSSL_PARAM *ec_explicit_tri_params_explicit = NULL;
# endif
#endif
-#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA) \
- || !defined(OPENSSL_NO_EC)
+#ifndef OPENSSL_NO_KEYPARAMS
static EVP_PKEY *make_template(const char *type, OSSL_PARAM *genparams)
{
EVP_PKEY *pkey = NULL;
@@ -513,8 +516,7 @@ static int test_unprotected_via_PEM(const char *type, EVP_PKEY *key)
dump_pem, 0);
}
-#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA) \
- || !defined(OPENSSL_NO_EC)
+#ifndef OPENSSL_NO_KEYPARAMS
static int check_params_DER(const char *type, const void *data, size_t data_len)
{
const unsigned char *datap = data;
@@ -569,7 +571,7 @@ static int test_params_via_PEM(const char *type, EVP_PKEY *key)
test_text, check_params_PEM,
dump_pem, 0);
}
-#endif /* ndef(OPENSSL_NO_DH) || ndef(OPENSSL_NO_DSA) || ndef(OPENSSL_NO_EC) */
+#endif /* !OPENSSL_NO_KEYPARAMS */
static int check_unprotected_legacy_PEM(const char *type,
const void *data, size_t data_len)
diff --git a/test/evp_pkey_dparams_test.c b/test/evp_pkey_dparams_test.c
index b8e9493dca..2b6bd31a66 100644
--- a/test/evp_pkey_dparams_test.c
+++ b/test/evp_pkey_dparams_test.c
@@ -21,7 +21,12 @@
#include <openssl/ec.h>
#include "testutil.h"
-#ifndef OPENSSL_NO_DH
+#if defined(OPENSSL_NO_DH) && defined(OPENSSL_NO_DSA) && defined(OPENSSL_NO_EC)
+# define OPENSSL_NO_KEYPARAMS
+#endif
+
+#ifndef OPENSSL_NO_KEYPARAMS
+# ifndef OPENSSL_NO_DH
static const unsigned char dhparam_bin[] = {
0x30,0x82,0x01,0x08,0x02,0x82,0x01,0x01,0x00,0xc0,0xd1,0x2e,0x14,0x18,0xbd,0x03,
0xfd,0x39,0xe1,0x99,0xf4,0x93,0x06,0x2d,0x49,0xc6,0xb5,0xb9,0xf0,0x91,0xcb,0x2f,
@@ -41,9 +46,9 @@ static const unsigned char dhparam_bin[] = {
0x06,0x7f,0x7f,0xd7,0x7b,0x42,0x5b,0xba,0x93,0x7a,0xeb,0x43,0x5f,0xce,0x59,0x26,
0xe8,0x76,0xdc,0xee,0xe2,0xbe,0x36,0x7a,0x83,0x02,0x01,0x02
};
-#endif
+# endif
-#ifndef OPENSSL_NO_DSA
+# ifndef OPENSSL_NO_DSA
static const unsigned char dsaparam_bin[] = {
0x30,0x82,0x02,0x28,0x02,0x82,0x01,0x01,0x00,0xf2,0x85,0x01,0xa5,0xb9,0x56,0x65,
0x19,0xff,0x9a,0x7d,0xf9,0x90,0xd6,0xaa,0x73,0xac,0xf7,0x94,0xfa,0x8a,0x64,0x6d,
@@ -81,29 +86,28 @@ static const unsigned char dsaparam_bin[] = {
0x22,0x15,0xc1,0x8b,0x04,0xb9,0x8a,0xa8,0xb7,0x1b,0x62,0x44,0xc6,0xef,0x4b,0x74,
0xd0,0xfd,0xa9,0xb4,0x4e,0xdd,0x7d,0x38,0x60,0xd1,0x40,0xcd
};
-#endif
+# endif
-#ifndef OPENSSL_NO_EC
+# ifndef OPENSSL_NO_EC
static const unsigned char ecparam_bin[] = {
0x06,0x08,0x2a,0x86,0x48,0xce,0x3d,0x03,0x01,0x07
};
-#endif
+# endif
-#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
static const struct {
int type;
const unsigned char *param_bin;
size_t param_bin_len;
} pkey_params [] = {
-#ifndef OPENSSL_NO_DH
+# ifndef OPENSSL_NO_DH
{ EVP_PKEY_DH, dhparam_bin, sizeof(dhparam_bin) },
-#endif
-#ifndef OPENSSL_NO_DSA
+# endif
+# ifndef OPENSSL_NO_DSA
{ EVP_PKEY_DSA, dsaparam_bin, sizeof(dsaparam_bin) },
-#endif
-#ifndef OPENSSL_NO_EC
+# endif
+# ifndef OPENSSL_NO_EC
{ EVP_PKEY_EC, ecparam_bin, sizeof(ecparam_bin) }
-#endif
+# endif
};
static int params_bio_test(int id)
@@ -140,7 +144,7 @@ static int params_bio_test(int id)
int setup_tests(void)
{
-#if defined(OPENSSL_NO_DH) && defined(OPENSSL_NO_DSA) && defined(OPENSSL_NO_EC)
+#ifdef OPENSSL_NO_KEYPARAMS
TEST_note("No DH/DSA/EC support");
#else
ADD_ALL_TESTS(params_bio_test, OSSL_NELEM(pkey_params));