Software APIs
sigverify_otp_keys.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_ROM_SIGVERIFY_OTP_KEYS_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_SIGVERIFY_OTP_KEYS_H_
7 
8 #include <stdint.h>
9 
11 #include "sw/device/silicon_creator/lib/drivers/hmac.h"
12 #include "sw/device/silicon_creator/lib/drivers/lifecycle.h"
13 #include "sw/device/silicon_creator/lib/error.h"
14 #include "sw/device/silicon_creator/rom/sigverify_key_types.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif // __cplusplus
19 
20 enum {
21  /**Maximum number of ECDSA keys supported in OTP. */
22  kSigVerifyOtpKeysEcdsaCount = 4,
23  /**Maximum number of SPX keys supported in OTP. */
24  kSigVerifyOtpKeysSpxCount = 4,
25 };
26 
27 /**
28  * SRAM representation of the OTP `ROT_CREATOR_AUTH_CODESIGN` partition.
29  *
30  * The data is loaded into SRAM via `sigverify_otp_keys_init()` and its
31  * integrity is verified by `sigverify_otp_keys_check()` before use.
32  *
33  * Static assertions are used inside the implementation to ensure that the size
34  * of the data structure matches the size of the OTP partition.
35  */
36 typedef struct sigverify_otp_keys {
37  /**
38  * ECDSA P-256 keys.
39  */
40  sigverify_rom_ecdsa_p256_key_t ecdsa[kSigVerifyOtpKeysEcdsaCount];
41  /**
42  * SPX keys.
43  */
44  sigverify_rom_spx_key_t spx[kSigVerifyOtpKeysSpxCount];
45  /**
46  * HMAC digest of the ECDSA and SPX keys.
47  */
50 
51 /**
52  * SRAM representation of the OTP `ROT_CREATOR_AUTH_STATE` partition.
53  *
54  * The data is loaded into SRAM via `sigverify_otp_keys_init()` and its
55  * integrity is verified by `sigverify_otp_keys_check()` before use.
56  *
57  * Static assertions are used inside the implementation to ensure that the size
58  * of the data structure matches the size of the OTP partition.
59  */
60 typedef struct sigverify_otp_key_states {
61  /**
62  * State of the ECDSA P-256 keys.
63  */
64  uint32_t ecdsa[kSigVerifyOtpKeysEcdsaCount];
65  /**
66  * State of the SPX keys.
67  */
68  uint32_t spx[kSigVerifyOtpKeysSpxCount];
70 
71 /**
72  * Context for OTP keys loaded into SRAM.
73  */
74 typedef struct sigverify_otp_key_ctx {
75  /**
76  * ECDSA and SPX keys.
77  */
79  /**
80  * Key states.
81  */
84 
85 /**
86  * Input parameters for `sigverify_otp_keys_get()`.
87  */
89  /**
90  * A key ID.
91  */
92  uint32_t key_id;
93  /**
94  * Life cycle state of the device.
95  */
96  lifecycle_state_t lc_state;
97  /**
98  * Array in which the requested key is searched for.
99  */
101 
102  /**
103  * Number of keys in `key_array`.
104  */
105  size_t key_cnt;
106  /**
107  * Size of each entry in `key_array`.
108  */
109  size_t key_size;
110 
111  uint32_t *key_states;
113 
114 /**
115  * Initializes the OTP keys context.
116  *
117  * @param ctx Context for OTP keys loaded into SRAM.
118  * @return The result of the operation.
119  */
121 rom_error_t sigverify_otp_keys_init(sigverify_otp_key_ctx_t *ctx);
122 
123 /**
124  * Verifies the integrity of the OTP keys.
125  *
126  * @param ctx Context for OTP keys loaded into SRAM.
127  * @return The result of the operation.
128  */
130 rom_error_t sigverify_otp_keys_check(sigverify_otp_key_ctx_t *ctx);
131 
132 /**
133  * Gets a key from the OTP keys array.
134  *
135  * @param params Input parameters.
136  * @param[out] key A pointer to the requested key.
137  * @return The result of the operation.
138  */
139 rom_error_t sigverify_otp_keys_get(sigverify_otp_keys_get_params_t params,
140  const sigverify_rom_key_header_t **key);
141 
142 #ifdef __cplusplus
143 } // extern "C"
144 #endif // __cplusplus
145 
146 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_SIGVERIFY_OTP_KEYS_H_