Skip to content

Commit 845359e

Browse files
committed
pta: qcom: ice: Add support for invalidating ICE slot key
Add support for invalidating a previously programmed key from the inline crypto engine's (ICE) key slot via the hardware key manager. Signed-off-by: Harshal Dev <harshal.dev@oss.qualcomm.com>
1 parent c562a0a commit 845359e

4 files changed

Lines changed: 63 additions & 1 deletion

File tree

core/pta/qcom/ice/hwkm/ice_hwkm.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,44 @@ static TEE_Result get_or_init_ephemeral_ctx(const uint8_t **ctx,
5454
return TEE_SUCCESS;
5555
}
5656

57+
TEE_Result clear_ice_slave_slot_hwkm(uint32_t slot)
58+
{
59+
struct hwkm_transaction t_clear = {
60+
.cmd = {
61+
.op = HWKM_OP_KEY_SLOT_CLEAR,
62+
.clear = {
63+
.dks = 0,
64+
.is_double_key = true,
65+
},
66+
},
67+
};
68+
int rc = HWKM_ERR_GENERIC;
69+
70+
if (slot >= ICE_MAX_KEY_IDX)
71+
return TEE_ERROR_BAD_PARAMETERS;
72+
73+
/* Disable slot first so stale key/config cannot be used. */
74+
io_write32_off_field(ICE_LUT_KEYS, ICE_CRYPTOCFG_r_16_OFF(slot),
75+
ICE_CRYPTOCFG_r_16_CFGE_BMSK,
76+
0x0);
77+
78+
t_clear.cmd.clear.dks = HWKM_ICE_MAP_SLOT(slot);
79+
80+
rc = hwkm_run_transaction(HWKM_KEY_DEST_ICE_SLAVE, &t_clear);
81+
if (rc)
82+
return hwkm_to_optee(rc);
83+
84+
if (t_clear.rsp.status != HWKM_RSP_ERR_SUCCESS &&
85+
t_clear.rsp.status != HWKM_CLEAR_ERR_DKS_SLOT_EMPTY) {
86+
EMSG("ICE invalidate clear failed: slot=%u mapped=%u status=0x%x",
87+
slot, (unsigned int)t_clear.cmd.clear.dks,
88+
(unsigned int)t_clear.rsp.status);
89+
return TEE_ERROR_GENERIC;
90+
}
91+
92+
return TEE_SUCCESS;
93+
}
94+
5795
/*
5896
* export_tpkey_wrapped_blob_from_ephemeral() - Unwrap input blob under
5997
* ephemeral wrapping key, then re-wrap/export under TPKEY.

core/pta/qcom/ice/hwkm/ice_hwkm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <tee_api_types.h>
1010

11+
TEE_Result clear_ice_slave_slot_hwkm(uint32_t slot);
12+
1113
TEE_Result set_config_ice_key_using_hwkm(uint32_t slot,
1214
const uint8_t *wrapped_blob,
1315
size_t wrapped_blob_len);
@@ -20,4 +22,4 @@ TEE_Result import_and_wrap_with_hw_key(const uint8_t *in_key, size_t in_key_len,
2022

2123
TEE_Result generate_hw_wrapped_key(uint8_t *out_blob, size_t *out_blob_len);
2224

23-
#endif /* __ICE_HWKM_H */
25+
#endif /* __ICE_HWKM_H */

core/pta/qcom/ice/ice.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111
#include <drivers/hwkm.h>
1212
#include "hwkm/ice_hwkm.h"
1313

14+
static TEE_Result cmd_ice_invalidate_key(uint32_t param_types,
15+
TEE_Param params[TEE_NUM_PARAMS])
16+
{
17+
const uint32_t exp_pt = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT,
18+
TEE_PARAM_TYPE_NONE,
19+
TEE_PARAM_TYPE_NONE,
20+
TEE_PARAM_TYPE_NONE);
21+
22+
if (param_types != exp_pt)
23+
return TEE_ERROR_BAD_PARAMETERS;
24+
25+
return clear_ice_slave_slot_hwkm(params[0].value.a);
26+
}
27+
1428
static TEE_Result cmd_ice_set_config_key(uint32_t param_types,
1529
TEE_Param params[TEE_NUM_PARAMS])
1630
{
@@ -144,6 +158,8 @@ static TEE_Result invoke_command(void *sess_ctx __unused, uint32_t cmd_id,
144158
TEE_Param params[TEE_NUM_PARAMS])
145159
{
146160
switch (cmd_id) {
161+
case PTA_CMD_ICE_INVALIDATE_KEY:
162+
return cmd_ice_invalidate_key(param_types, params);
147163
case PTA_CMD_ICE_SET_CONFIG_KEY:
148164
return cmd_ice_set_config_key(param_types, params);
149165
case PTA_CMD_ICE_GENERATE_KEY:

lib/libutee/include/pta_qcom_ice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
{ 0x29e87b9e, 0x012a, 0x4878, \
1818
{ 0xa1, 0xe1, 0xa1, 0xb9, 0x0a, 0x21, 0x5b, 0x16 } }
1919

20+
/*
21+
* Invalidate ICE key slot - overwrite key registers with random data
22+
* [in] params[0].value.a Key slot index (0..ICE_MAX_KEY_IDX-1)
23+
*/
24+
#define PTA_CMD_ICE_INVALIDATE_KEY 0
25+
2026
/*
2127
* Program ICE key slot with key material and full configuration
2228
* [in] params[0].value.a Key slot index (0..ICE_MAX_KEY_IDX-1)

0 commit comments

Comments
 (0)