Software APIs
sigverify_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_EXT_SIGVERIFY_KEYS_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_EXT_SIGVERIFY_KEYS_H_
7 
8 #include <stdint.h>
9 
10 #include "sw/device/silicon_creator/lib/error.h"
11 #include "sw/device/silicon_creator/lib/sigverify/rsa_key.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif // __cplusplus
16 
17 /**
18  * ROM_EXT Key types.
19  *
20  * ROM_EXT key types are unlike ROM key types:
21  * - ROM key types are bound to certain lifecycle states. ROM_EXT keys types
22  * are not.
23  * - ROM_EXT key types affect keymgr diversification. This prevents the
24  * different keys types from being able to derive the same secrets.
25  *
26  * To distinguish these types from ROM key types, we refer to them as firmware
27  * keys.
28  *
29  * Encoding generated with
30  * $ ./util/design/sparse-fsm-encode.py -d 6 -m 3 -n 32 \
31  * -s 1985033815 --language=c
32  *
33  * Minimum Hamming distance: 15
34  * Maximum Hamming distance: 18
35  * Minimum Hamming weight: 13
36  * Maximum Hamming weight: 16
37  */
38 typedef enum sigverify_key_type {
39  /**
40  * A testing key.
41  */
42  kSigverifyKeyTypeFirmwareTest = 0x3ff0c819,
43  /**
44  * A production key.
45  */
46  kSigverifyKeyTypeFirmwareProd = 0x43a839ad,
47  /**
48  * A development key.
49  */
50  kSigverifyKeyTypeFirmwareDev = 0x7a01a471,
51 } sigverify_key_type_t;
52 
53 /**
54  * An RSA public key stored in ROM.
55  */
56 typedef struct sigverify_rom_ext_key {
57  /**
58  * An RSA public key.
59  */
61  /**
62  * Type of the key.
63  */
64  sigverify_key_type_t key_type;
66 
67 /**
68  * Number of RSA public keys.
69  */
70 extern const size_t kSigverifyRsaKeysCnt;
71 
72 /**
73  * Step size to use when checking RSA public keys.
74  *
75  * This must be coprime with and less than `kSigverifyNumRsaKeys`.
76  * Note: Step size is not applicable when `kSigverifyNumRsaKeys` is 1.
77  */
78 extern const size_t kSigverifyRsaKeysStep;
79 
80 /**
81  * Public keys for signature verification.
82  */
83 extern const sigverify_rom_ext_key_t kSigverifyRsaKeys[];
84 
85 /**
86  * Returns the key with the given ID.
87  *
88  * This function returns the key only if it can be used in the given life cycle
89  * state and is valid in OTP. OTP check is performed only if the device is in a
90  * non-test operational state (PROD, PROD_END, DEV, RMA).
91  *
92  * @param key_id A key ID.
93  * @param lc_state Life cycle state of the device.
94  * @param key Key with the given ID, valid only if it exists.
95  * @return Result of the operation.
96  */
98 rom_error_t sigverify_rsa_key_get(uint32_t key_id,
99  const sigverify_rsa_key_t **key);
100 
101 #ifdef __cplusplus
102 } // extern "C"
103 #endif // __cplusplus
104 
105 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_EXT_SIGVERIFY_KEYS_H_