Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'tee-sha1-lib-for-v6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/jenswi/linux-tee into soc/drivers

Use SHA-1 library instead of crypto_shash

* tag 'tee-sha1-lib-for-v6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/jenswi/linux-tee:
tee: Use SHA-1 library instead of crypto_shash

Link: https://lore.kernel.org/r/20250912091611.GA1442659@rayden
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+10 -48
+1 -2
drivers/tee/Kconfig
··· 3 3 menuconfig TEE 4 4 tristate "Trusted Execution Environment support" 5 5 depends on HAVE_ARM_SMCCC || COMPILE_TEST || CPU_SUP_AMD 6 - select CRYPTO 7 - select CRYPTO_SHA1 6 + select CRYPTO_LIB_SHA1 8 7 select DMA_SHARED_BUFFER 9 8 select GENERIC_ALLOCATOR 10 9 help
+9 -46
drivers/tee/tee_core.c
··· 14 14 #include <linux/slab.h> 15 15 #include <linux/tee_core.h> 16 16 #include <linux/uaccess.h> 17 - #include <crypto/hash.h> 18 17 #include <crypto/sha1.h> 19 18 #include "tee_private.h" 20 19 ··· 141 142 * This implements section (for SHA-1): 142 143 * 4.3. Algorithm for Creating a Name-Based UUID 143 144 */ 144 - static int uuid_v5(uuid_t *uuid, const uuid_t *ns, const void *name, 145 - size_t size) 145 + static void uuid_v5(uuid_t *uuid, const uuid_t *ns, const void *name, 146 + size_t size) 146 147 { 147 148 unsigned char hash[SHA1_DIGEST_SIZE]; 148 - struct crypto_shash *shash = NULL; 149 - struct shash_desc *desc = NULL; 150 - int rc; 149 + struct sha1_ctx ctx; 151 150 152 - shash = crypto_alloc_shash("sha1", 0, 0); 153 - if (IS_ERR(shash)) { 154 - rc = PTR_ERR(shash); 155 - pr_err("shash(sha1) allocation failed\n"); 156 - return rc; 157 - } 158 - 159 - desc = kzalloc(sizeof(*desc) + crypto_shash_descsize(shash), 160 - GFP_KERNEL); 161 - if (!desc) { 162 - rc = -ENOMEM; 163 - goto out_free_shash; 164 - } 165 - 166 - desc->tfm = shash; 167 - 168 - rc = crypto_shash_init(desc); 169 - if (rc < 0) 170 - goto out_free_desc; 171 - 172 - rc = crypto_shash_update(desc, (const u8 *)ns, sizeof(*ns)); 173 - if (rc < 0) 174 - goto out_free_desc; 175 - 176 - rc = crypto_shash_update(desc, (const u8 *)name, size); 177 - if (rc < 0) 178 - goto out_free_desc; 179 - 180 - rc = crypto_shash_final(desc, hash); 181 - if (rc < 0) 182 - goto out_free_desc; 151 + sha1_init(&ctx); 152 + sha1_update(&ctx, (const u8 *)ns, sizeof(*ns)); 153 + sha1_update(&ctx, (const u8 *)name, size); 154 + sha1_final(&ctx, hash); 183 155 184 156 memcpy(uuid->b, hash, UUID_SIZE); 185 157 186 158 /* Tag for version 5 */ 187 159 uuid->b[6] = (hash[6] & 0x0F) | 0x50; 188 160 uuid->b[8] = (hash[8] & 0x3F) | 0x80; 189 - 190 - out_free_desc: 191 - kfree(desc); 192 - 193 - out_free_shash: 194 - crypto_free_shash(shash); 195 - return rc; 196 161 } 197 162 198 163 int tee_session_calc_client_uuid(uuid_t *uuid, u32 connection_method, ··· 166 203 kgid_t grp = INVALID_GID; 167 204 char *name = NULL; 168 205 int name_len; 169 - int rc; 206 + int rc = 0; 170 207 171 208 if (connection_method == TEE_IOCTL_LOGIN_PUBLIC || 172 209 connection_method == TEE_IOCTL_LOGIN_REE_KERNEL) { ··· 223 260 goto out_free_name; 224 261 } 225 262 226 - rc = uuid_v5(uuid, &tee_client_uuid_ns, name, name_len); 263 + uuid_v5(uuid, &tee_client_uuid_ns, name, name_len); 227 264 out_free_name: 228 265 kfree(name); 229 266