pk: minor fixes (guards and a wrong assignment)
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
diff --git a/include/mbedtls/pk.h b/include/mbedtls/pk.h
index 4a8e50c..f2cf9fe 100644
--- a/include/mbedtls/pk.h
+++ b/include/mbedtls/pk.h
@@ -213,7 +213,8 @@
* format and use PSA functions
* - if !ECP_C then use new raw data and PSA functions directly.
*/
-#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_ECP_C)
+#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_ECP_C) && \
+ defined(MBEDTLS_ECP_LIGHT)
#define MBEDTLS_PK_USE_PSA_EC_DATA
#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_ECP_C */
@@ -290,7 +291,7 @@
size_t MBEDTLS_PRIVATE(pub_raw_len); /**< Valid bytes in "pub_raw" */
psa_ecc_family_t MBEDTLS_PRIVATE(ec_family); /**< EC family of pk */
size_t MBEDTLS_PRIVATE(ec_bits); /**< Curve's bits of pk */
-#endif /* MBEDTLS_PK_USE_PSA_EC_PUB_KEY */
+#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
} mbedtls_pk_context;
#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
diff --git a/library/debug.c b/library/debug.c
index 1868cb7..8236452 100644
--- a/library/debug.c
+++ b/library/debug.c
@@ -194,6 +194,7 @@
}
#endif /* MBEDTLS_ECP_LIGHT */
+#if defined(MBEDTLS_BIGNUM_C)
#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
void mbedtls_debug_print_psa_ec(const mbedtls_ssl_context *ssl, int level,
const char *file, int line,
@@ -240,7 +241,6 @@
}
#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
-#if defined(MBEDTLS_BIGNUM_C)
void mbedtls_debug_print_mpi(const mbedtls_ssl_context *ssl, int level,
const char *file, int line,
const char *text, const mbedtls_mpi *X)
diff --git a/library/pk.c b/library/pk.c
index 47c19b2..826c29a 100644
--- a/library/pk.c
+++ b/library/pk.c
@@ -227,7 +227,7 @@
return 0;
}
-#endif /* MBEDTLS_PK_USE_PSA_EC_PUB_KEY */
+#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
/*
diff --git a/library/pk_wrap.c b/library/pk_wrap.c
index 32d697a..376af25 100644
--- a/library/pk_wrap.c
+++ b/library/pk_wrap.c
@@ -1140,15 +1140,15 @@
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
const psa_ecc_family_t curve = prv->ec_family;
- const size_t curve_bits = PSA_BITS_TO_BYTES(prv->ec_bits);
+ const size_t curve_bits = prv->ec_bits;
#else /* !MBEDTLS_PK_USE_PSA_EC_DATA */
uint8_t pub_key_buf[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH];
size_t pub_key_len;
size_t curve_bits;
const psa_ecc_family_t curve =
mbedtls_ecc_group_to_psa(mbedtls_pk_ec_ro(*prv)->grp.id, &curve_bits);
- const size_t curve_bytes = PSA_BITS_TO_BYTES(curve_bits);
#endif /* !MBEDTLS_PK_USE_PSA_EC_DATA */
+ const size_t curve_bytes = PSA_BITS_TO_BYTES(curve_bits);
psa_set_key_type(&key_attr, PSA_KEY_TYPE_ECC_KEY_PAIR(curve));
psa_set_key_usage_flags(&key_attr, PSA_KEY_USAGE_EXPORT);