Skip to content

Commit cf398c0

Browse files
committed
[test] Add rng fi
Add the host and test scripts for rng fi. Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
1 parent f2f40ef commit cf398c0

4 files changed

Lines changed: 403 additions & 7 deletions

File tree

communication/fi_rng_commands.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,10 @@ def rng_entropy_bias(self) -> None:
108108
time.sleep(0.05)
109109
self.target.write(json.dumps("EntropySrcBias").encode("ascii"))
110110

111-
def rng_fw_overwrite(self, init: Optional[bool] = False,
112-
disable_health_check: Optional[bool] = False) -> None:
111+
def rng_fw_overwrite(self, disable_health_check: Optional[bool] = False) -> None:
113112
""" Starts the rng_fw_overwrite test.
114113
115114
Args:
116-
init: Using disable_health_check is only possible at the very first
117-
rng_fw_overwrite test. Afterwards this option cannot be switched.
118115
disable_health_check: Turn the health check on or off.
119116
"""
120117
# RngFi command.
@@ -123,9 +120,8 @@ def rng_fw_overwrite(self, init: Optional[bool] = False,
123120
# FWOverride command.
124121
time.sleep(0.05)
125122
self.target.write(json.dumps("FWOverride").encode("ascii"))
126-
if init:
127-
data = {"disable_health_check": disable_health_check}
128-
self.target.write(json.dumps(data).encode("ascii"))
123+
data = {"disable_health_check": disable_health_check}
124+
self.target.write(json.dumps(data).encode("ascii"))
129125

130126
def start_test(self, cfg: dict) -> None:
131127
""" Start the selected test.

test/penetrationtests/fi/BUILD

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,46 @@ py_binary(
203203
}),
204204
)
205205

206+
py_binary(
207+
name = "fi_rng_test",
208+
srcs = ["test_scripts/fi_rng_test.py"],
209+
testonly = True,
210+
deps = [
211+
":fi_rng_functions",
212+
"//communication:dut",
213+
"//communication:chip",
214+
"//communication:fi_rng_commands",
215+
"//test/penetrationtests/util:utils",
216+
"@rules_python//python/runfiles",
217+
],
218+
data = [
219+
"@lowrisc_opentitan//sw/host/opentitantool",
220+
] +
221+
select({
222+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/config:env_silicon_owner_gb_rom_ext": [
223+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/firmware:pen_test_fi_silicon_owner_gb_rom_ext",
224+
],
225+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/config:env_fpga_cw310_rom_with_fake_keys": [
226+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/firmware:pen_test_fi_fpga_cw310_rom_with_fake_keys",
227+
],
228+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/config:env_fpga_cw310_sival_rom_ext": [
229+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/firmware:pen_test_fi_fpga_cw310_sival_rom_ext",
230+
],
231+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/config:env_fpga_cw310_test_rom": [
232+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/firmware:pen_test_fi_fpga_cw310_test_rom",
233+
],
234+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/config:env_silicon_owner_a2_rom_ext": [
235+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/firmware:pen_test_fi_silicon_owner_a2_rom_ext",
236+
],
237+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/config:env_silicon_owner_sival_rom_ext": [
238+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/firmware:pen_test_fi_silicon_owner_sival_rom_ext",
239+
],
240+
"//conditions:default": [
241+
"@lowrisc_opentitan//sw/device/tests/penetrationtests/firmware:pen_test_fi_silicon_owner_gb_rom_ext",
242+
],
243+
}),
244+
)
245+
206246
py_library(
207247
name = "fi_ibex_functions",
208248
srcs = ["host_scripts/fi_ibex_functions.py"],
@@ -251,4 +291,14 @@ py_library(
251291
"//communication:chip",
252292
"//communication:fi_rom_commands",
253293
],
294+
)
295+
296+
py_library(
297+
name = "fi_rng_functions",
298+
srcs = ["host_scripts/fi_rng_functions.py"],
299+
deps = [
300+
"//communication:dut",
301+
"//communication:chip",
302+
"//communication:fi_rng_commands",
303+
],
254304
)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from communication.fi_rng_commands import OTFIRng
2+
from communication.chip import *
3+
from communication.dut import DUT
4+
import time
5+
6+
def char_csrng_bias(opentitantool, iterations, trigger):
7+
target = DUT()
8+
reset_target(opentitantool)
9+
# Clear the output from the reset
10+
target.dump_all()
11+
12+
rngfi = OTFIRng(target)
13+
# Initialize our chip and catch its output
14+
device_id, sensors, alerts, owner_page, boot_log, boot_measurements, version = rngfi.init("char_csrng_bias")
15+
for _ in range(iterations):
16+
rngfi.rng_csrng_bias(trigger)
17+
response = target.read_response()
18+
return response
19+
20+
def char_edn_resp_ack(opentitantool, iterations):
21+
target = DUT()
22+
reset_target(opentitantool)
23+
# Clear the output from the reset
24+
target.dump_all()
25+
26+
rngfi = OTFIRng(target)
27+
# Initialize our chip and catch its output
28+
device_id, sensors, alerts, owner_page, boot_log, boot_measurements, version = rngfi.init("char_edn_resp_ack")
29+
for _ in range(iterations):
30+
rngfi.rng_edn_resp_ack()
31+
response = target.read_response()
32+
return response
33+
34+
def char_edn_bias(opentitantool, iterations):
35+
target = DUT()
36+
reset_target(opentitantool)
37+
# Clear the output from the reset
38+
target.dump_all()
39+
40+
rngfi = OTFIRng(target)
41+
# Initialize our chip and catch its output
42+
device_id, sensors, alerts, owner_page, boot_log, boot_measurements, version = rngfi.init("char_edn_bias")
43+
for _ in range(iterations):
44+
rngfi.rng_edn_bias()
45+
response = target.read_response()
46+
return response
47+
48+
def char_entropy_bias(opentitantool, iterations):
49+
target = DUT()
50+
reset_target(opentitantool)
51+
# Clear the output from the reset
52+
target.dump_all()
53+
54+
rngfi = OTFIRng(target)
55+
# Initialize our chip and catch its output
56+
device_id, sensors, alerts, owner_page, boot_log, boot_measurements, version = rngfi.init("char_entropy_bias")
57+
for _ in range(iterations):
58+
rngfi.rng_entropy_bias()
59+
response = target.read_response()
60+
return response
61+
62+
def char_fw_overwrite(opentitantool, iterations, disable_health_check):
63+
target = DUT()
64+
rngfi = OTFIRng(target)
65+
66+
for _ in range(iterations):
67+
reset_target(opentitantool)
68+
# Clear the output from the reset
69+
target.dump_all()
70+
71+
# Initialize our chip and catch its output
72+
device_id, sensors, alerts, owner_page, boot_log, boot_measurements, version = rngfi.init("char_fw_overwrite")
73+
rngfi.rng_fw_overwrite(disable_health_check)
74+
response = target.read_response()
75+
return response

0 commit comments

Comments
 (0)