Software APIs
owner_block.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_OWNERSHIP_OWNER_BLOCK_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_OWNERSHIP_OWNER_BLOCK_H_
7 
9 #include "sw/device/silicon_creator/lib/boot_data.h"
10 #include "sw/device/silicon_creator/lib/error.h"
11 #include "sw/device/silicon_creator/lib/ownership/datatypes.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif // __cplusplus
16 
17 /**
18  * The signature or sealing status of an owner page.
19  */
20 typedef enum owner_page_status {
21  /** Invalid: `INV_`. */
22  kOwnerPageStatusInvalid = 0x5f564e49,
23  /** Sealed: `SEAL`. */
24  kOwnerPageStatusSealed = 0x4c414553,
25  /** Signed: `SIGN`. */
26  kOwnerPageStatusSigned = 0x4e474953,
27 } owner_page_status_t;
28 
29 /**
30  * RAM copies of the owner pages read out of flash INFO pages.
31  */
32 extern owner_block_t owner_page[2];
33 extern owner_page_status_t owner_page_valid[2];
34 
35 /**
36  * The owner config struct contains high-level configuration items
37  * from an owner block.
38  */
39 typedef struct owner_config {
40  /** The requested SRAM execution configuration. */
41  owner_sram_exec_mode_t sram_exec;
42  /** The requested flash configuration. */
44  /** The requested flash INFO configuration. */
46  /** The requested rescue configuration. */
49 
50 /**
51  * The application keyring collects application keys from the owner config
52  * block.
53  */
54 typedef struct owner_application_keyring {
55  /** The number of application keys found. */
56  size_t length;
57  /** Pointers to the application keys. */
60 
61 /**
62  * Determine if the ownership update mode is one of the "newversion" modes.
63  *
64  * @return kHardenedBoolTrue if it is a newversion mode.
65  */
66 hardened_bool_t owner_block_newversion_mode(void);
67 
68 /**
69  * Check if owner page 1 is valid for ownership transfer.
70  *
71  * @param bootdata The current bootdata.
72  * @return kHardenedBoolTrue if page 1 is valid.
73  */
74 hardened_bool_t owner_block_page1_valid_for_transfer(boot_data_t *bootdata);
75 
76 /**
77  * Initialize the owner config with default values.
78  *
79  * The sram_exec mode is set to DisabledLocked and the three configuration
80  * pointers are set to kHardenedBoolFalse.
81  *
82  * @param config A pointer to a config struct holding pointers to config items.
83  */
84 void owner_config_default(owner_config_t *config);
85 
86 /**
87  * Parse an owner block, extracting pointers to keys and configuration items.
88  *
89  * @param block The owner block to parse.
90  * @param config A pointer to a config struct holding pointers to config items.
91  * @param keyring A pointer to a keyring struct holding application key
92  * pointers.
93  * @return error code.
94  */
95 rom_error_t owner_block_parse(const owner_block_t *block,
96  owner_config_t *config,
98 
99 /**
100  * Check the flash config for errors.
101  *
102  * Currently, this checks that a flash config region covering the ROM_EXT
103  * is compatible with the default flash config region.
104  *
105  * @param flash A pointer to a flash configuration struct.
106  * @return error code.
107  */
108 rom_error_t owner_block_flash_check(const owner_flash_config_t *flash);
109 
110 /**
111  * Apply the flash configuration parameters from the owner block.
112  *
113  * @param flash A pointer to a flash configuration struct.
114  * @param config_side Which side of the flash to configure.
115  * @param lockdown Apply any special lockdown configuration to the specified
116  * side of the flash. May use kHardenedBoolFalse to skip
117  * lockdown.
118  * @return error code.
119  */
120 rom_error_t owner_block_flash_apply(const owner_flash_config_t *flash,
121  uint32_t config_side, uint32_t lockdown);
122 
123 /**
124  * Apply the flash info configuration parameters from the owner block.
125  *
126  * @param info A pointer to a flash_info configuration.
127  * @return error code.
128  */
129 rom_error_t owner_block_info_apply(const owner_flash_info_config_t *info);
130 
131 rom_error_t owner_keyring_find_key(const owner_application_keyring_t *keyring,
132  uint32_t key_alg, uint32_t key_id,
133  size_t *index);
134 
135 /**
136  * Determine whether the given key is on owner page 0 or page 1.
137  *
138  * @return page number.
139  */
140 size_t owner_block_key_page(const owner_application_key_t *key);
141 
142 /**
143  * Determine whether a particular rescue command is allowed.
144  *
145  * @param rescue A pointer to the rescue configuration.
146  * @param command The rescue command to check.
147  * @return kHardenedBoolTrue if allowed.
148  */
149 hardened_bool_t owner_rescue_command_allowed(
150  const owner_rescue_config_t *rescue, uint32_t command);
151 
152 /**
153  * Measure the content of the owner page.
154  *
155  * @param page The owner page to measure.
156  * @param measurement The measurement value.
157  */
158 void owner_block_measurement(size_t page, hmac_digest_t *mesaurment);
159 #ifdef __cplusplus
160 } // extern "C"
161 #endif // __cplusplus
162 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_OWNERSHIP_OWNER_BLOCK_H_