xref: /aosp_15_r20/external/coreboot/src/security/tpm/tspi/crtm.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef __SECURITY_TSPI_CRTM_H__
4 #define __SECURITY_TSPI_CRTM_H__
5 
6 #include <program_loading.h>
7 #include <security/tpm/tspi.h>
8 #include <security/tpm/tss_errors.h>
9 #include <types.h>
10 #include <vb2_sha.h>
11 
12 #if CONFIG(TPM_LOG_CB)
13 #  define TPM_MEASURE_ALGO (tlcl_get_family() == TPM_1 ? VB2_HASH_SHA1 : VB2_HASH_SHA256)
14 #elif CONFIG(TPM_LOG_TPM1)
15 #  define TPM_MEASURE_ALGO VB2_HASH_SHA1
16 #elif CONFIG(TPM_LOG_TPM2)
17 #  if CONFIG(TPM_HASH_SHA1)
18 #    define TPM_MEASURE_ALGO VB2_HASH_SHA1
19 #  endif
20 #  if CONFIG(TPM_HASH_SHA256)
21 #    define TPM_MEASURE_ALGO VB2_HASH_SHA256
22 #  endif
23 #  if CONFIG(TPM_HASH_SHA384)
24 #    define TPM_MEASURE_ALGO VB2_HASH_SHA384
25 #  endif
26 #  if CONFIG(TPM_HASH_SHA512)
27 #    define TPM_MEASURE_ALGO VB2_HASH_SHA512
28 #  endif
29 #endif
30 
31 #if !defined(TPM_MEASURE_ALGO)
32 #  if !CONFIG(TPM_MEASURED_BOOT)
33 #    define TPM_MEASURE_ALGO VB2_HASH_INVALID
34 #  else
35 #    error "Misconfiguration: failed to determine TPM hashing algorithm"
36 #  endif
37 #endif
38 
39 /**
40  * Measure digests cached in TPM log entries into PCRs
41  */
42 tpm_result_t tspi_measure_cache_to_pcr(void);
43 
44 /**
45  * Extend a measurement hash taken for a CBFS file into the appropriate PCR.
46  */
47 tpm_result_t tspi_cbfs_measurement(const char *name, uint32_t type, const struct vb2_hash *hash);
48 
49 /*
50  * Provide a function on SoC level to measure the bootblock for cases where bootblock is
51  * neither in FMAP nor in CBFS (e.g. in IFWI).
52  */
53 int tspi_soc_measure_bootblock(int pcr_index);
54 
55 #endif /* __SECURITY_TSPI_CRTM_H__ */
56