Skip to content

Commit

Permalink
[kmac/rtl] Abort when sideload key is invalid during operation
Browse files Browse the repository at this point in the history
The KMAC HW IP block features an option to load keys from Key Manager
via a HW key sideload interface.  Prior to this commit, KMAC would:
- when used via the SW application interface: *not check at all* if the
  sideload key is valid (issue #10704, #16855);
- when used via a HW application interface: check if the sideload key is
  valid *only for a single cycle* when the application interface gets
  configured (state `StAppCfg` in `kmac_app`).

This could lead to cases where KMAC would use an invalid sideload key.

This commit fixes the problem by checking whether the sideload key is
valid in *every* FSM state in which the sideload key is used.  If the
sideload key is invalid even for a single cycle (the FSM cannot know
whether the key is being used in this exact cycle or not), `kmac_app`'s
FSM goes into the `StKeyMgrErrKeyNotValid` state.  In that state, the
FSM signals the `keymgr_pkg::ErrKeyNotValid` error code in KMAC's
`err_code` CSR.  The FSM then transitions to the `StError` state, where
it drains data from the HW application interface by keeping
`app_o.ready` high.  The digest output remains all-zero (it can only
take a non-zero value in the `StAppWait` state).  The FSM exits the
`StError` state after SW has signalled that it has processed the error
by writing the `processed` bit in the `CFG_SHADOWED` CSR *and* the
active HW app interface has sent the last data item.

This commit resolves #10704 and implements the RTL part of #16855.
Covering this in DV remains open, although the existing tests (which
don't cover this) keep their previous pass rates.

Signed-off-by: Andreas Kurth <[email protected]>
  • Loading branch information
andreaskurth committed Apr 26, 2024
1 parent b41a891 commit db8e322
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
1 change: 0 additions & 1 deletion hw/ip/kmac/rtl/kmac.sv
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,6 @@ module kmac
);

// Error
// As of now, only SHA3 error exists. More error codes will be added.

logic event_error;
assign event_error = sha3_err.valid | app_err.valid
Expand Down
35 changes: 33 additions & 2 deletions hw/ip/kmac/rtl/kmac_app.sv
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,9 @@ module kmac_app

service_rejected_error_set = 1'b 1;

end else if ((AppCfg[app_id].Mode == AppKMAC) &&
!keymgr_key_i.valid) begin
end else if ((AppCfg[app_id].Mode == AppKMAC) && !keymgr_key_i.valid) begin
// The current HW application interface does *keyed* MAC but the key to be used is not
// valid, so abort into the invalid key error state.
st_d = StKeyMgrErrKeyNotValid;

// As mux_sel is not set to SelApp, app_data_ready is still 0.
Expand All @@ -463,6 +464,12 @@ module kmac_app
end else begin
st_d = StAppMsg;
end

// The current HW application interface does *keyed* MAC but the key to be used is not
// valid, so abort into the invalid key error state.
if (AppCfg[app_id].Mode == AppKMAC && !keymgr_key_i.valid) begin
st_d = StKeyMgrErrKeyNotValid;
end
end

StAppOutLen: begin
Expand All @@ -473,11 +480,23 @@ module kmac_app
end else begin
st_d = StAppOutLen;
end

// The current HW application interface does *keyed* MAC but the key to be used is not
// valid, so abort into the invalid key error state.
if (AppCfg[app_id].Mode == AppKMAC && !keymgr_key_i.valid) begin
st_d = StKeyMgrErrKeyNotValid;
end
end

StAppProcess: begin
cmd_o = CmdProcess;
st_d = StAppWait;

// The current HW application interface does *keyed* MAC but the key to be used is not
// valid, so abort into the invalid key error state.
if (AppCfg[app_id].Mode == AppKMAC && !keymgr_key_i.valid) begin
st_d = StKeyMgrErrKeyNotValid;
end
end

StAppWait: begin
Expand All @@ -490,6 +509,12 @@ module kmac_app
end else begin
st_d = StAppWait;
end

// The current HW application interface does *keyed* MAC but the key to be used is not
// valid, so abort into the invalid key error state.
if (AppCfg[app_id].Mode == AppKMAC && !keymgr_key_i.valid) begin
st_d = StKeyMgrErrKeyNotValid;
end
end

StSw: begin
Expand All @@ -503,6 +528,12 @@ module kmac_app
end else begin
st_d = StSw;
end

// If keyed MAC is enabled (`kmac_en_o`) together with key sideloading (`keymgr_key_en_i`)
// but the sideloaded key is not valid, abort into the invalid key error state.
if (kmac_en_o && keymgr_key_en_i && !keymgr_key_i.valid) begin
st_d = StKeyMgrErrKeyNotValid;
end
end

StKeyMgrErrKeyNotValid: begin
Expand Down

0 comments on commit db8e322

Please sign in to comment.