From 51afcd93c9eed6d9f6292d80fa33aacb1bc53149 Mon Sep 17 00:00:00 2001 From: Jorge Ramirez-Ortiz Date: Thu, 18 Jan 2024 19:40:10 +0100 Subject: [PATCH] drivers: caam: sm2 operation fallback Fallback to software operations for SM2. Reverts the temporary solution implemented in commit '3489781e9072 ("drivers: caam: disable CFG_CRYPTO_SM2_* when ECC CAAM driver is enabled")'. Signed-off-by: Jorge Ramirez-Ortiz Acked-by: Etienne Carriere Acked-by: Jens Wiklander Acked-by: Clement Faure --- core/drivers/crypto/caam/acipher/caam_ecc.c | 22 +++++++++++++++++++-- core/drivers/crypto/caam/crypto.mk | 7 ------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/core/drivers/crypto/caam/acipher/caam_ecc.c b/core/drivers/crypto/caam/acipher/caam_ecc.c index b9c2cde8817..6327745da67 100644 --- a/core/drivers/crypto/caam/acipher/caam_ecc.c +++ b/core/drivers/crypto/caam/acipher/caam_ecc.c @@ -143,11 +143,20 @@ static enum caam_ecc_curve get_caam_curve(uint32_t tee_curve) * @size_bits Key size in bits */ static TEE_Result do_allocate_keypair(struct ecc_keypair *key, - uint32_t type __unused, + uint32_t type, size_t size_bits) { ECC_TRACE("Allocate Keypair of %zu bits", size_bits); + switch (type) { + case TEE_TYPE_SM2_PKE_KEYPAIR: + case TEE_TYPE_SM2_DSA_KEYPAIR: + /* Software fallback */ + return TEE_ERROR_NOT_IMPLEMENTED; + default: + break; + } + /* Initialize the key fields to NULL */ memset(key, 0, sizeof(*key)); @@ -184,11 +193,20 @@ static TEE_Result do_allocate_keypair(struct ecc_keypair *key, * @size_bits Key size in bits */ static TEE_Result do_allocate_publickey(struct ecc_public_key *key, - uint32_t type __unused, + uint32_t type, size_t size_bits) { ECC_TRACE("Allocate Public Key of %zu bits", size_bits); + switch (type) { + case TEE_TYPE_SM2_PKE_PUBLIC_KEY: + case TEE_TYPE_SM2_DSA_PUBLIC_KEY: + /* Software fallback */ + return TEE_ERROR_NOT_IMPLEMENTED; + default: + break; + } + /* Initialize the key fields to NULL */ memset(key, 0, sizeof(*key)); diff --git a/core/drivers/crypto/caam/crypto.mk b/core/drivers/crypto/caam/crypto.mk index 13f8e4cc070..5dbb3c6729c 100644 --- a/core/drivers/crypto/caam/crypto.mk +++ b/core/drivers/crypto/caam/crypto.mk @@ -205,12 +205,5 @@ ifeq ($(call cfg-one-enabled,CFG_CRYPTO_DRV_RSA CFG_CRYPTO_DRV_ECC \ $(call force, CFG_CRYPTO_DRV_ACIPHER,y,Mandated by CFG_CRYPTO_DRV_{RSA|ECC|DSA|DH}) endif -# Disable SM2 as it is not supported by the CAAM driver -ifeq ($(CFG_NXP_CAAM_ECC_DRV),y) -$(call force,CFG_CRYPTO_SM2_PKE,n) -$(call force,CFG_CRYPTO_SM2_KEP,n) -$(call force,CFG_CRYPTO_SM2_DSA,n) -endif - endif # CFG_CRYPTO_DRIVER endif # CFG_NXP_CAAM