Skip to content

Commit 2d5cc77

Browse files
committed
[test] Ensure SHA3 is idle before using KMAC
In some situations software seems to work fast enough that it can try to use KMAC before SHA3 is idle after the previous use. Our testutils check for this condition but error out rather than try to recover from it. This change uses a very small timeout since it should become idle very quickly ideally. Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
1 parent a3980b0 commit 2d5cc77

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

sw/device/tests/entropy_src_fw_override_test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ static status_t entropy_config(
262262
return OK_STATUS();
263263
}
264264

265+
/**
266+
* Check whether KMAC's SHA3 state is idle.
267+
*/
268+
static bool kmac_is_idle(void) {
269+
dif_kmac_status_t status;
270+
CHECK_DIF_OK(dif_kmac_get_status(&kmac, &status));
271+
return status.sha3_state == kDifKmacSha3StateIdle;
272+
}
273+
265274
/**
266275
* Configure the entropy source in extract and insert mode and run some entropy
267276
* consumers.
@@ -328,6 +337,7 @@ status_t firmware_override_extract_insert(
328337
uint32_t output[8];
329338
LOG_INFO("Running KMAC...");
330339
for (int i = 0; i < kKmacRepeats; i++) {
340+
IBEX_SPIN_FOR(kmac_is_idle(), 20);
331341
TRY(kmac_testutils_kmac(&kmac, kDifKmacModeKmacLen128, &software_key,
332342
/*custom_string=*/NULL, /*custom_string_len=*/0,
333343
/*message=*/"hello", /*message_len=*/6,

0 commit comments

Comments
 (0)