psa_util: guard ECDSA conversion functions with proper (internal) symbol
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
diff --git a/include/mbedtls/config_adjust_legacy_crypto.h b/include/mbedtls/config_adjust_legacy_crypto.h
index 696266c..833f152 100644
--- a/include/mbedtls/config_adjust_legacy_crypto.h
+++ b/include/mbedtls/config_adjust_legacy_crypto.h
@@ -400,6 +400,13 @@
#define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
#endif
+/* psa_util file features some ECDSA conversion functions, to convert between
+ * legacy's ASN.1 DER format and PSA's raw one. */
+#if defined(MBEDTLS_ECDSA_C) || defined(MBEDTLS_PSA_CRYPTO_C) && \
+ (defined(PSA_WANT_ALG_ECDSA) || defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA))
+#define MBEDTLS_PSA_UTIL_HAVE_ECDSA
+#endif
+
/* Some internal helpers to determine which keys are availble. */
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_AES_C)) || \
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_AES))
diff --git a/include/mbedtls/psa_util.h b/include/mbedtls/psa_util.h
index 93fb38d..3bf05d1 100644
--- a/include/mbedtls/psa_util.h
+++ b/include/mbedtls/psa_util.h
@@ -182,6 +182,8 @@
}
#endif /* MBEDTLS_PSA_CRYPTO_C */
+#if defined(MBEDTLS_PSA_UTIL_HAVE_ECDSA)
+
#if defined(MBEDTLS_ASN1_WRITE_C)
/** Convert an ECDSA signature from raw format (used by PSA APIs) to DER ASN.1
* format (used by legacy crypto APIs).
@@ -220,6 +222,8 @@
size_t bits);
#endif /* MBEDTLS_ASN1_PARSE_C */
+#endif /* MBEDTLS_PSA_UTIL_HAVE_ECDSA */
+
/**@}*/
#endif /* MBEDTLS_PSA_UTIL_H */
diff --git a/library/psa_util.c b/library/psa_util.c
index ef9aff1..c78b603 100644
--- a/library/psa_util.c
+++ b/library/psa_util.c
@@ -338,6 +338,8 @@
#endif /* MBEDTLS_PSA_CRYPTO_C */
+#if defined(MBEDTLS_PSA_UTIL_HAVE_ECDSA)
+
#if defined(MBEDTLS_ASN1_WRITE_C)
/**
* \brief Convert a single raw coordinate to DER ASN.1 format. The output der
@@ -569,3 +571,5 @@
return 0;
}
#endif /* MBEDTLS_ASN1_PARSE_C */
+
+#endif /* MBEDTLS_PSA_UTIL_HAVE_ECDSA */
diff --git a/tests/suites/test_suite_psa_crypto_util.function b/tests/suites/test_suite_psa_crypto_util.function
index 3c49766..bfdafa7 100644
--- a/tests/suites/test_suite_psa_crypto_util.function
+++ b/tests/suites/test_suite_psa_crypto_util.function
@@ -3,7 +3,7 @@
#include <mbedtls/psa_util.h>
/* END_HEADER */
-/* BEGIN_CASE depends_on:MBEDTLS_ASN1_WRITE_C */
+/* BEGIN_CASE depends_on:MBEDTLS_PSA_UTIL_HAVE_ECDSA:MBEDTLS_ASN1_WRITE_C */
void ecdsa_raw_to_der(int key_bits, data_t *input, data_t *exp_result, int exp_ret)
{
unsigned char *tmp_buf = NULL;
@@ -25,7 +25,7 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_ASN1_PARSE_C */
+/* BEGIN_CASE depends_on:MBEDTLS_PSA_UTIL_HAVE_ECDSA:MBEDTLS_ASN1_PARSE_C */
void ecdsa_der_to_raw(int key_bits, data_t *input, data_t *exp_result, int exp_ret)
{
unsigned char *tmp_buf = NULL;