5 #ifndef OPENTITAN_SW_DEVICE_TESTS_PENETRATIONTESTS_FIRMWARE_LIB_PENTEST_LIB_H_
6 #define OPENTITAN_SW_DEVICE_TESTS_PENETRATIONTESTS_FIRMWARE_LIB_PENTEST_LIB_H_
9 #include "sw/device/lib/ujson/ujson.h"
10 #include "sw/device/tests/penetrationtests/json/pentest_lib_commands.h"
14 #define NOP10 NOP1 NOP1 NOP1 NOP1 NOP1 NOP1 NOP1 NOP1 NOP1 NOP1
15 #define NOP30 NOP10 NOP10 NOP10
16 #define NOP100 NOP10 NOP10 NOP10 NOP10 NOP10 NOP10 NOP10 NOP10 NOP10 NOP10
18 NOP100 NOP100 NOP100 NOP100 NOP100 NOP100 NOP100 NOP100 NOP100 NOP100
26 #define PENTEST_ASM_TRIGGER_HIGH \
27 asm volatile(NOP10); \
28 asm volatile("lui a0, 0x1000;"); \
29 asm volatile("addi a0, a0, 256;"); \
30 asm volatile("lui a1, 0x40040;"); \
31 asm volatile("sw a0, 24(a1);"); \
40 #define PENTEST_ASM_TRIGGER_LOW \
41 asm volatile(NOP10); \
42 asm volatile("lui a0, 0x1000;"); \
43 asm volatile("lui a1, 0x40040;"); \
44 asm volatile("sw a0, 24(a1);"); \
61 typedef enum pentest_trigger_source {
68 kPentestTriggerSourceAes = 0,
72 kPentestTriggerSourceHmac = 1,
76 kPentestTriggerSourceKmac = 2,
80 kPentestTriggerSourceOtbn = 3,
81 } pentest_trigger_source_t;
86 typedef enum pentest_trigger_type {
94 kPentestTriggerTypeHwGated = 0,
99 kPentestTriggerTypeSw = 1,
100 } pentest_trigger_type_t;
110 typedef enum pentest_peripheral {
114 kPentestPeripheralEdn = 1 << 0,
118 kPentestPeripheralCsrng = 1 << 1,
122 kPentestPeripheralEntropy = 1 << 2,
126 kPentestPeripheralAes = 1 << 3,
130 kPentestPeripheralHmac = 1 << 4,
134 kPentestPeripheralKmac = 1 << 5,
138 kPentestPeripheralOtbn = 1 << 6,
142 kPentestPeripheralIoDiv4 = 1 << 7,
146 kPentestPeripheralIoDiv2 = 1 << 8,
150 kPentestPeripheralUsb = 1 << 9,
154 kPentestPeripheralIo = 1 << 10,
155 } pentest_peripheral_t;
166 typedef uint32_t pentest_peripherals_t;
174 typedef enum pentest_lfsr_context {
178 kPentestLfsrMasking = 0,
182 kPentestLfsrOrder = 1,
184 } pentest_lfsr_context_t;
196 status_t pentest_configure_entropy_source_max_reseed_interval(
void);
212 void pentest_clear_sensor_recov_alerts(
void);
230 void pentest_configure_alert_handler(
void);
240 status_t pentest_read_device_id(uint32_t device_id[]);
278 bool disable_icache,
bool disable_dummy_instr,
bool enable_jittery_clock,
279 bool enable_sram_readback,
bool *clock_jitter_locked,
bool *clock_jitter_en,
280 bool *sram_main_readback_locked,
bool *sram_ret_readback_locked,
281 bool *sram_main_readback_en,
bool *sram_ret_readback_en);
290 void pentest_init(pentest_trigger_source_t trigger,
291 pentest_peripherals_t enable);
298 const dif_uart_t *pentest_get_uart(
void);
305 void pentest_select_trigger_type(pentest_trigger_type_t trigger_type);
314 void pentest_set_trigger_high(
void);
319 void pentest_set_trigger_low(
void);
325 typedef void (*sca_callee)(void);
340 void pentest_call_and_sleep(sca_callee callee, uint32_t sleep_cycles,
341 bool sw_trigger,
bool otbn);
352 void pentest_seed_lfsr(uint32_t seed, pentest_lfsr_context_t context);
367 uint32_t pentest_next_lfsr(uint16_t num_steps, pentest_lfsr_context_t context);
385 uint32_t pentest_linear_layer(uint32_t input);
404 uint32_t pentest_non_linear_layer(uint32_t input);