From nobody Sun Oct 5 14:37:46 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C09E1B644; Fri, 1 Aug 2025 23:56:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754092566; cv=none; b=q8T+wnY4IAu/xqrcEcFjx5zQkxoXgMJMwmUdQ+EQSQ9lPX6bL5rWcSpmJJsyYyOMZ4ueApOOdvvdb4DdxmaEWZi/AB8XVq8k1DBJwKU+9LxR5cPwoHm55S3oiIBt85Fjmv8yipoxOa1TQMEo+UnKz9rJJa6xAkIRjDAOSmTAMCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754092566; c=relaxed/simple; bh=dbaFLzCG/5EkHTeHj907dORnHsrShX2dlh1BlaIdXok=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=DPOPklhs/VYV/G4HNrxDaEuBr4cM+10WmaUV1rGeLkrfVKQUqe49GttbjAtYtMTpT3a1dtCgZiQnFuK5AbOZFFJhu+KPSeo4E48RrZE6D5OrzYUeyNINzvTvdZez8hrW9g7Ce8reHf1N8qNJESibDYYWrpUW60iFUcLIMWh3CCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p8a1t5NY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p8a1t5NY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D4A3C4CEE7; Fri, 1 Aug 2025 23:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754092566; bh=dbaFLzCG/5EkHTeHj907dORnHsrShX2dlh1BlaIdXok=; h=From:To:Cc:Subject:Date:From; b=p8a1t5NYG6c2K+OI6nAVg88FYPTy/1li6BCKUEzy4rRRTpg8B/6Y3zLka/U7RjFgy PKKbeziwCQJh3gPrHoWMyrlM/WixH/isi29k61/aNlTAuS+zMdqawoZhNaacTq4FsH NqKEF81yw2JuzXpKrB3R6Pu1MVawZmdyYyRMpTP7TEDeCp9n77VwvyWi2Tvzsk+xXT LLfYahxLDKgyGxeV3uPf9NrBt7sscnMCw9wZeWboYTaNA622HT+d5qc5Rr7p46AtVh Emvs0Ir8MuMTUPxCuIgCmsBwfCasaCsiPbzIzKbyslliw7+6Abto6e6tEp0F0Rbmx1 DwCTYmtLjSOKQ== From: Eric Biggers To: Jens Wiklander , Sumit Garg , op-tee@lists.trustedfirmware.org Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH] tee: Use SHA-1 library instead of crypto_shash Date: Fri, 1 Aug 2025 16:55:41 -0700 Message-ID: <20250801235541.14050-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the SHA-1 library functions instead of crypto_shash. This is simpler and faster. Change uuid_v5() to return void, since it can no longer fail. Signed-off-by: Eric Biggers Reviewed-by: Sumit Garg --- Note: this patch depends on the SHA-1 library functions that were merged in v6.17-rc1. drivers/tee/Kconfig | 3 +-- drivers/tee/tee_core.c | 55 +++++++----------------------------------- 2 files changed, 10 insertions(+), 48 deletions(-) diff --git a/drivers/tee/Kconfig b/drivers/tee/Kconfig index 61b507c187801..a84767940fbfc 100644 --- a/drivers/tee/Kconfig +++ b/drivers/tee/Kconfig @@ -1,12 +1,11 @@ # SPDX-License-Identifier: GPL-2.0-only # Generic Trusted Execution Environment Configuration menuconfig TEE tristate "Trusted Execution Environment support" depends on HAVE_ARM_SMCCC || COMPILE_TEST || CPU_SUP_AMD - select CRYPTO - select CRYPTO_SHA1 + select CRYPTO_LIB_SHA1 select DMA_SHARED_BUFFER select GENERIC_ALLOCATOR help This implements a generic interface towards a Trusted Execution Environment (TEE). diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index acc7998758ad8..d079aeee0690a 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -12,11 +12,10 @@ #include #include #include #include #include -#include #include #include "tee_private.h" =20 #define TEE_NUM_DEVICES 32 =20 @@ -140,72 +139,36 @@ static int tee_release(struct inode *inode, struct fi= le *filp) * UUIDv5 is specific in RFC 4122. * * This implements section (for SHA-1): * 4.3. Algorithm for Creating a Name-Based UUID */ -static int uuid_v5(uuid_t *uuid, const uuid_t *ns, const void *name, - size_t size) +static void uuid_v5(uuid_t *uuid, const uuid_t *ns, const void *name, + size_t size) { unsigned char hash[SHA1_DIGEST_SIZE]; - struct crypto_shash *shash =3D NULL; - struct shash_desc *desc =3D NULL; - int rc; - - shash =3D crypto_alloc_shash("sha1", 0, 0); - if (IS_ERR(shash)) { - rc =3D PTR_ERR(shash); - pr_err("shash(sha1) allocation failed\n"); - return rc; - } - - desc =3D kzalloc(sizeof(*desc) + crypto_shash_descsize(shash), - GFP_KERNEL); - if (!desc) { - rc =3D -ENOMEM; - goto out_free_shash; - } - - desc->tfm =3D shash; + struct sha1_ctx ctx; =20 - rc =3D crypto_shash_init(desc); - if (rc < 0) - goto out_free_desc; - - rc =3D crypto_shash_update(desc, (const u8 *)ns, sizeof(*ns)); - if (rc < 0) - goto out_free_desc; - - rc =3D crypto_shash_update(desc, (const u8 *)name, size); - if (rc < 0) - goto out_free_desc; - - rc =3D crypto_shash_final(desc, hash); - if (rc < 0) - goto out_free_desc; + sha1_init(&ctx); + sha1_update(&ctx, (const u8 *)ns, sizeof(*ns)); + sha1_update(&ctx, (const u8 *)name, size); + sha1_final(&ctx, hash); =20 memcpy(uuid->b, hash, UUID_SIZE); =20 /* Tag for version 5 */ uuid->b[6] =3D (hash[6] & 0x0F) | 0x50; uuid->b[8] =3D (hash[8] & 0x3F) | 0x80; - -out_free_desc: - kfree(desc); - -out_free_shash: - crypto_free_shash(shash); - return rc; } =20 int tee_session_calc_client_uuid(uuid_t *uuid, u32 connection_method, const u8 connection_data[TEE_IOCTL_UUID_LEN]) { gid_t ns_grp =3D (gid_t)-1; kgid_t grp =3D INVALID_GID; char *name =3D NULL; int name_len; - int rc; + int rc =3D 0; =20 if (connection_method =3D=3D TEE_IOCTL_LOGIN_PUBLIC || connection_method =3D=3D TEE_IOCTL_LOGIN_REE_KERNEL) { /* Nil UUID to be passed to TEE environment */ uuid_copy(uuid, &uuid_null); @@ -258,11 +221,11 @@ int tee_session_calc_client_uuid(uuid_t *uuid, u32 co= nnection_method, default: rc =3D -EINVAL; goto out_free_name; } =20 - rc =3D uuid_v5(uuid, &tee_client_uuid_ns, name, name_len); + uuid_v5(uuid, &tee_client_uuid_ns, name, name_len); out_free_name: kfree(name); =20 return rc; } base-commit: 0905809b38bda1fa0b206986c44d846e46f13c1d --=20 2.50.1