coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
antirollback.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 /*
4  * Functions for querying, manipulating and locking rollback indices
5  * stored in the TPM NVRAM.
6  */
7 
8 #ifndef ANTIROLLBACK_H_
9 #define ANTIROLLBACK_H_
10 
11 #include <types.h>
12 #include <security/tpm/tspi.h>
13 #include <vb2_sha.h>
14 
15 struct vb2_context;
16 enum vb2_pcr_digest;
17 
18 /* TPM NVRAM location indices. */
19 #define FIRMWARE_NV_INDEX 0x1007
20 #define KERNEL_NV_INDEX 0x1008
21 /* 0x1009 used to be used as a backup space. Think of conflicts if you
22  * want to use 0x1009 for something else. */
23 #define BACKUP_NV_INDEX 0x1009
24 #define FWMP_NV_INDEX 0x100a
25 /* 0x100b: Hash of MRC_CACHE training data for recovery boot */
26 #define MRC_REC_HASH_NV_INDEX 0x100b
27 /* 0x100c: OOBE autoconfig public key hashes */
28 /* 0x100d: Hash of MRC_CACHE training data for non-recovery boot */
29 #define MRC_RW_HASH_NV_INDEX 0x100d
30 #define HASH_NV_SIZE VB2_SHA256_DIGEST_SIZE
31 /* Widevine Secure Counter space */
32 #define WIDEVINE_COUNTER_NV_INDEX(n) (0x3000 + (n))
33 #define NUM_WIDEVINE_COUNTERS 4
34 #define WIDEVINE_COUNTER_NAME "Widevine Secure Counter"
35 #define WIDEVINE_COUNTER_SIZE sizeof(uint64_t)
36 /* Zero-Touch Enrollment related spaces */
37 #define ZTE_BOARD_ID_NV_INDEX 0x3fff00
38 #define ZTE_RMA_SN_BITS_INDEX 0x3fff01
39 #define ZTE_RMA_BYTES_COUNTER_INDEX 0x3fff04
40 
41 /* Structure definitions for TPM spaces */
42 
43 /* Flags for firmware space */
44 
45 /*
46  * Last boot was developer mode. TPM ownership is cleared when transitioning
47  * to/from developer mode.
48  */
49 #define FLAG_LAST_BOOT_DEVELOPER 0x01
50 
51 /* All functions return TPM_SUCCESS (zero) if successful, non-zero if error */
52 
53 uint32_t antirollback_read_space_firmware(struct vb2_context *ctx);
54 
55 /**
56  * Write may be called if the versions change.
57  */
58 uint32_t antirollback_write_space_firmware(struct vb2_context *ctx);
59 
60 /**
61  * Read and write kernel space in TPM.
62  */
63 uint32_t antirollback_read_space_kernel(struct vb2_context *ctx);
64 uint32_t antirollback_write_space_kernel(struct vb2_context *ctx);
65 
66 /**
67  * Lock must be called.
68  */
70 
71 /*
72  * Read MRC hash data from TPM.
73  * @param index index into TPM NVRAM where hash is stored The index
74  * can be set to either MRC_REC_HASH_NV_INDEX or
75  * MRC_RW_HASH_NV_INDEX depending upon whether we are
76  * booting in recovery or normal mode.
77  * @param data pointer to buffer where hash from TPM read into
78  * @param size size of buffer
79  */
81 /*
82  * Write new hash data to MRC space in TPM.\
83  * @param index index into TPM NVRAM where hash is stored The index
84  * can be set to either MRC_REC_HASH_NV_INDEX or
85  * MRC_RW_HASH_NV_INDEX depending upon whether we are
86  * booting in recovery or normal mode.
87  * @param data pointer to buffer of hash value to be written
88  * @param size size of buffer
89 */
91  uint32_t size);
92 /*
93  * Lock down MRC hash space in TPM.
94  * @param index index into TPM NVRAM where hash is stored The index
95  * can be set to either MRC_REC_HASH_NV_INDEX or
96  * MRC_RW_HASH_NV_INDEX depending upon whether we are
97  * booting in recovery or normal mode.
98 */
100 
101 #endif /* ANTIROLLBACK_H_ */
uint32_t antirollback_read_space_mrc_hash(uint32_t index, uint8_t *data, uint32_t size)
Definition: secdata_mock.c:62
uint32_t antirollback_lock_space_firmware(void)
Lock must be called.
Definition: secdata_mock.c:52
uint32_t antirollback_lock_space_mrc_hash(uint32_t index)
Definition: secdata_mock.c:57
uint32_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data, uint32_t size)
Definition: secdata_mock.c:67
uint32_t antirollback_read_space_kernel(struct vb2_context *ctx)
Read and write kernel space in TPM.
Definition: secdata_mock.c:29
uint32_t antirollback_write_space_firmware(struct vb2_context *ctx)
Write may be called if the versions change.
Definition: secdata_mock.c:24
uint32_t antirollback_read_space_firmware(struct vb2_context *ctx)
Definition: secdata_mock.c:18
uint32_t antirollback_write_space_kernel(struct vb2_context *ctx)
Definition: secdata_mock.c:47
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8