Skip to content

Commit 2857e11

Browse files
committed
[pentest] Add ECC256 Keygen SCA test
This commit adds the ECC256 key generation side-channel penetration test to the codebase. The host code is located in lowRISC/ot-sca#347 Signed-off-by: Pascal Nasahl <[email protected]>
1 parent aabeeee commit 2857e11

23 files changed

+688
-16
lines changed

sw/device/sca/aes_serial.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static void aes_encrypt(const uint8_t *plaintext, size_t plaintext_len) {
245245
// Using the SecAesStartTriggerDelay hardware parameter, the AES unit is
246246
// configured to start operation 40 cycles after receiving the start trigger.
247247
// This allows Ibex to go to sleep in order to not disturb the capture.
248-
sca_call_and_sleep(aes_manual_trigger, kIbexAesSleepCycles, false);
248+
sca_call_and_sleep(aes_manual_trigger, kIbexAesSleepCycles, false, false);
249249
}
250250

251251
/**

sw/device/sca/kmac_serial.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static void sha3_serial_absorb(const uint8_t *msg, size_t msg_len) {
480480
// configured to start operation 40 cycles after receiving the START and PROC
481481
// commands. This allows Ibex to go to sleep in order to not disturb the
482482
// capture.
483-
sca_call_and_sleep(kmac_msg_proc, kIbexSha3SleepCycles, false);
483+
sca_call_and_sleep(kmac_msg_proc, kIbexSha3SleepCycles, false, false);
484484
}
485485

486486
/**

sw/device/sca/lib/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ cc_library(
5555
"//sw/device/lib/arch:device",
5656
"//sw/device/lib/base:bitfield",
5757
"//sw/device/lib/base:macros",
58+
"//sw/device/lib/crypto/drivers:otbn",
5859
"//sw/device/lib/dif:clkmgr",
5960
"//sw/device/lib/dif:csrng",
6061
"//sw/device/lib/dif:edn",

sw/device/sca/lib/sca.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "sw/device/lib/arch/device.h"
99
#include "sw/device/lib/base/bitfield.h"
1010
#include "sw/device/lib/base/macros.h"
11+
#include "sw/device/lib/crypto/drivers/otbn.h"
1112
#include "sw/device/lib/dif/dif_clkmgr.h"
1213
#include "sw/device/lib/dif/dif_entropy_src.h"
1314
#include "sw/device/lib/dif/dif_gpio.h"
@@ -310,7 +311,7 @@ void sca_set_trigger_low(void) {
310311
}
311312

312313
void sca_call_and_sleep(sca_callee callee, uint32_t sleep_cycles,
313-
bool sw_trigger) {
314+
bool sw_trigger, bool otbn) {
314315
// Disable the IO_DIV4_PERI clock to reduce noise during the actual capture.
315316
// This also disables the UART(s) and GPIO modules required for
316317
// communication with the scope. Therefore, it has to be re-enabled after
@@ -335,12 +336,16 @@ void sca_call_and_sleep(sca_callee callee, uint32_t sleep_cycles,
335336

336337
callee();
337338

339+
wait_for_interrupt();
340+
341+
if (otbn) {
342+
otbn_busy_wait_for_done();
343+
}
344+
338345
if (sw_trigger) {
339346
sca_set_trigger_low();
340347
}
341348

342-
wait_for_interrupt();
343-
344349
// Re-enable IO_DIV4_PERI clock to resume communication with the scope.
345350
OT_DISCARD(dif_clkmgr_gateable_clock_set_enabled(
346351
&clkmgr, CLKMGR_CLK_ENABLES_CLK_IO_DIV4_PERI_EN_BIT, kDifToggleEnabled));

sw/device/sca/lib/sca.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,10 @@ typedef void (*sca_callee)(void);
197197
* @param callee Function to call before putting Ibex to sleep.
198198
* @param sleep_cycles Number of cycles to sleep.
199199
* @param sw_trigger Raise trigger before calling the target function.
200+
* @param otbn Wait until OTBN execution has finished.
200201
*/
201202
void sca_call_and_sleep(sca_callee callee, uint32_t sleep_cycles,
202-
bool sw_trigger);
203+
bool sw_trigger, bool otbn);
203204

204205
/**
205206
* Seeds the software LFSR usable e.g. for key masking.

sw/device/sca/otbn_vertical/ecc256_keygen_serial.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static void p256_run_keygen(uint32_t mode, const uint32_t *share0,
204204

205205
// Execute program.
206206
sca_set_trigger_high();
207-
sca_call_and_sleep(otbn_manual_trigger, kIbexOtbnSleepCycles, false);
207+
sca_call_and_sleep(otbn_manual_trigger, kIbexOtbnSleepCycles, false, false);
208208
SS_CHECK_STATUS_OK(otbn_busy_wait_for_done());
209209
sca_set_trigger_low();
210210
}

sw/device/sca/otbn_vertical/ecc256_modinv_serial.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static void p256_run_modinv(uint32_t *k0, uint32_t *k1) {
9292

9393
// Execute program.
9494
sca_set_trigger_high();
95-
sca_call_and_sleep(otbn_manual_trigger, kIbexOtbnSleepCycles, false);
95+
sca_call_and_sleep(otbn_manual_trigger, kIbexOtbnSleepCycles, false, false);
9696
otbn_busy_wait_for_done();
9797
sca_set_trigger_low();
9898
}

sw/device/sca/sha3_serial.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static void sha3_serial_absorb(const uint8_t *msg, size_t msg_len) {
405405
// configured to start operation 40 cycles after receiving the START and PROC
406406
// commands. This allows Ibex to go to sleep in order to not disturb the
407407
// capture.
408-
sca_call_and_sleep(kmac_msg_proc, kIbexSha3SleepCycles, true);
408+
sca_call_and_sleep(kmac_msg_proc, kIbexSha3SleepCycles, true, false);
409409
}
410410

411411
/**

sw/device/tests/penetrationtests/firmware/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ FIRMWARE_DEPS_FPGA = [
1919
"//sw/device/tests/penetrationtests/firmware/sca:hmac_sca",
2020
"//sw/device/tests/penetrationtests/firmware/sca:ibex_sca",
2121
"//sw/device/tests/penetrationtests/firmware/sca:kmac_sca",
22+
"//sw/device/tests/penetrationtests/firmware/sca:otbn_sca",
2223
"//sw/device/tests/penetrationtests/firmware/sca:prng_sca",
2324
"//sw/device/tests/penetrationtests/firmware/sca:sha3_sca",
2425
"//sw/device/tests/penetrationtests/firmware/sca:trigger_sca",
@@ -57,6 +58,7 @@ FIRMWARE_DEPS_SCA = [
5758
"//sw/device/tests/penetrationtests/firmware/sca:hmac_sca",
5859
"//sw/device/tests/penetrationtests/firmware/sca:ibex_sca",
5960
"//sw/device/tests/penetrationtests/firmware/sca:kmac_sca",
61+
"//sw/device/tests/penetrationtests/firmware/sca:otbn_sca",
6062
"//sw/device/tests/penetrationtests/firmware/sca:prng_sca",
6163
"//sw/device/tests/penetrationtests/firmware/sca:sha3_sca",
6264
"//sw/device/tests/penetrationtests/firmware/sca:trigger_sca",

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "sw/device/tests/penetrationtests/json/ibex_sca_commands.h"
2121
#include "sw/device/tests/penetrationtests/json/kmac_sca_commands.h"
2222
#include "sw/device/tests/penetrationtests/json/otbn_fi_commands.h"
23+
#include "sw/device/tests/penetrationtests/json/otbn_sca_commands.h"
2324
#include "sw/device/tests/penetrationtests/json/prng_sca_commands.h"
2425
#include "sw/device/tests/penetrationtests/json/sha3_sca_commands.h"
2526
#include "sw/device/tests/penetrationtests/json/trigger_sca_commands.h"
@@ -33,6 +34,7 @@
3334
#include "sca/hmac_sca.h"
3435
#include "sca/ibex_sca.h"
3536
#include "sca/kmac_sca.h"
37+
#include "sca/otbn_sca.h"
3638
#include "sca/prng_sca.h"
3739
#include "sca/sha3_sca.h"
3840
#include "sca/trigger_sca.h"
@@ -65,6 +67,9 @@ status_t process_cmd(ujson_t *uj) {
6567
case kPenetrationtestCommandKmacSca:
6668
RESP_ERR(uj, handle_kmac_sca(uj));
6769
break;
70+
case kPenetrationtestCommandOtbnSca:
71+
RESP_ERR(uj, handle_otbn_sca(uj));
72+
break;
6873
case kPenetrationtestCommandOtbnFi:
6974
RESP_ERR(uj, handle_otbn_fi(uj));
7075
break;

0 commit comments

Comments
 (0)