Skip to content

Commit e59236b

Browse files
ebiggershansendc
authored andcommitted
x86/sgx: Use SHA-256 library API instead of crypto_shash API
This user of SHA-256 does not support any other algorithm, so the crypto_shash abstraction provides no value. Just use the SHA-256 library API instead, which is much simpler and easier to use. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://lore.kernel.org/all/20250428183838.799333-1-ebiggers%40kernel.org
1 parent b443265 commit e59236b

File tree

3 files changed

+3
-31
lines changed

3 files changed

+3
-31
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,8 +1881,7 @@ endchoice
18811881
config X86_SGX
18821882
bool "Software Guard eXtensions (SGX)"
18831883
depends on X86_64 && CPU_SUP_INTEL && X86_X2APIC
1884-
depends on CRYPTO=y
1885-
depends on CRYPTO_SHA256=y
1884+
select CRYPTO_LIB_SHA256
18861885
select MMU_NOTIFIER
18871886
select NUMA_KEEP_MEMINFO if NUMA
18881887
select XARRAY_MULTI

arch/x86/kernel/cpu/sgx/driver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#ifndef __ARCH_SGX_DRIVER_H__
33
#define __ARCH_SGX_DRIVER_H__
44

5-
#include <crypto/hash.h>
65
#include <linux/kref.h>
76
#include <linux/mmu_notifier.h>
87
#include <linux/radix-tree.h>

arch/x86/kernel/cpu/sgx/ioctl.c

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <asm/mman.h>
55
#include <asm/sgx.h>
6+
#include <crypto/sha2.h>
67
#include <linux/mman.h>
78
#include <linux/delay.h>
89
#include <linux/file.h>
@@ -463,31 +464,6 @@ static long sgx_ioc_enclave_add_pages(struct sgx_encl *encl, void __user *arg)
463464
return ret;
464465
}
465466

466-
static int __sgx_get_key_hash(struct crypto_shash *tfm, const void *modulus,
467-
void *hash)
468-
{
469-
SHASH_DESC_ON_STACK(shash, tfm);
470-
471-
shash->tfm = tfm;
472-
473-
return crypto_shash_digest(shash, modulus, SGX_MODULUS_SIZE, hash);
474-
}
475-
476-
static int sgx_get_key_hash(const void *modulus, void *hash)
477-
{
478-
struct crypto_shash *tfm;
479-
int ret;
480-
481-
tfm = crypto_alloc_shash("sha256", 0, CRYPTO_ALG_ASYNC);
482-
if (IS_ERR(tfm))
483-
return PTR_ERR(tfm);
484-
485-
ret = __sgx_get_key_hash(tfm, modulus, hash);
486-
487-
crypto_free_shash(tfm);
488-
return ret;
489-
}
490-
491467
static int sgx_encl_init(struct sgx_encl *encl, struct sgx_sigstruct *sigstruct,
492468
void *token)
493469
{
@@ -523,9 +499,7 @@ static int sgx_encl_init(struct sgx_encl *encl, struct sgx_sigstruct *sigstruct,
523499
sgx_xfrm_reserved_mask)
524500
return -EINVAL;
525501

526-
ret = sgx_get_key_hash(sigstruct->modulus, mrsigner);
527-
if (ret)
528-
return ret;
502+
sha256(sigstruct->modulus, SGX_MODULUS_SIZE, (u8 *)mrsigner);
529503

530504
mutex_lock(&encl->lock);
531505

0 commit comments

Comments
 (0)