From 1d33876d3733064a5b8b31c392d8ab5df435e781 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 12 Feb 2024 14:18:26 +0100 Subject: [PATCH] Fix some preprocessor guards Fix the build in some configurations. Signed-off-by: Gilles Peskine --- library/pk.c | 3 +-- tests/suites/test_suite_pk.function | 18 ++++++++++-------- tests/suites/test_suite_pkparse.function | 6 ++++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/library/pk.c b/library/pk.c index f623af999..28663a828 100644 --- a/library/pk.c +++ b/library/pk.c @@ -784,8 +784,7 @@ static int import_public_into_psa(const mbedtls_pk_context *pk, size_t from_bits = 0; psa_ecc_family_t from_family = mbedtls_ecc_group_to_psa(ec->grp.id, &from_bits); - psa_key_type_t to_type = psa_get_key_type(attributes); - if (to_type != PSA_KEY_TYPE_ECC_PUBLIC_KEY(from_family)) { + if (psa_type != PSA_KEY_TYPE_ECC_PUBLIC_KEY(from_family)) { return MBEDTLS_ERR_PK_TYPE_MISMATCH; } int ret = mbedtls_ecp_write_public_key( diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function index 5d0ee1a46..76713649a 100644 --- a/tests/suites/test_suite_pk.function +++ b/tests/suites/test_suite_pk.function @@ -114,11 +114,6 @@ #if defined(MBEDTLS_TEST_PSA_ECC_ONE_FAMILY) #define MBEDTLS_TEST_PSA_ECC_AT_LEAST_ONE_CURVE -#else -/* Always define the macros so that we can use them in test data. */ -#define MBEDTLS_TEST_PSA_ECC_ONE_FAMILY 0 -#define MBEDTLS_PSA_ECC_ONE_CURVE_BITS 0 -#define MBEDTLS_TEST_ECP_DP_ONE_CURVE 0 #endif /* Pick a second curve, for tests that need two supported curves of the @@ -136,13 +131,20 @@ #define MBEDTLS_TEST_PSA_ECC_ANOTHER_FAMILY PSA_ECC_FAMILY_SECP_K1 #define MBEDTLS_PSA_ECC_ONE_CURVE_BITS 256 #define MBEDTLS_TEST_PSA_ECC_HAVE_TWO_FAMILIES -#else -/* Always define the macros so that we can use them in test data. */ -#define MBEDTLS_TEST_PSA_ECC_ANOTHER_FAMILY 0 #endif #endif /* defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) */ +/* Always define the macros so that we can use them in test data. */ +#if !defined(MBEDTLS_TEST_PSA_ECC_ONE_FAMILY) +#define MBEDTLS_TEST_PSA_ECC_ONE_FAMILY 0 +#define MBEDTLS_PSA_ECC_ONE_CURVE_BITS 0 +#define MBEDTLS_TEST_ECP_DP_ONE_CURVE 0 +#endif +#if !defined(MBEDTLS_TEST_PSA_ECC_ANOTHER_FAMILY) +#define MBEDTLS_TEST_PSA_ECC_ANOTHER_FAMILY 0 +#endif + #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) static int pk_genkey_ec(mbedtls_pk_context *pk, mbedtls_ecp_group_id grp_id) { diff --git a/tests/suites/test_suite_pkparse.function b/tests/suites/test_suite_pkparse.function index 6c904a397..3227ce9ac 100644 --- a/tests/suites/test_suite_pkparse.function +++ b/tests/suites/test_suite_pkparse.function @@ -14,7 +14,7 @@ #define HAVE_mbedtls_pk_parse_key_pkcs8_encrypted_der #endif -#if defined(MBEDTLS_PSA_CRYPTO_C) +#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_FS_IO) static int test_psa_bridge(const mbedtls_pk_context *ctx, psa_key_usage_t usage_flag) { @@ -62,6 +62,7 @@ exit: return ok; } +#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) /* Whether a pk key can do ECDSA. Opaque keys are not supported since this * test suite does not create opaque keys. */ static int pk_can_ecdsa(const mbedtls_pk_context *ctx) @@ -80,7 +81,8 @@ static int pk_can_ecdsa(const mbedtls_pk_context *ctx) return 0; #endif } -#endif /* MBEDTLS_PSA_CRYPTO_C */ +#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ +#endif /* MBEDTLS_PSA_CRYPTO_C && && MBEDTLS_FS_IO */ /* END_HEADER */