Software APIs
dif_keymgr_dpe.h
Go to the documentation of this file.
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_LIB_DIF_DIF_KEYMGR_DPE_H_
6
#define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_KEYMGR_DPE_H_
7
8
/**
9
* @file
10
* @brief <a href="/book/hw/ip/keymgr_dpe/">Key Manager DPE</a> Device Interface
11
* Functions
12
*/
13
14
#include <stdint.h>
15
16
#include "
sw/device/lib/base/macros.h
"
17
#include "
sw/device/lib/base/mmio.h
"
18
#include "
sw/device/lib/dif/dif_base.h
"
19
20
#include "
sw/device/lib/dif/autogen/dif_keymgr_dpe_autogen.h
"
21
22
#ifdef __cplusplus
23
extern
"C"
{
24
#endif
// __cplusplus
25
26
/**
27
* SW-visible key manager DPE states.
28
*
29
* Key manager RTL has more than 4 finite state machine (FSM) states, but it
30
* simply truncates the reported state into four states given below. The reason
31
* behind this truncation is that FSM lingers on some states temporarily (i.e.
32
* few clock cycles) and the transition into the next state does not require
33
* further invocation.
34
*
35
* From SW point of view, key manager FSM transitions follow a sequence
36
* sequential manner and these transitions are irreversible until a power cycle.
37
*/
38
typedef
enum
dif_keymgr_dpe_state
{
39
kDifKeymgrDpeStateReset = 0,
40
kDifKeymgrDpeStateAvailable = 1,
41
kDifKeymgrDpeStateDisabled = 2,
42
kDifKeymgrDpeStateInvalid = 3
43
}
dif_keymgr_dpe_state_t
;
44
45
/**
46
* Enumeration for side load slot clearing.
47
*/
48
typedef
enum
dif_keymgr_sideload_clr
{
49
kDifKeymgrDpeSideLoadClearNone = 0,
50
kDifKeymgrDpeSideLoadClearAes = 1,
51
kDifKeymgrDpeSideLoadClearKmac = 2,
52
kDifKeymgrDpeSideLoadClearOtbn = 3,
53
// Using different value than those enumerated above should clear all slots,
54
// so we can use the mask value of this field to denote ALL case.
55
kDifKeymgrDpeSideLoadClearAll = 7,
56
}
dif_keymgr_dpe_sideload_clr_t
;
57
58
/**
59
* Runtime configuration for keymgr dpe.
60
*/
61
typedef
struct
dif_keymgr_dpe_config
{
62
/**
63
* Number of keymgr_dpe cycles before the entropy is reseeded.
64
*
65
* Keymgr dpe uses random values generated by the entropy source for
66
* initializing its state and clearing sideload keys. This value determines
67
* the frequency at which this random value is updated.
68
*/
69
uint16_t
entropy_reseed_interval
;
70
}
dif_keymgr_dpe_config_t
;
71
72
/**
73
* Input parameters for advancing a DPE context/slot.
74
*/
75
typedef
struct
dif_keymgr_dpe_advance_params
{
76
/**
77
* This value is used by key manager as input to DICE computation and can be
78
* either a value that represents the measurement of a boot stage or simply a
79
* tag from a manifest.
80
*/
81
uint32_t
binding_value
[8];
82
83
/**
84
* Maximum allowed version for keys to be generated at a state. This value is
85
* stored inside keymgr slot so that it can later be compared against the
86
* `key_version` input provided along with generation request.
87
*/
88
uint32_t
max_key_version
;
89
90
/**
91
* The source slot to be used as parent DPE context.
92
*/
93
uint32_t
slot_src_sel
;
94
95
/**
96
* The destination slot which recieves the derived child DPE context.
97
*/
98
uint32_t
slot_dst_sel
;
99
100
/**
101
* The slot policy bits for the derived child DPE context.
102
*/
103
uint32_t
slot_policy
;
104
}
dif_keymgr_dpe_advance_params_t
;
105
106
/**
107
* Key destination of a versioned key generation operation.
108
*
109
* Regardless of whether the generated key is SW or sideload key, HW uses a
110
* unique diversification constant for each cryptographic use case. In the case
111
* of sideload key, this enum value is also used to determine the target
112
* peripheral port to which the generated key is loaded.
113
*/
114
typedef
enum
dif_keymgr_dpe_key_dest
{
115
/**
116
* Diversify the generated key for no HW IP (and don't sideload it).
117
*/
118
kDifKeymgrDpeKeyDestNone
= 0,
119
/**
120
* Diversify the generated key for AES (and load it to AES peripheral port if
121
* sideload key).
122
*/
123
kDifKeymgrDpeKeyDestAes
= 1,
124
/**
125
* Diversify the generated key for KMAC (and load it to KMAC peripheral port
126
* if sideload key).
127
*/
128
kDifKeymgrDpeKeyDestKmac
= 2,
129
/**
130
* Diversify the generated key for OTBN (and load it to OTBN peripheral port
131
* if sideload key).
132
*/
133
kDifKeymgrDpeKeyDestOtbn
= 3,
134
}
dif_keymgr_dpe_key_dest_t
;
135
136
/**
137
* Input parameters for advancing a DPE context/slot.
138
*/
139
typedef
struct
dif_keymgr_dpe_generate_params
{
140
/**
141
* Destination for {AES, KMAC, OTBN}, which is used for diversification.
142
*/
143
dif_keymgr_dpe_key_dest_t
key_dest
;
144
145
/**
146
* Set to true, if this is a sideload key, otherwise set to false.
147
*/
148
bool
sideload_key
;
149
150
/**
151
* Salt value used as input for key generation (i.e. becomes part of the
152
* message payload sent to KMAC during computation).
153
*/
154
uint32_t
salt
[8];
155
156
/**
157
* The key version used for generating versioned key. This value should not be
158
* greater than the `max_key_version` value stored inside the source slot that
159
* is used to generate the key.
160
*/
161
uint32_t
version
;
162
163
/**
164
* The source slot from which the key is derived.
165
*/
166
uint32_t
slot_src_sel
;
167
}
dif_keymgr_dpe_generate_params_t
;
168
169
/**
170
* Input parameters for erasing a DPE context/slot.
171
*/
172
typedef
struct
dif_keymgr_dpe_erase_params
{
173
/**
174
* Index for the slot to be erased.
175
*/
176
uint32_t
slot_dst_sel
;
177
}
dif_keymgr_dpe_erase_params_t
;
178
179
/**
180
* Useed to represent the output of SW generated key.
181
*/
182
typedef
struct
dif_keymgr_dpe_output
{
183
uint32_t value[2][8];
184
}
dif_keymgr_dpe_output_t
;
185
186
/**
187
* Status code bit flags.
188
*
189
* See also: `dif_keymgr_dpe_status_codes_t`.
190
*/
191
typedef
enum
dif_keymgr_dpe_status_code
{
192
/**
193
* Key manager is idle.
194
*/
195
kDifKeymgrDpeStatusCodeIdle
= 1 << 0,
196
/**
197
* Software invoked an invalid operation.
198
*/
199
kDifKeymgrDpeStatusCodeInvalidOperation
= 1 << 1,
200
/**
201
* Key manager issued invalid data to KMAC interface.
202
*/
203
kDifKeymgrDpeStatusCodeInvalidKmacInput
= 1 << 2,
204
/**
205
* Key manager encountered invalid state.
206
*/
207
kDifKeymgrDpeStatusCodeInvalidState
= 1 << 3,
208
209
}
dif_keymgr_dpe_status_code_t
;
210
211
/**
212
* Define mask for error fields of `dif_keymgr_dpe_status_code_t`.
213
*/
214
static
const
bitfield_field32_t
kIdleBitfield = (
bitfield_field32_t
){
215
.mask = 0x1,
216
.index = 0,
217
};
218
219
/**
220
* Define mask for idle field of `dif_keymgr_dpe_status_code_t`.
221
*/
222
static
const
bitfield_field32_t
kErrorBitfield = (
bitfield_field32_t
){
223
.mask = 0x7,
224
.index = 1,
225
};
226
227
/**
228
* A bit vector of status codes.
229
*
230
* The following snippet can be used to check if key manager is idle:
231
*
232
* `bool is_idle = (status_codes & kDifKeymgrDpeStatusCodeIdle);`
233
*
234
* The following snippet can be used to check if key manager is idle and
235
* error-free:
236
*
237
* `bool is_idle_and_ok = (status_codes == kDifKeymgrDpeStatusCodeIdle);`
238
*
239
* See also: `dif_keymgr_dpe_status_code_t`.
240
*/
241
typedef
uint8_t
dif_keymgr_dpe_status_codes_t
;
242
243
/**
244
* Initializes the keymgr_pde block by performing an advance operation.
245
*
246
* The hardware does not have an explicit initialize command. Initialization is
247
* simple the first advance call without software binding, max version or
248
* policy registers set. Use this call before calling
249
* `dif_keymgr_dpe_advance_state()`.
250
*
251
* @param keymgr_dpe A key manager handle.
252
* @param slot_dst_sel Target slot used to latch the UDS key.
253
* @return The result of the operation.
254
*/
255
dif_result_t
dif_keymgr_dpe_initialize
(
const
dif_keymgr_dpe_t
*keymgr_dpe,
256
uint32_t slot_dst_sel);
257
258
/**
259
* Advances a keymgr_dpe slot with given parameters.
260
*
261
* @param keymgr_dpe A key manager handle.
262
* @param params Struct to pass inputs consumed by HW during advance.
263
* @return The result of the operation.
264
*/
265
OT_WARN_UNUSED_RESULT
266
dif_result_t
dif_keymgr_dpe_advance_state
(
267
const
dif_keymgr_dpe_t
*keymgr_dpe,
268
const
dif_keymgr_dpe_advance_params_t
*params);
269
270
/**
271
* Erases a given keymgr_dpe slot.
272
*
273
* @param keymgr_dpe A key manager handle.
274
* @param params A struct that selects the slot to be erased.
275
* @return The result of the operation.
276
*/
277
OT_WARN_UNUSED_RESULT
278
dif_result_t
dif_keymgr_dpe_erase_slot
(
279
const
dif_keymgr_dpe_t
*keymgr_dpe,
280
const
dif_keymgr_dpe_erase_params_t
*params);
281
282
/**
283
* Disables key manager dpe.
284
*
285
* This function disables keymgr dpe until the next power cycle by making
286
* it transition to the "disabled" state. The "disabled" state is a terminal
287
* state where the keymgr dpe is no longer operational and its secret values
288
* are wiped.
289
*
290
* @param keymgr_dpe A key manager handle.
291
* @return The result of the operation.
292
*/
293
OT_WARN_UNUSED_RESULT
294
dif_result_t
dif_keymgr_dpe_disable
(
const
dif_keymgr_dpe_t
*keymgr_dpe);
295
296
/**
297
* Generate a SW/HW key from a chosen keymgr_dpe slot.
298
*
299
* @param keymgr_dpe A key manager handle.
300
* @param params Struct to pass inputs consumed by HW generate operation.
301
* @return The result of the operation.
302
*/
303
OT_WARN_UNUSED_RESULT
304
dif_result_t
dif_keymgr_dpe_generate
(
305
const
dif_keymgr_dpe_t
*keymgr_dpe,
306
const
dif_keymgr_dpe_generate_params_t
*params);
307
308
/**
309
* Gets the operational status of keymgr_dpe.
310
*
311
* This function also clears OP_STATUS and ERR_CODE registers after reading
312
* them.
313
*
314
* @param keymgr_dpe A key manager handle.
315
* @param[out] status_codes Out-param for key manager status codes.
316
* @return The result of the operation.
317
*/
318
OT_WARN_UNUSED_RESULT
319
dif_result_t
dif_keymgr_dpe_get_status_codes
(
320
const
dif_keymgr_dpe_t
*keymgr_dpe,
321
dif_keymgr_dpe_status_codes_t
*status_codes);
322
323
/**
324
* Gets the current state of key manager.
325
*
326
* @param keymgr_dpe A key manager handle.
327
* @param[out] state Out-param for current key manager state.
328
* @return The result of the operation.
329
*/
330
OT_WARN_UNUSED_RESULT
331
dif_result_t
dif_keymgr_dpe_get_state
(
const
dif_keymgr_dpe_t
*keymgr_dpe,
332
dif_keymgr_dpe_state_t
*state);
333
334
/**
335
* Read the value of SW generated key from its related CSR. It is the
336
* responsibility of the caller to check that key generation has completed.
337
*
338
* @param keymgr_dpe A key manager handle.
339
* @param[out] output The key value in two shares.
340
* @return The result of the operation.
341
*/
342
OT_WARN_UNUSED_RESULT
343
dif_result_t
dif_keymgr_dpe_read_output
(
const
dif_keymgr_dpe_t
*keymgr_dpe,
344
dif_keymgr_dpe_output_t
*output);
345
346
/**
347
* Starts or stops clearing of sideload keys.
348
*
349
* Selecting a sideload destination other than `kDifKeymgrDpeSideLoadClearNone`
350
* causes keymgr_dpe to continuously overwrite the corresponding sideload key
351
* port with randomness (Destination can either be AES, KMAC or OTBN).
352
* Any value that is not one of the enumerated destinations clears all sideload
353
* key ports. To resume normal operation, call this function again with
354
* `kDifKeymgrDpeSideLoadClearNone` to stop the clearing.
355
*
356
* @param keymgr_dpe A key manager handle.
357
* @param clear_dest Target sideload key.
358
* @return The result of the operation.
359
*/
360
OT_WARN_UNUSED_RESULT
361
dif_result_t
dif_keymgr_dpe_clear_sideload_key
(
362
const
dif_keymgr_dpe_t
*keymgr_dpe,
363
dif_keymgr_dpe_sideload_clr_t
clear_dest);
364
365
/**
366
* Runtime configuration for keymgr dpe.
367
*
368
* @param keymgr_dpe A key manager handle.
369
* @param config configuration for the keymgr dpe.
370
* @return The result of the operation.
371
*/
372
OT_WARN_UNUSED_RESULT
373
dif_result_t
dif_keymgr_dpe_configure
(
const
dif_keymgr_dpe_t
*keymgr_dpe,
374
dif_keymgr_dpe_config_t
config);
375
376
#ifdef __cplusplus
377
}
// extern "C"
378
#endif
// __cplusplus
379
380
#endif
// OPENTITAN_SW_DEVICE_LIB_DIF_DIF_KEYMGR_DPE_H_
sw
device
lib
dif
dif_keymgr_dpe.h
Return to
OpenTitan Documentation