|
14 | 14 |
|
15 | 15 | CONFIG_INFILE = None
|
16 | 16 | CONFIG_OUTFILE = None
|
| 17 | +CONFIG_REKEY = False |
17 | 18 |
|
18 |
| -opts, rems = getopt.getopt(sys.argv[1:],"f:w:",["--file=","--writefile="]) |
| 19 | +opts, rems = getopt.getopt(sys.argv[1:],"f:w:k",["--file=","--writefile=","--rekey"]) |
19 | 20 | for arg,val in opts:
|
20 | 21 | if arg in ("-w","--writefile"):
|
21 | 22 | CONFIG_OUTFILE = val
|
22 | 23 | elif arg in ("-f","--file"):
|
23 | 24 | CONFIG_INFILE = val
|
| 25 | + elif arg in ("-k","--rekey"): |
| 26 | + CONFIG_REKEY = True |
24 | 27 |
|
25 | 28 | if CONFIG_INFILE is None or CONFIG_OUTFILE is None:
|
26 | 29 | print("You must populate both -f and -w")
|
|
34 | 37 |
|
35 | 38 | DODES_END = 0x8974
|
36 | 39 |
|
37 |
| -for i in range(0,50): |
38 |
| - print("Beginning attempt") |
| 40 | +rand_key = np.array([random.randint(0,0xFF) for i in range(0,8)],dtype=np.uint8) |
| 41 | +key_str = " ".join(["%02x" % x for x in rand_key]) |
| 42 | + |
| 43 | +if CONFIG_REKEY is False: |
| 44 | + print("Key is %s" % key_str) |
| 45 | + |
| 46 | +for i in range(0,25): |
39 | 47 | emu = rainbow_arm(trace_config=TraceConfig(register=HammingWeight()))
|
40 | 48 | emu.load(CONFIG_INFILE)
|
41 | 49 | emu.setup()
|
| 50 | + if CONFIG_REKEY is True: |
| 51 | + rand_key = np.array([random.randint(0,0xFF) for i in range(0,8)],dtype=np.uint8) |
| 52 | + key_str = " ".join(["%02x" % x for x in rand_key]) |
| 53 | + print("Key is %s" % key_str) |
| 54 | + emu[KEY_ADDR] = bytes(rand_key[0:4]) |
| 55 | + emu[KEY_ADDR+4] = bytes(rand_key[4:8]) |
42 | 56 | rand_input = np.array([random.randint(0,0xFF) for i in range(0,8)],dtype=np.uint8)
|
43 | 57 | emu[DATA_ADDR] = bytes(rand_input[0:4])
|
44 | 58 | emu[DATA_ADDR + 4] = bytes(rand_input[4:8])
|
|
55 | 69 | gc.collect()
|
56 | 70 |
|
57 | 71 | cs.save(CONFIG_OUTFILE)
|
| 72 | + |
| 73 | +if CONFIG_REKEY is False: |
| 74 | + print("Reminder: key is %s" % key_str) |
0 commit comments