From 2b0d0c50127c4c45264f634d0efee347ffbce329 Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Thu, 1 Jun 2023 14:32:53 +0200 Subject: [PATCH] core: ltc: configure internal SHA-1 and SHA-224 Adds _CFG_CORE_LTC_SHA1_DESC and _CFG_CORE_LTC_SHA224_DESC to allow enabling support for SHA-1 and SHA-224 internally in LTC. Signed-off-by: Jens Wiklander Acked-By: Jerome Forissier --- core/crypto.mk | 4 ++++ core/lib/libtomcrypt/rsa.c | 10 +++++----- core/lib/libtomcrypt/src/hashes/sha2/sub.mk | 2 +- core/lib/libtomcrypt/src/hashes/sub.mk | 2 +- core/lib/libtomcrypt/sub.mk | 4 ++-- core/lib/libtomcrypt/tomcrypt.c | 4 ++-- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/core/crypto.mk b/core/crypto.mk index c0dab5a9308..368f1f83a69 100644 --- a/core/crypto.mk +++ b/core/crypto.mk @@ -251,6 +251,10 @@ endif # libtomcrypt (LTC) specifics, phase #2 ############################################################### +_CFG_CORE_LTC_SHA1_DESC := $(call cfg-one-enabled, _CFG_CORE_LTC_SHA1_DESC \ + _CFG_CORE_LTC_SHA1) +_CFG_CORE_LTC_SHA224_DESC := $(call cfg-one-enabled, _CFG_CORE_LTC_SHA224_DESC \ + _CFG_CORE_LTC_SHA224) _CFG_CORE_LTC_SHA256_DESC := $(call cfg-one-enabled, _CFG_CORE_LTC_SHA256_DESC \ _CFG_CORE_LTC_SHA224 \ _CFG_CORE_LTC_SHA256) diff --git a/core/lib/libtomcrypt/rsa.c b/core/lib/libtomcrypt/rsa.c index 56a67c4e01c..4a2b1d8817c 100644 --- a/core/lib/libtomcrypt/rsa.c +++ b/core/lib/libtomcrypt/rsa.c @@ -29,7 +29,7 @@ static TEE_Result tee_algo_to_ltc_hashindex(uint32_t algo, int *ltc_hashindex) { switch (algo) { -#if defined(_CFG_CORE_LTC_SHA1) +#if defined(_CFG_CORE_LTC_SHA1_DESC) case TEE_ALG_RSASSA_PKCS1_V1_5_SHA1: case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA1: case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1: @@ -43,28 +43,28 @@ static TEE_Result tee_algo_to_ltc_hashindex(uint32_t algo, int *ltc_hashindex) *ltc_hashindex = find_hash("md5"); break; #endif -#if defined(_CFG_CORE_LTC_SHA224) +#if defined(_CFG_CORE_LTC_SHA224_DESC) case TEE_ALG_RSASSA_PKCS1_V1_5_SHA224: case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA224: case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA224: *ltc_hashindex = find_hash("sha224"); break; #endif -#if defined(_CFG_CORE_LTC_SHA256) +#if defined(_CFG_CORE_LTC_SHA256_DESC) case TEE_ALG_RSASSA_PKCS1_V1_5_SHA256: case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256: case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA256: *ltc_hashindex = find_hash("sha256"); break; #endif -#if defined(_CFG_CORE_LTC_SHA384) +#if defined(_CFG_CORE_LTC_SHA384_DESC) case TEE_ALG_RSASSA_PKCS1_V1_5_SHA384: case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA384: case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA384: *ltc_hashindex = find_hash("sha384"); break; #endif -#if defined(_CFG_CORE_LTC_SHA512) +#if defined(_CFG_CORE_LTC_SHA512_DESC) case TEE_ALG_RSASSA_PKCS1_V1_5_SHA512: case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA512: case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA512: diff --git a/core/lib/libtomcrypt/src/hashes/sha2/sub.mk b/core/lib/libtomcrypt/src/hashes/sha2/sub.mk index 2a497beddc3..cd701ec1aec 100644 --- a/core/lib/libtomcrypt/src/hashes/sha2/sub.mk +++ b/core/lib/libtomcrypt/src/hashes/sha2/sub.mk @@ -1,4 +1,4 @@ -srcs-$(_CFG_CORE_LTC_SHA224) += sha224.c +srcs-$(_CFG_CORE_LTC_SHA224_DESC) += sha224.c ifneq ($(_CFG_CORE_LTC_SHA256_ACCEL),y) srcs-$(_CFG_CORE_LTC_SHA256_DESC) += sha256.c diff --git a/core/lib/libtomcrypt/src/hashes/sub.mk b/core/lib/libtomcrypt/src/hashes/sub.mk index 4a9b66e6155..d58f920f194 100644 --- a/core/lib/libtomcrypt/src/hashes/sub.mk +++ b/core/lib/libtomcrypt/src/hashes/sub.mk @@ -1,6 +1,6 @@ srcs-$(_CFG_CORE_LTC_MD5) += md5.c -ifeq ($(_CFG_CORE_LTC_SHA1),y) +ifeq ($(_CFG_CORE_LTC_SHA1_DESC),y) ifneq ($(_CFG_CORE_LTC_SHA1_ACCEL),y) srcs-y += sha1.c endif diff --git a/core/lib/libtomcrypt/sub.mk b/core/lib/libtomcrypt/sub.mk index 6e0d58e1e7b..08cb085076a 100644 --- a/core/lib/libtomcrypt/sub.mk +++ b/core/lib/libtomcrypt/sub.mk @@ -39,10 +39,10 @@ cppflags-lib-y += -DLTC_NO_HASHES ifeq ($(_CFG_CORE_LTC_MD5),y) cppflags-lib-y += -DLTC_MD5 endif -ifeq ($(_CFG_CORE_LTC_SHA1),y) +ifeq ($(_CFG_CORE_LTC_SHA1_DESC),y) cppflags-lib-y += -DLTC_SHA1 endif -ifeq ($(_CFG_CORE_LTC_SHA224),y) +ifeq ($(_CFG_CORE_LTC_SHA224_DESC),y) cppflags-lib-y += -DLTC_SHA224 endif ifeq ($(_CFG_CORE_LTC_SHA256_DESC),y) diff --git a/core/lib/libtomcrypt/tomcrypt.c b/core/lib/libtomcrypt/tomcrypt.c index f4779e988a4..a7b58a35131 100644 --- a/core/lib/libtomcrypt/tomcrypt.c +++ b/core/lib/libtomcrypt/tomcrypt.c @@ -102,10 +102,10 @@ static void tee_ltc_reg_algs(void) #if defined(_CFG_CORE_LTC_MD5) register_hash(&md5_desc); #endif -#if defined(_CFG_CORE_LTC_SHA1) +#if defined(_CFG_CORE_LTC_SHA1) || defined(_CFG_CORE_LTC_SHA1_DESC) register_hash(&sha1_desc); #endif -#if defined(_CFG_CORE_LTC_SHA224) +#if defined(_CFG_CORE_LTC_SHA224) || defined(_CFG_CORE_LTC_SHA224_DESC) register_hash(&sha224_desc); #endif #if defined(_CFG_CORE_LTC_SHA256) || defined(_CFG_CORE_LTC_SHA256_DESC)