1*** Variables ***
2${UART}                       sysbus.uart0
3${URI}                        @https://dl.antmicro.com/projects/renode
4
5*** Keywords ***
6Create Machine
7    [Arguments]  ${elf}
8
9    Execute Command           mach create
10    Execute Command           machine LoadPlatformDescription @platforms/cpus/cc2538.repl
11    Execute Command           machine PyDevFromFile @scripts/pydev/flipflop.py 0x400D2004 0x4 True
12    Execute Command           machine PyDevFromFile @scripts/pydev/flipflop.py 0x400D7000 0x4 True
13
14    Execute Command           sysbus LoadBinary @https://dl.antmicro.com/projects/renode/cc2538_rom_dump.bin-s_524288-0c196cdc21b5397f82e0ff42b206d1cc4b6d7522 0x0
15    Execute Command           sysbus LoadELF ${elf}
16    Execute Command           sysbus.cpu VectorTableOffset 0x200000
17
18*** Test Cases ***
19Should Handle CBC Mode
20    Create Machine            ${URI}/cbc-test.elf-s_175305-302d5f0f3348815c3f02b6ba200f0dc36a8ec7c4
21
22    Create Terminal Tester    ${UART}
23    Start Emulation
24
25    Wait For Line On Uart     Test vector #0: encrypt
26    Wait For Line On Uart     cbc_crypt_start(): success
27    Wait For Line On Uart     Output message OK
28
29    Wait For Line On Uart     Test vector #1: encrypt
30    Wait For Line On Uart     cbc_crypt_start(): success
31    Wait For Line On Uart     Output message OK
32
33    Wait For Line On Uart     Test vector #2: encrypt
34    Wait For Line On Uart     cbc_crypt_start(): success
35    Wait For Line On Uart     Output message OK
36
37    Wait For Line On Uart     Test vector #3: encrypt
38    Wait For Line On Uart     cbc_crypt_start(): success
39    Wait For Line On Uart     Output message OK
40
41    Wait For Line On Uart     Test vector #4: decrypt
42    Wait For Line On Uart     cbc_crypt_start(): success
43    Wait For Line On Uart     Output message OK
44
45    Wait For Line On Uart     Test vector #5: decrypt
46    Wait For Line On Uart     cbc_crypt_start(): success
47    Wait For Line On Uart     Output message OK
48
49    Wait For Line On Uart     Test vector #6: decrypt
50    Wait For Line On Uart     cbc_crypt_start(): success
51    Wait For Line On Uart     Output message OK
52
53    Wait For Line On Uart     Test vector #7: decrypt
54    Wait For Line On Uart     cbc_crypt_start(): success
55    Wait For Line On Uart     Output message OK
56
57    Wait For Line On Uart     Test vector #8: encrypt
58    Wait For Line On Uart     cbc_crypt_start(): success
59    Wait For Line On Uart     Output message OK
60
61    Wait For Line On Uart     Test vector #9: encrypt
62    Wait For Line On Uart     cbc_crypt_start(): success
63    Wait For Line On Uart     Output message OK
64
65    Wait For Line On Uart     Test vector #10: decrypt
66    Wait For Line On Uart     cbc_crypt_start(): success
67    Wait For Line On Uart     Output message OK
68
69    Wait For Line On Uart     Test vector #11: decrypt
70    Wait For Line On Uart     cbc_crypt_start(): success
71    Wait For Line On Uart     Output message OK
72
73    Wait For Line On Uart     Test vector #12: encrypt
74    Wait For Line On Uart     cbc_crypt_start(): success
75    Wait For Line On Uart     Output message OK
76
77    Wait For Line On Uart     Test vector #13: encrypt
78    Wait For Line On Uart     cbc_crypt_start(): success
79    Wait For Line On Uart     Output message OK
80
81    Wait For Line On Uart     Test vector #14: decrypt
82    Wait For Line On Uart     cbc_crypt_start(): success
83    Wait For Line On Uart     Output message OK
84
85    Wait For Line On Uart     Test vector #15: decrypt
86    Wait For Line On Uart     cbc_crypt_start(): success
87    Wait For Line On Uart     Output message OK
88
89Should Handle CBC MAC Mode
90    Create Machine            ${URI}/cbc-mac-test.elf-s_175341-81f921163a7405a02853560527b9d09388feaacf
91
92    Create Terminal Tester    ${UART}
93    Start Emulation
94
95    Wait For Line On Uart     Test vector #0:
96    Wait For Line On Uart     cbc_mac_auth_start(): success
97    Wait For Line On Uart     cbc_mac_auth_get_result(): success
98    Wait For Line On Uart     MAC OK
99
100    Wait For Line On Uart     Test vector #1:
101    Wait For Line On Uart     cbc_mac_auth_start(): success
102    Wait For Line On Uart     cbc_mac_auth_get_result(): success
103    Wait For Line On Uart     MAC OK
104
105    Wait For Line On Uart     Test vector #2:
106    Wait For Line On Uart     cbc_mac_auth_start(): success
107    Wait For Line On Uart     cbc_mac_auth_get_result(): success
108    Wait For Line On Uart     MAC OK
109
110    Wait For Line On Uart     Test vector #3:
111    Wait For Line On Uart     cbc_mac_auth_start(): success
112    Wait For Line On Uart     cbc_mac_auth_get_result(): success
113    Wait For Line On Uart     MAC OK
114
115    Wait For Line On Uart     Test vector #4:
116    Wait For Line On Uart     cbc_mac_auth_start(): success
117    Wait For Line On Uart     cbc_mac_auth_get_result(): success
118    Wait For Line On Uart     MAC OK
119
120    Wait For Line On Uart     Test vector #5:
121    Wait For Line On Uart     cbc_mac_auth_start(): success
122    Wait For Line On Uart     cbc_mac_auth_get_result(): success
123    Wait For Line On Uart     MAC OK
124
125    Wait For Line On Uart     Test vector #6:
126    Wait For Line On Uart     cbc_mac_auth_start(): success
127    Wait For Line On Uart     cbc_mac_auth_get_result(): success
128    Wait For Line On Uart     MAC OK
129
130    Wait For Line On Uart     Test vector #7:
131    Wait For Line On Uart     cbc_mac_auth_start(): success
132    Wait For Line On Uart     cbc_mac_auth_get_result(): success
133    Wait For Line On Uart     MAC OK
134
135    Wait For Line On Uart     Test vector #8:
136    Wait For Line On Uart     cbc_mac_auth_start(): success
137    Wait For Line On Uart     cbc_mac_auth_get_result(): success
138    Wait For Line On Uart     MAC OK
139
140    Wait For Line On Uart     Test vector #9:
141    Wait For Line On Uart     cbc_mac_auth_start(): success
142    Wait For Line On Uart     cbc_mac_auth_get_result(): success
143    Wait For Line On Uart     MAC OK
144
145    Wait For Line On Uart     Test vector #10:
146    Wait For Line On Uart     cbc_mac_auth_start(): success
147    Wait For Line On Uart     cbc_mac_auth_get_result(): success
148    Wait For Line On Uart     MAC OK
149
150    Wait For Line On Uart     Test vector #11:
151    Wait For Line On Uart     cbc_mac_auth_start(): success
152    Wait For Line On Uart     cbc_mac_auth_get_result(): success
153    Wait For Line On Uart     MAC OK
154
155    Wait For Line On Uart     Test vector #12:
156    Wait For Line On Uart     cbc_mac_auth_start(): success
157    Wait For Line On Uart     cbc_mac_auth_get_result(): success
158    Wait For Line On Uart     MAC OK
159
160    Wait For Line On Uart     Test vector #13:
161    Wait For Line On Uart     cbc_mac_auth_start(): success
162    Wait For Line On Uart     cbc_mac_auth_get_result(): success
163    Wait For Line On Uart     MAC OK
164
165    Wait For Line On Uart     Test vector #14:
166    Wait For Line On Uart     cbc_mac_auth_start(): success
167    Wait For Line On Uart     cbc_mac_auth_get_result(): success
168    Wait For Line On Uart     MAC OK
169
170    Wait For Line On Uart     Test vector #15:
171    Wait For Line On Uart     cbc_mac_auth_start(): success
172    Wait For Line On Uart     cbc_mac_auth_get_result(): success
173    Wait For Line On Uart     MAC OK
174
175Should Handle CTR Mode
176    Create Machine            ${URI}/ctr-test.elf-s_175305-f32f4ec1a1d9fd1675cfe60f9c3502ceffd92aba
177
178    Create Terminal Tester    ${UART}
179    Start Emulation
180
181    Wait For Line On Uart     Test vector #0: encrypt
182    Wait For Line On Uart     ctr_crypt_start(): success
183    Wait For Line On Uart     Output message OK
184
185    Wait For Line On Uart     Test vector #1: decrypt
186    Wait For Line On Uart     ctr_crypt_start(): success
187    Wait For Line On Uart     Output message OK
188
189    Wait For Line On Uart     Test vector #2: encrypt
190    Wait For Line On Uart     ctr_crypt_start(): success
191    Wait For Line On Uart     Output message OK
192
193    Wait For Line On Uart     Test vector #3: decrypt
194    Wait For Line On Uart     ctr_crypt_start(): success
195    Wait For Line On Uart     Output message OK
196
197    Wait For Line On Uart     Test vector #4: encrypt
198    Wait For Line On Uart     ctr_crypt_start(): success
199    Wait For Line On Uart     Output message OK
200
201    Wait For Line On Uart     Test vector #5: decrypt
202    Wait For Line On Uart     ctr_crypt_start(): success
203    Wait For Line On Uart     Output message OK
204
205Should Handle CCM Mode
206    Create Machine            ${URI}/ccm-test.elf-s_175602-29d010d3aa0aa587e32cfded335a62da85563ab2
207
208    Create Terminal Tester    ${UART}
209    Start Emulation
210
211    Wait For Line On Uart     Test vector #0: encrypt
212    Wait For Line On Uart     ccm_auth_encrypt_start(): success
213    Wait For Line On Uart     ccm_auth_encrypt_get_result(): success
214    Wait For Line On Uart     Encrypted message OK
215    Wait For Line On Uart     MIC OK
216
217    Wait For Line On Uart     Test vector #1: encrypt
218    Wait For Line On Uart     ccm_auth_encrypt_start(): success
219    Wait For Line On Uart     ccm_auth_encrypt_get_result(): success
220    Wait For Line On Uart     Encrypted message OK
221    Wait For Line On Uart     MIC OK
222
223    Wait For Line On Uart     Test vector #2: encrypt
224    Wait For Line On Uart     ccm_auth_encrypt_start(): success
225    Wait For Line On Uart     ccm_auth_encrypt_get_result(): success
226    Wait For Line On Uart     Encrypted message OK
227    Wait For Line On Uart     MIC OK
228
229    Wait For Line On Uart     Test vector #3: decrypt
230    Wait For Line On Uart     ccm_auth_decrypt_start(): success
231    Wait For Line On Uart     ccm_auth_decrypt_get_result(): success
232    Wait For Line On Uart     Decrypted message OK
233
234    Wait For Line On Uart     Test vector #4: decrypt
235    Wait For Line On Uart     ccm_auth_decrypt_start(): success
236    Wait For Line On Uart     ccm_auth_decrypt_get_result(): success
237    Wait For Line On Uart     Decrypted message OK
238
239    Wait For Line On Uart     Test vector #5: decrypt
240    Wait For Line On Uart     ccm_auth_decrypt_start(): success
241    Wait For Line On Uart     ccm_auth_decrypt_get_result(): success
242    Wait For Line On Uart     Decrypted message OK
243
244    Wait For Line On Uart     Test vector #6: encrypt
245    Wait For Line On Uart     ccm_auth_encrypt_start(): success
246    Wait For Line On Uart     ccm_auth_encrypt_get_result(): success
247    Wait For Line On Uart     Encrypted message OK
248    Wait For Line On Uart     MIC OK
249
250    Wait For Line On Uart     Test vector #7: encrypt
251    Wait For Line On Uart     ccm_auth_encrypt_start(): success
252    Wait For Line On Uart     ccm_auth_encrypt_get_result(): success
253    Wait For Line On Uart     Encrypted message OK
254    Wait For Line On Uart     MIC OK
255
256    Wait For Line On Uart     Test vector #8: encrypt
257    Wait For Line On Uart     ccm_auth_encrypt_start(): success
258    Wait For Line On Uart     ccm_auth_encrypt_get_result(): success
259    Wait For Line On Uart     Encrypted message OK
260    Wait For Line On Uart     MIC OK
261
262    Wait For Line On Uart     Test vector #9: encrypt
263    Wait For Line On Uart     ccm_auth_encrypt_start(): success
264    Wait For Line On Uart     ccm_auth_encrypt_get_result(): success
265    Wait For Line On Uart     Encrypted message OK
266    Wait For Line On Uart     MIC OK
267
268    Wait For Line On Uart     Test vector #10: decrypt
269    Wait For Line On Uart     ccm_auth_decrypt_start(): success
270    Wait For Line On Uart     ccm_auth_decrypt_get_result(): success
271    Wait For Line On Uart     Decrypted message OK
272
273    Wait For Line On Uart     Test vector #11: decrypt
274    Wait For Line On Uart     ccm_auth_decrypt_start(): success
275    Wait For Line On Uart     ccm_auth_decrypt_get_result(): success
276    Wait For Line On Uart     Decrypted message OK
277
278    Wait For Line On Uart     Test vector #12: decrypt
279    Wait For Line On Uart     ccm_auth_decrypt_start(): success
280    Wait For Line On Uart     ccm_auth_decrypt_get_result(): success
281    Wait For Line On Uart     Decrypted message OK
282
283    Wait For Line On Uart     Test vector #13: decrypt
284    Wait For Line On Uart     ccm_auth_decrypt_start(): success
285    Wait For Line On Uart     ccm_auth_decrypt_get_result(): success
286    Wait For Line On Uart     Decrypted message OK
287
288    Wait For Line On Uart     Test vector #14: encrypt
289    Wait For Line On Uart     ccm_auth_encrypt_start(): success
290    Wait For Line On Uart     ccm_auth_encrypt_get_result(): success
291    Wait For Line On Uart     Encrypted message OK
292    Wait For Line On Uart     MIC OK
293
294    Wait For Line On Uart     Test vector #15: encrypt
295    Wait For Line On Uart     ccm_auth_encrypt_start(): success
296    Wait For Line On Uart     ccm_auth_encrypt_get_result(): success
297    Wait For Line On Uart     Encrypted message OK
298    Wait For Line On Uart     MIC OK
299
300    Wait For Line On Uart     Test vector #16: encrypt
301    Wait For Line On Uart     ccm_auth_encrypt_start(): success
302    Wait For Line On Uart     ccm_auth_encrypt_get_result(): success
303    Wait For Line On Uart     Encrypted message OK
304    Wait For Line On Uart     MIC OK
305
306    Wait For Line On Uart     Test vector #17: encrypt
307    Wait For Line On Uart     ccm_auth_encrypt_start(): success
308    Wait For Line On Uart     ccm_auth_encrypt_get_result(): success
309    Wait For Line On Uart     Encrypted message OK
310    Wait For Line On Uart     MIC OK
311
312    Wait For Line On Uart     Test vector #18: decrypt
313    Wait For Line On Uart     ccm_auth_decrypt_start(): success
314    Wait For Line On Uart     ccm_auth_decrypt_get_result(): success
315    Wait For Line On Uart     Decrypted message OK
316
317    Wait For Line On Uart     Test vector #19: decrypt
318    Wait For Line On Uart     ccm_auth_decrypt_start(): success
319    Wait For Line On Uart     ccm_auth_decrypt_get_result(): success
320    Wait For Line On Uart     Decrypted message OK
321
322    Wait For Line On Uart     Test vector #20: decrypt
323    Wait For Line On Uart     ccm_auth_decrypt_start(): success
324    Wait For Line On Uart     ccm_auth_decrypt_get_result(): success
325    Wait For Line On Uart     Decrypted message OK
326
327    Wait For Line On Uart     Test vector #21: decrypt
328    Wait For Line On Uart     ccm_auth_decrypt_start(): success
329    Wait For Line On Uart     ccm_auth_decrypt_get_result(): success
330    Wait For Line On Uart     Decrypted message OK
331
332