bignum and ASN.1 objects are built as part of the X.509 bundle keyed off the RSA and ASN.1 parser options. They are not X.509 specific: an ECDSA module needs the same objects and listing them in a second bundle would produce duplicate symbols at link time.
Add MBEDTLS_LIB_BIGNUM and MBEDTLS_LIB_ASN1 and select them from the existing users and build the objects once in the crypto bundle. Signed-off-by: Ayoub Zaki <[email protected]> --- lib/mbedtls/Kconfig | 15 +++++++++++++++ lib/mbedtls/Makefile | 15 +++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig index 789721ee6cd..63ce9360d8e 100644 --- a/lib/mbedtls/Kconfig +++ b/lib/mbedtls/Kconfig @@ -233,6 +233,19 @@ config HKDF_MBEDTLS endif # MBEDTLS_LIB_CRYPTO +config MBEDTLS_LIB_BIGNUM + bool + help + Selected by the modules that need MbedTLS multi-precision integer + arithmetic (RSA and ECP). It is a separate symbol so that the objects + are built exactly once when several of those modules are enabled. + +config MBEDTLS_LIB_ASN1 + bool + help + Selected by the modules that need the MbedTLS ASN.1 parser and + writer. See MBEDTLS_LIB_BIGNUM for why this is a separate symbol. + config MBEDTLS_LIB_X509 bool "MbedTLS certificate libraries" select ASN1_DECODER_MBEDTLS if ASN1_DECODER @@ -250,6 +263,7 @@ if MBEDTLS_LIB_X509 config ASN1_DECODER_MBEDTLS bool "ASN1 decoder with MbedTLS certificate library" depends on MBEDTLS_LIB_X509 && ASN1_DECODER + select MBEDTLS_LIB_ASN1 help This option chooses MbedTLS certificate library for ASN1 decoder. @@ -264,6 +278,7 @@ config RSA_PUBLIC_KEY_PARSER_MBEDTLS bool "RSA public key parser with MbedTLS certificate library" depends on ASYMMETRIC_PUBLIC_KEY_MBEDTLS select ASN1_DECODER_MBEDTLS + select MBEDTLS_LIB_BIGNUM help This option chooses MbedTLS certificate library for RSA public key parser. diff --git a/lib/mbedtls/Makefile b/lib/mbedtls/Makefile index c5b445bd85c..d77af928983 100644 --- a/lib/mbedtls/Makefile +++ b/lib/mbedtls/Makefile @@ -36,16 +36,19 @@ mbedtls_lib_crypto-$(CONFIG_$(PHASE_)SHA512_MBEDTLS) += \ mbedtls_lib_crypto-$(CONFIG_$(PHASE_)HKDF_MBEDTLS) += \ $(MBEDTLS_LIB_DIR)/hkdf.o -# MbedTLS X509 library -obj-$(CONFIG_$(XPL_)MBEDTLS_LIB_X509) += mbedtls_lib_x509.o -mbedtls_lib_x509-y := $(MBEDTLS_LIB_DIR)/x509.o -mbedtls_lib_x509-$(CONFIG_$(PHASE_)ASN1_DECODER_MBEDTLS) += \ +# Shared by the X509/RSA and ECDSA modules built once. +mbedtls_lib_crypto-$(CONFIG_$(PHASE_)MBEDTLS_LIB_ASN1) += \ $(MBEDTLS_LIB_DIR)/asn1parse.o \ $(MBEDTLS_LIB_DIR)/asn1write.o \ $(MBEDTLS_LIB_DIR)/oid.o -mbedtls_lib_x509-$(CONFIG_$(PHASE_)RSA_PUBLIC_KEY_PARSER_MBEDTLS) += \ +mbedtls_lib_crypto-$(CONFIG_$(PHASE_)MBEDTLS_LIB_BIGNUM) += \ $(MBEDTLS_LIB_DIR)/bignum.o \ - $(MBEDTLS_LIB_DIR)/bignum_core.o \ + $(MBEDTLS_LIB_DIR)/bignum_core.o + +# MbedTLS X509 library +obj-$(CONFIG_$(XPL_)MBEDTLS_LIB_X509) += mbedtls_lib_x509.o +mbedtls_lib_x509-y := $(MBEDTLS_LIB_DIR)/x509.o +mbedtls_lib_x509-$(CONFIG_$(PHASE_)RSA_PUBLIC_KEY_PARSER_MBEDTLS) += \ $(MBEDTLS_LIB_DIR)/rsa.o \ $(MBEDTLS_LIB_DIR)/rsa_alt_helpers.o mbedtls_lib_x509-$(CONFIG_$(PHASE_)ASYMMETRIC_PUBLIC_KEY_MBEDTLS) += \ -- 2.43.0
