Software APIs
keymgr_dpe_testutils.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_LIB_TESTING_KEYMGR_DPE_TESTUTILS_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_KEYMGR_DPE_TESTUTILS_H_
7 
8 #include "sw/device/lib/base/status.h"
10 
11 /**
12  * Locks OTP, restarts and initializes keymgr_dpe with UDS (a.k.a. the OTP
13  * root key).
14  *
15  * This procedure essentially gets the keymgr_dpe into the stage where it
16  * can be used for tests. An example is given below:
17  * ```
18  * void test_main(void) {
19  * // The following sets up keymgr_dpe and asks it to latch UDS.
20  * dif_keymgr_dpe_t keymgr_dpe;
21  * keymgr_dpe_testutils_startup(&keymgr_dpe);
22  *
23  * // Remainder of test; optionally advance to CreatorRootKey state, generate
24  * // keys and identities.
25  * ...
26  * }
27  * ```
28  *
29  * @param[out] keymgr_dpe A key manager handle, may be uninitialized.
30  * @return The result of the operation.
31  */
33 status_t keymgr_dpe_testutils_startup(dif_keymgr_dpe_t *keymgr_dpe,
34  uint32_t slot_dst_sel);
35 
36 /**
37  * Issues a keymgr_dpe advance operation and wait for it to complete.
38  *
39  * @param keymgr_dpe A key manager handle.
40  * @param params Inputs that are consumed by HW during advance operation.
41  * @return The result of the operation.
42  */
44 status_t keymgr_dpe_testutils_advance_state(
45  const dif_keymgr_dpe_t *keymgr_dpe,
46  const dif_keymgr_dpe_advance_params_t *params);
47 
48 /**
49  * Issues a keymgr_dpe key generation operation and wait for it to complete.
50  *
51  * @param keymgr_dpe A key manager handle.
52  * @param params Inputs that are consumed by HW during generate operation.
53  * @return The result of the operation.
54  */
56 status_t keymgr_dpe_testutils_generate(
57  const dif_keymgr_dpe_t *keymgr_dpe,
60 
61 /**
62  * Erase a keymgr_dpe slot.
63  *
64  * @param keymgr_dpe A key manager handle.
65  * @param params A wrapper struct that contains the destination slot to be
66  * erased.
67  * @return The result of the operation.
68  */
70 status_t keymgr_dpe_testutils_erase_slot(
71  const dif_keymgr_dpe_t *keymgr_dpe,
72  const dif_keymgr_dpe_erase_params_t *params);
73 
74 /**
75  * Checks if the current keymgr_dpe state matches the expected state
76  *
77  * @param keymgr_dpe A key manager handle.
78  * @param exp_state The expected key manager state.
79  * @return The result of the operation.
80  */
82 status_t keymgr_dpe_testutils_check_state(
83  const dif_keymgr_dpe_t *keymgr_dpe, const dif_keymgr_dpe_state_t exp_state);
84 
85 /**
86  * Polling keymgr_dpe status until it becomes idle.
87  * Fail the test if the status code indicates any error.
88  *
89  * @param keymgr_dpe A key manager handle.
90  * @return The result of the operation.
91  */
93 status_t keymgr_dpe_testutils_wait_for_operation_done(
94  const dif_keymgr_dpe_t *keymgr_dpe);
95 
96 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_KEYMGR_DPE_TESTUTILS_H_