Skip to content

Commit 3f3671d

Browse files
committed
[aes/sw] Reduce alerts in aes_masking_off test
This commit modifies the test to reconfigure CSRNG and EDN0 after seeding the AES PRNG with the required seed. Depending on the execution environment, other entropy consumers may also request entropy from EDN0 in the background, which can trigger additional recoverable alerts in EDN0 otherwise. Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
1 parent 771a935 commit 3f3671d

5 files changed

Lines changed: 28 additions & 8 deletions

File tree

sw/device/lib/testing/aes_testutils.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ const uint32_t kEdnSeedMaterialReseed[kEdnSeedMaterialLen] = {
9191
0x96994362, 0x7ef8f0b9, 0x5b5332dc, 0xd0df9b12, 0x96dfbaa9, 0xac0b5af7,
9292
0xec2504be, 0xb00fb68c, 0xf37e0a7f, 0x88172eec, 0x4e4b5f58, 0xfec120c0};
9393

94-
status_t aes_testutils_masking_prng_zero_output_seed(const dif_csrng_t *csrng,
95-
const dif_edn_t *edn0) {
94+
status_t aes_testutils_masking_prng_zero_output_seed(
95+
const dif_csrng_t *csrng, const dif_edn_t *edn0,
96+
bool gen_zero_output_seed) {
9697
// Shutdown EDN0 and CSRNG
9798
TRY(dif_edn_stop(edn0));
9899
TRY(dif_csrng_stop(csrng));
@@ -136,7 +137,11 @@ status_t aes_testutils_masking_prng_zero_output_seed(const dif_csrng_t *csrng,
136137
.len = 0,
137138
},
138139
},
139-
.reseed_interval = 1, // Reseed after every single generate.
140+
// When producing the seed causing AES to output an all-zero output, we
141+
// need to reseed CSRNG after every single generate. Otherwise, we reseed
142+
// less frequently. This produces a different seed and avoids repetition
143+
// alerts in EDN.
144+
.reseed_interval = gen_zero_output_seed ? 1 : 16,
140145
};
141146
memcpy(edn0_params.instantiate_cmd.seed_material.data,
142147
kEdnSeedMaterialInstantiate, sizeof(kEdnSeedMaterialInstantiate));

sw/device/lib/testing/aes_testutils.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ inline bool aes_testutils_get_status(dif_aes_t *aes, dif_aes_status_t status) {
5252
*
5353
* @param csrng A CSRNG DIF handle.
5454
* @param edn0 An EDN DIF handle.
55+
* @param gen_zero_output_seed If not set, the produced seed will not result in
56+
* an all-zero output vector of the PRNG but it will also not trigger repetition
57+
* alerts in EDN.
5558
* @return The result of the operation.
5659
*/
5760
OT_WARN_UNUSED_RESULT
5861
status_t aes_testutils_masking_prng_zero_output_seed(const dif_csrng_t *csrng,
59-
const dif_edn_t *edn0);
62+
const dif_edn_t *edn0,
63+
bool gen_zero_output_seed);
6064

6165
/**
6266
* CTR_DRBG Known-Answer-Test (KAT) using the CSRNG SW application interface.

sw/device/sca/aes_serial.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ static void aes_key_mask_and_config(const uint8_t *key, size_t key_len) {
229229
const dif_edn_t edn0 = {
230230
.base_addr = mmio_region_from_addr(TOP_EARLGREY_EDN0_BASE_ADDR)};
231231

232-
CHECK_STATUS_OK(aes_testutils_masking_prng_zero_output_seed(&csrng, &edn0));
232+
CHECK_STATUS_OK(
233+
aes_testutils_masking_prng_zero_output_seed(&csrng, &edn0, true));
233234
#endif
234235
SS_CHECK_DIF_OK(dif_aes_start(&aes, &transaction, &key_shares, NULL));
235236

@@ -818,7 +819,8 @@ bool test_main(void) {
818819
const dif_edn_t edn0 = {
819820
.base_addr = mmio_region_from_addr(TOP_EARLGREY_EDN0_BASE_ADDR)};
820821

821-
CHECK_STATUS_OK(aes_testutils_masking_prng_zero_output_seed(&csrng, &edn0));
822+
CHECK_STATUS_OK(
823+
aes_testutils_masking_prng_zero_output_seed(&csrng, &edn0, true));
822824
aes_sca_load_fixed_seed();
823825
}
824826
#endif

sw/device/tests/aes_masking_off_test.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ status_t execute_test(const dif_csrng_t *csrng, const dif_edn_t *edn0) {
6363
LOG_INFO("Testing AES with masking switched off");
6464

6565
// Initialize EDN and CSRNG to generate the required seed.
66-
CHECK_STATUS_OK(aes_testutils_masking_prng_zero_output_seed(csrng, edn0));
66+
CHECK_STATUS_OK(
67+
aes_testutils_masking_prng_zero_output_seed(csrng, edn0, true));
6768

6869
// Initialise AES.
6970
dif_aes_t aes;
@@ -110,6 +111,13 @@ status_t execute_test(const dif_csrng_t *csrng, const dif_edn_t *edn0) {
110111
CHECK_DIF_OK(dif_aes_trigger(&aes, kDifAesTriggerPrngReseed));
111112
AES_TESTUTILS_WAIT_FOR_STATUS(&aes, kDifAesStatusIdle, true, kTestTimeout);
112113

114+
// Now reconfigure the CSRNG and EDN0 to avoid triggering further recoverable
115+
// alerts in EDN0. Depending on the execution environment, other entropy
116+
// consumers than AES can request entropy which would trigger the alert, too.
117+
CHECK_STATUS_OK(
118+
aes_testutils_masking_prng_zero_output_seed(csrng, edn0, false));
119+
120+
// Check that the only recoverable alert that fired was for repeated genbits.
113121
uint32_t alerts;
114122
CHECK_DIF_OK(dif_edn_get_recoverable_alerts(&edn, &alerts));
115123
CHECK(alerts == (1 << kDifEdnRecoverableAlertRepeatedGenBits));

sw/device/tests/penetrationtests/firmware/sca/aes_sca.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ status_t handle_aes_pentest_seed_lfsr(ujson_t *uj) {
10291029
const dif_edn_t edn0 = {
10301030
.base_addr = mmio_region_from_addr(TOP_EARLGREY_EDN0_BASE_ADDR)};
10311031

1032-
status_t res = aes_testutils_masking_prng_zero_output_seed(&csrng, &edn0);
1032+
status_t res =
1033+
aes_testutils_masking_prng_zero_output_seed(&csrng, &edn0, true);
10331034
if (res.value != 0) {
10341035
return ABORTED();
10351036
}

0 commit comments

Comments
 (0)