Skip to content

Commit 0a77734

Browse files
committed
[ot] hw/opentitan: ot_keymgr: Model KMAC_DONE and KMAC_OUT faults
Though we likely wouldn't expect to see either of these faults in QEMU when everything is working, modeling these faults helps both more closely align with the actual HW, and should help debugging the QEMU model if errors do occur (e.g a KMAC issue could manifest as a `KMAC_OUT` fault in the `keymgr`, aiding in debugging). Signed-off-by: Alex Jones <[email protected]>
1 parent 83d5671 commit 0a77734

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

hw/opentitan/ot_keymgr.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,8 +1246,6 @@ static void ot_keymgr_operation_advance(OtKeyMgrState *s, OtKeyMgrStage stage,
12461246
trace_ot_keymgr_advance(s->ot_id, STAGE_NAME(stage), (int)stage,
12471247
CDI_NAME(cdi), (int)cdi);
12481248

1249-
/* @todo: do we need to check for any error states here? */
1250-
12511249
ot_keymgr_reset_kdf_buffer(s);
12521250

12531251
size_t expected_kdf_len = 0u;
@@ -1564,13 +1562,38 @@ ot_keymgr_handle_kmac_response(void *opaque, const OtKMACAppRsp *rsp)
15641562
}
15651563
}
15661564

1565+
if (!s->op_state.op_req) {
1566+
/* KMAC response when we weren't expecting one */
1567+
s->regs[R_FAULT_STATUS] |= R_FAULT_STATUS_KMAC_DONE_MASK;
1568+
ot_keymgr_update_alerts(s);
1569+
ot_keymgr_schedule_fsm(s);
1570+
return;
1571+
}
1572+
15671573
if (!rsp->done) {
15681574
/* not the last response from KMAC, send more data */
15691575
ot_keymgr_send_kmac_req(s);
15701576
return;
15711577
}
15721578

1573-
g_assert(s->kdf_buf.offset == s->kdf_buf.length);
1579+
if (s->kdf_buf.offset != s->kdf_buf.length) {
1580+
/* KMAC interface reports done but we did not send the whole KDF buf */
1581+
s->regs[R_FAULT_STATUS] |= R_FAULT_STATUS_KMAC_DONE_MASK;
1582+
ot_keymgr_update_alerts(s);
1583+
ot_keymgr_schedule_fsm(s);
1584+
return;
1585+
}
1586+
1587+
/* @todo: check share1 as well when KMAC masking is supported */
1588+
bool share0_valid = ot_keymgr_valid_data_check(rsp->digest_share0,
1589+
OT_KMAC_APP_DIGEST_BYTES);
1590+
if (!share0_valid) {
1591+
/* KMAC returned all 0s or all 1s*/;
1592+
s->regs[R_FAULT_STATUS] |= R_FAULT_STATUS_KMAC_OUT_MASK;
1593+
ot_keymgr_update_alerts(s);
1594+
ot_keymgr_schedule_fsm(s);
1595+
return;
1596+
}
15741597

15751598
uint32_t ctrl = ot_shadow_reg_peek(&s->control);
15761599
bool op_complete;

0 commit comments

Comments
 (0)