diff options
| author | Heiko Schocher <[email protected]> | 2025-11-18 05:30:41 +0100 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2025-12-04 09:38:58 -0600 |
| commit | 7c3f05ad51e4bc23dd4f411f28968f1d8f43099c (patch) | |
| tree | 5368efdf970d4f807e2d032152b4bf38deda568f /lib | |
| parent | 213601a600f1e8894cea76b0bfc131f038882407 (diff) | |
tpm2: add sm3 256 hash support
add sm3 256 hash support, so TPM2 chips which report
5 pcrs with sm3 hash do not fail with:
u-boot=> tpm2 autostart
tpm2_get_pcr_info: too many pcrs: 5
Error: -90
Signed-off-by: Heiko Schocher <[email protected]>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/efi_loader/efi_tcg2.c | 3 | ||||
| -rw-r--r-- | lib/tpm-v2.c | 4 | ||||
| -rw-r--r-- | lib/tpm_tcg2.c | 9 |
3 files changed, 14 insertions, 2 deletions
diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 1832eeb5dce..bdf78897d47 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -430,6 +430,9 @@ static efi_status_t tcg2_hash_pe_image(void *efi, u64 efi_size, case TPM2_ALG_SHA512: hash_calculate("sha512", regs->reg, regs->num, hash); break; + case TPM2_ALG_SM3_256: + hash_calculate("sm3_256", regs->reg, regs->num, hash); + break; default: continue; } diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 5b21c57ae42..f443b738f82 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -686,10 +686,10 @@ int tpm2_get_pcr_info(struct udevice *dev, struct tpml_pcr_selection *pcrs) pcrs->count = get_unaligned_be32(response); /* - * We only support 4 algorithms for now so check against that + * check against the supported algorithms in hash_algo_list, * instead of TPM2_NUM_PCR_BANKS */ - if (pcrs->count > 4 || pcrs->count < 1) { + if (pcrs->count > ARRAY_SIZE(hash_algo_list) || pcrs->count < 1) { printf("%s: too many pcrs: %u\n", __func__, pcrs->count); return -EMSGSIZE; } diff --git a/lib/tpm_tcg2.c b/lib/tpm_tcg2.c index c314b401d0b..d41228f75a9 100644 --- a/lib/tpm_tcg2.c +++ b/lib/tpm_tcg2.c @@ -12,6 +12,7 @@ #include <u-boot/sha1.h> #include <u-boot/sha256.h> #include <u-boot/sha512.h> +#include <u-boot/sm3.h> #include <version_string.h> #include <asm/io.h> #include <linux/bitops.h> @@ -144,6 +145,12 @@ int tcg2_create_digest(struct udevice *dev, const u8 *input, u32 length, len = TPM2_SHA512_DIGEST_SIZE; break; #endif +#if IS_ENABLED(CONFIG_SM3) + case TPM2_ALG_SM3_256: + sm3_hash(input, length, final); + len = TPM2_SM3_256_DIGEST_SIZE; + break; +#endif default: printf("%s: unsupported algorithm %x\n", __func__, priv->active_banks[i]); @@ -319,6 +326,7 @@ static int tcg2_replay_eventlog(struct tcg2_event_log *elog, case TPM2_ALG_SHA256: case TPM2_ALG_SHA384: case TPM2_ALG_SHA512: + case TPM2_ALG_SM3_256: len = tpm2_algorithm_to_len(algo); break; default: @@ -431,6 +439,7 @@ static int tcg2_log_parse(struct udevice *dev, struct tcg2_event_log *elog, case TPM2_ALG_SHA256: case TPM2_ALG_SHA384: case TPM2_ALG_SHA512: + case TPM2_ALG_SM3_256: len = get_unaligned_le16(&event->digest_sizes[i].digest_size); if (tpm2_algorithm_to_len(algo) != len) { log_err("EventLog invalid algorithm length\n"); |
