Skip to content

Commit eee2b32

Browse files
committed
[ot] hw/opentitan: ot_keymgr: Implement sideloaded key clearing
Implements basic functionality for clearing the sideloaded keys, which for now just zeroes out the keys, as wiping with entropy is not yet implemented. Signed-off-by: Alex Jones <[email protected]>
1 parent bde1ed4 commit eee2b32

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

hw/opentitan/ot_keymgr.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,20 @@ static const char *KEY_SINK_NAMES[] = {
575575
KEY_SINK_NAMES[(_st_)] : \
576576
"?")
577577

578+
#define SIDELOAD_CLEAR_ENTRY(_st_) \
579+
[KEYMGR_SIDELOAD_CLEAR_##_st_] = stringify(_st_)
580+
static const char *SIDELOAD_CLEAR_NAMES[] = {
581+
SIDELOAD_CLEAR_ENTRY(NONE),
582+
SIDELOAD_CLEAR_ENTRY(AES),
583+
SIDELOAD_CLEAR_ENTRY(KMAC),
584+
SIDELOAD_CLEAR_ENTRY(OTBN),
585+
};
586+
#undef SIDELOAD_CLEAR_ENTRY
587+
#define SIDELOAD_CLEAR_NAME(_st_) \
588+
(((unsigned)(_st_)) < ARRAY_SIZE(SIDELOAD_CLEAR_NAMES) ? \
589+
SIDELOAD_CLEAR_NAMES[(_st_)] : \
590+
"?")
591+
578592
#define WORKING_STATE_ENTRY(_st_) \
579593
[KEYMGR_WORKING_STATE_##_st_] = stringify(_st_)
580594
static const char *WORKING_STATE_NAMES[] = {
@@ -901,6 +915,39 @@ static void ot_keymgr_push_kdf_key(OtKeyMgrState *s, const uint8_t *key_share0,
901915
false);
902916
}
903917

918+
static void ot_keymgr_sideload_clear(OtKeyMgrState *s)
919+
{
920+
int sideload_clear =
921+
(int)FIELD_EX32(s->regs[R_SIDELOAD_CLEAR], SIDELOAD_CLEAR, VAL);
922+
923+
trace_ot_keymgr_sideload_clear(s->ot_id,
924+
SIDELOAD_CLEAR_NAME(sideload_clear),
925+
sideload_clear);
926+
927+
/* @todo: this should use random dummy data instead */
928+
uint8_t share0[KEYMGR_KEY_SIZE_MAX] = { 0 };
929+
uint8_t share1[KEYMGR_KEY_SIZE_MAX] = { 0 };
930+
931+
switch (sideload_clear) {
932+
case KEYMGR_SIDELOAD_CLEAR_NONE:
933+
break;
934+
case KEYMGR_SIDELOAD_CLEAR_AES:
935+
case KEYMGR_SIDELOAD_CLEAR_OTBN:
936+
case KEYMGR_SIDELOAD_CLEAR_KMAC: {
937+
OtKeyMgrKeySink sink =
938+
(OtKeyMgrKeySink)(sideload_clear - KEY_SINK_OFFSET);
939+
ot_keymgr_push_key(s, sink, share0, share1, false, true);
940+
break;
941+
}
942+
default:
943+
/* continuously clear ALL slots if a non-enumerated value is written */
944+
for (unsigned ix = 0; ix < KEYMGR_KEY_SINK_COUNT; ix++) {
945+
ot_keymgr_push_key(s, (OtKeyMgrKeySink)ix, share0, share1, false,
946+
true);
947+
}
948+
}
949+
}
950+
904951
/* check that 'data' is not all zeros or all ones */
905952
static bool ot_keymgr_valid_data_check(const uint8_t *data, size_t len)
906953
{
@@ -1990,7 +2037,7 @@ static void ot_keymgr_write(void *opaque, hwaddr addr, uint64_t val64,
19902037
}
19912038
val32 &= R_SIDELOAD_CLEAR_VAL_MASK;
19922039
s->regs[reg] = val32;
1993-
/* @todo: implement R_SIDELOAD_CLEAR */
2040+
ot_keymgr_sideload_clear(s);
19942041
break;
19952042
case R_RESEED_INTERVAL_REGWEN:
19962043
val32 &= R_RESEED_INTERVAL_REGWEN_EN_MASK;

hw/opentitan/trace-events

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ ot_keymgr_reset(const char *id, const char *stage) "%s: %s"
303303
ot_keymgr_restore_kmac_key(const char *id) "%s"
304304
ot_keymgr_schedule_fsm(const char *id, const char *func, int line) "%s @ %s:%d"
305305
ot_keymgr_seed_missing(const char *id, unsigned ix) "%s: #%u"
306+
ot_keymgr_sideload_clear(const char *id, const char *sc, unsigned nsc) "%s: [%s:%u]"
306307
ot_keymgr_update_alert(const char *id, int prev, int next) "%s: %d -> %d"
307308

308309
# ot_keymgr_dpe.c

0 commit comments

Comments
 (0)