1+ from communication .sca_kmac_commands import OTKMAC
2+ from communication .sca_prng_commands import OTPRNG
3+ from communication .sca_trigger_commands import OTTRIGGER
4+ from communication .chip import *
5+ from communication .dut import DUT
6+ import time
7+ import random
8+
9+ def char_kmac_single (opentitantool , iterations , masking , key , text ):
10+ target = DUT ()
11+ reset_target (opentitantool )
12+ # Clear the output from the reset
13+ target .dump_all ()
14+
15+ kmacsca = OTKMAC (target , "ujson" )
16+ # Initialize our chip and catch its output
17+ device_id , owner_page , boot_log , boot_measurements , version = kmacsca .init (0 )
18+
19+ if masking :
20+ lfsr_seed = [0 , 1 , 2 , 3 ]
21+ else :
22+ lfsr_seed = [0 , 0 , 0 , 0 ]
23+ kmacsca .write_lfsr_seed (lfsr_seed )
24+
25+ kmacsca .write_key (key )
26+
27+ # Set the trigger
28+ triggersca = OTTRIGGER (target , "ujson" )
29+ triggersca .select_trigger (0 )
30+
31+ for _ in range (iterations ):
32+ kmacsca .absorb (text , len (text ))
33+ response = target .read_response ()
34+ return response
35+
36+ def char_kmac_batch_daisy_chain (opentitantool , iterations , num_segments , masking , key , text ):
37+ target = DUT ()
38+ reset_target (opentitantool )
39+ # Clear the output from the reset
40+ target .dump_all ()
41+
42+ kmacsca = OTKMAC (target , "ujson" )
43+ # Initialize our chip and catch its output
44+ device_id , owner_page , boot_log , boot_measurements , version = kmacsca .init (0 )
45+
46+ if masking :
47+ lfsr_seed = [0 , 1 , 2 , 3 ]
48+ else :
49+ lfsr_seed = [0 , 0 , 0 , 0 ]
50+ kmacsca .write_lfsr_seed (lfsr_seed )
51+
52+ # Set the trigger
53+ triggersca = OTTRIGGER (target , "ujson" )
54+ triggersca .select_trigger (0 )
55+
56+ for _ in range (iterations ):
57+ kmacsca .absorb_daisy_chain (text , key , num_segments )
58+ response = target .read_response ()
59+ return response
60+
61+ def char_kmac_batch (opentitantool , iterations , num_segments , masking , key , text ):
62+ target = DUT ()
63+ reset_target (opentitantool )
64+ # Clear the output from the reset
65+ target .dump_all ()
66+
67+ kmacsca = OTKMAC (target , "ujson" )
68+ # Initialize our chip and catch its output
69+ device_id , owner_page , boot_log , boot_measurements , version = kmacsca .init (0 )
70+
71+ if masking :
72+ lfsr_seed = [0 , 1 , 2 , 3 ]
73+ else :
74+ lfsr_seed = [0 , 0 , 0 , 0 ]
75+ kmacsca .write_lfsr_seed (lfsr_seed )
76+
77+ # Set the trigger
78+ triggersca = OTTRIGGER (target , "ujson" )
79+ triggersca .select_trigger (0 )
80+
81+ # Set the internal prng
82+ ot_prng = OTPRNG (target = target , protocol = "ujson" )
83+ ot_prng .seed_prng ([1 ,0 ,0 ,0 ])
84+
85+ kmacsca .fvsr_key_set (key , len (key ))
86+
87+ for _ in range (iterations ):
88+ kmacsca .absorb_batch (num_segments )
89+ response = target .read_response ()
90+ return response
0 commit comments