10
10
from typing import Optional
11
11
12
12
13
- class OTFICrypto :
14
- def __init__ (self , target ) -> None :
15
- self .target = target
13
+ from target .communication .otfi import OTFI
16
14
17
- def _ujson_crypto_cmd (self ) -> None :
18
- time .sleep (0.01 )
19
- self .target .write (json .dumps ("CryptoFi" ).encode ("ascii" ))
20
- time .sleep (0.01 )
21
15
22
- def init (self ) -> None :
23
- """ Initialize the Crypto FI code on the chip.
24
- Returns:
25
- The device ID of the device.
26
- """
27
- # CryptoFi command.
28
- self ._ujson_crypto_cmd ()
29
- # Init command.
30
- time .sleep (0.01 )
31
- self .target .write (json .dumps ("Init" ).encode ("ascii" ))
32
- # Read back device ID from device.
33
- return self .read_response (max_tries = 30 )
16
+ class OTFICrypto (OTFI ):
17
+ def __init__ (self , target ) -> None :
18
+ super ().__init__ (target , "Crypto" )
34
19
35
20
def crypto_shadow_reg_access (self ) -> None :
36
21
""" Starts the crypto.fi.shadow_reg_access test.
37
22
"""
38
23
# CryptoFi command.
39
- self ._ujson_crypto_cmd ()
24
+ self ._ujson_fi_cmd ()
40
25
# ShadowRegAccess command.
41
26
time .sleep (0.01 )
42
27
self .target .write (json .dumps ("ShadowRegAccess" ).encode ("ascii" ))
@@ -45,7 +30,7 @@ def crypto_aes_key(self) -> None:
45
30
""" Starts the crypto.fi.aes_key test.
46
31
"""
47
32
# CryptoFi command.
48
- self ._ujson_crypto_cmd ()
33
+ self ._ujson_fi_cmd ()
49
34
# Aes command.
50
35
time .sleep (0.01 )
51
36
self .target .write (json .dumps ("Aes" ).encode ("ascii" ))
@@ -59,7 +44,7 @@ def crypto_aes_plaintext(self) -> None:
59
44
""" Starts the crypto.fi.aes_plaintext test.
60
45
"""
61
46
# CryptoFi command.
62
- self ._ujson_crypto_cmd ()
47
+ self ._ujson_fi_cmd ()
63
48
# Aes command.
64
49
time .sleep (0.01 )
65
50
self .target .write (json .dumps ("Aes" ).encode ("ascii" ))
@@ -73,7 +58,7 @@ def crypto_aes_encrypt(self) -> None:
73
58
""" Starts the crypto.fi.aes_encrypt test.
74
59
"""
75
60
# CryptoFi command.
76
- self ._ujson_crypto_cmd ()
61
+ self ._ujson_fi_cmd ()
77
62
# Aes command.
78
63
time .sleep (0.01 )
79
64
self .target .write (json .dumps ("Aes" ).encode ("ascii" ))
@@ -87,7 +72,7 @@ def crypto_aes_ciphertext(self) -> None:
87
72
""" Starts the crypto.fi.aes_ciphertext test.
88
73
"""
89
74
# CryptoFi command.
90
- self ._ujson_crypto_cmd ()
75
+ self ._ujson_fi_cmd ()
91
76
# Aes command.
92
77
time .sleep (0.01 )
93
78
self .target .write (json .dumps ("Aes" ).encode ("ascii" ))
@@ -101,7 +86,7 @@ def crypto_kmac_key(self) -> None:
101
86
""" Starts the crypto.fi.kmac_key test.
102
87
"""
103
88
# CryptoFi command.
104
- self ._ujson_crypto_cmd ()
89
+ self ._ujson_fi_cmd ()
105
90
# Kmac command.
106
91
time .sleep (0.01 )
107
92
self .target .write (json .dumps ("Kmac" ).encode ("ascii" ))
@@ -115,7 +100,7 @@ def crypto_kmac_absorb(self) -> None:
115
100
""" Starts the crypto.fi.kmac_absorb test.
116
101
"""
117
102
# CryptoFi command.
118
- self ._ujson_crypto_cmd ()
103
+ self ._ujson_fi_cmd ()
119
104
# Kmac command.
120
105
time .sleep (0.01 )
121
106
self .target .write (json .dumps ("Kmac" ).encode ("ascii" ))
@@ -129,7 +114,7 @@ def crypto_kmac_squeeze(self) -> None:
129
114
""" Starts the crypto.fi.kmac_squeeze test.
130
115
"""
131
116
# CryptoFi command.
132
- self ._ujson_crypto_cmd ()
117
+ self ._ujson_fi_cmd ()
133
118
# Kmac command.
134
119
time .sleep (0.01 )
135
120
self .target .write (json .dumps ("Kmac" ).encode ("ascii" ))
@@ -143,7 +128,7 @@ def crypto_kmac_static(self) -> None:
143
128
""" Starts the crypto.fi.kmac_static test.
144
129
"""
145
130
# CryptoFi command.
146
- self ._ujson_crypto_cmd ()
131
+ self ._ujson_fi_cmd ()
147
132
# Kmac command.
148
133
time .sleep (0.01 )
149
134
self .target .write (json .dumps ("Kmac" ).encode ("ascii" ))
@@ -152,31 +137,3 @@ def crypto_kmac_static(self) -> None:
152
137
mode = {"key_trigger" : False , "absorb_trigger" : False ,
153
138
"static_trigger" : True , "squeeze_trigger" : False }
154
139
self .target .write (json .dumps (mode ).encode ("ascii" ))
155
-
156
- def start_test (self , cfg : dict ) -> None :
157
- """ Start the selected test.
158
-
159
- Call the function selected in the config file. Uses the getattr()
160
- construct to call the function.
161
-
162
- Args:
163
- cfg: Config dict containing the selected test.
164
- """
165
- test_function = getattr (self , cfg ["test" ]["which_test" ])
166
- test_function ()
167
-
168
- def read_response (self , max_tries : Optional [int ] = 1 ) -> str :
169
- """ Read response from Crypto FI framework.
170
- Args:
171
- max_tries: Maximum number of attempts to read from UART.
172
-
173
- Returns:
174
- The JSON response of OpenTitan.
175
- """
176
- it = 0
177
- while it != max_tries :
178
- read_line = str (self .target .readline ())
179
- if "RESP_OK" in read_line :
180
- return read_line .split ("RESP_OK:" )[1 ].split (" CRC:" )[0 ]
181
- it += 1
182
- return ""
0 commit comments