Commit 83ac50c3421fbdc4d48e76a8521265d48d44f71f

Authored by Brice Colombier
1 parent a513362fa8
Exists in master

CONFIRM working, backtracking in progress, AW in progress

Showing 16 changed files with 415 additions and 180 deletions

AW_decoder/AW_decoder.vhd View file @ 83ac50c
  1 +LIBRARY ieee;
  2 +USE ieee.std_logic_1164.ALL;
  3 +
  4 +ENTITY AW_decoder IS
  5 +
  6 + PORT (
  7 + formatted_AW : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
  8 + AW : OUT STD_LOGIC_VECTOR(7 DOWNTO 0));
  9 +
  10 +END ENTITY AW_decoder;
  11 +
  12 +ARCHITECTURE rtl OF AW_decoder IS
  13 +
  14 +BEGIN
  15 +
  16 +
  17 +
  18 +END ARCHITECTURE rtl;
AW_decoder/gen_AW_decoder.py View file @ 83ac50c
  1 +import random as rd
  2 +
  3 +def gen_AW_decoder (AW, in_width, locking=True, masking=True):
  4 + """Generates a decoder for the Activation Word
  5 +
  6 + in_width: width of the input coming from the cipher
  7 + """
  8 +
  9 + unlocking_word = ""
  10 + unmasking_word = ""
  11 + if locking:
  12 + if masking:
  13 + try:
  14 + unlocking_word, unmasking_word = AW.split()
  15 + except ValueError:
  16 + raise ValueError("Incorrect AW provided, must be \"AW_lock|AW_mask\"")
  17 + else:
  18 + if len(AW.split()) == 1:
  19 + unlocking_word = AW
  20 + else:
  21 + raise ValueError("AW provided comes in multiple parts, should have only one")
  22 + elif masking:
  23 + if len(AW.split()) == 1:
  24 + unmasking_word = AW
  25 + else:
  26 + raise ValueError("AW provided comes in multiple parts, should have only one")
  27 + else:
  28 + raise ValueError("At least one of locking or masking must be set to True")
  29 +
  30 + with open("AW_decoder.vhd", "w") as vhd_file:
  31 + # Header
  32 + vhd_file.write("LIBRARY ieee;\n")
  33 + vhd_file.write("USE ieee.std_logic_1164.ALL;\n\n")
  34 + # Entity
  35 + vhd_file.write("ENTITY AW_decoder IS\n\n")
  36 + vhd_file.write(" PORT (\n")
  37 + vhd_file.write(" formatted_AW : IN STD_LOGIC_VECTOR("+str(in_width-1)+" DOWNTO 0);\n")
  38 + vhd_file.write(" AW : OUT STD_LOGIC_VECTOR("+str(len(AW)-1)+" DOWNTO 0));\n\n")
  39 + vhd_file.write("END ENTITY AW_decoder;\n\n")
  40 + # Architecture
  41 + vhd_file.write("ARCHITECTURE rtl OF AW_decoder IS\n\n")
  42 + vhd_file.write("BEGIN\n\n\n\n")
  43 + formatted_AW = ''.join([str(int(2*rd.random())) for i in xrange(in_width)])
  44 + formatted_AW_LSB = formatted_AW[:len(formatted_AW)/2]
  45 + formatted_AW_MSB = formatted_AW[len(formatted_AW)/2:]
  46 + pos_0s_MSB_AW = [x for x in range(len(formatted_AW_MSB)) if formatted_AW_MSB[x] == '0']
  47 + pos_1s_MSB_AW = [x for x in range(len(formatted_AW_MSB)) if formatted_AW_MSB[x] == '1']
  48 + # Locking part
  49 +
  50 +
  51 + vhd_file.write("END ARCHITECTURE rtl;\n")
  52 +
  53 + return formatted_AW_MSB, pos_0s_MSB_AW, pos_1s_MSB_AW
  54 +
  55 +if __name__ == "__main__":
  56 + print gen_AW_decoder("0001 1010", 8, locking=True, masking=True)
  57 + print gen_AW_decoder("00011010", 8, locking=False, masking=True)
  58 + print gen_AW_decoder("00011010", 8, locking=True, masking=False)
CASCADE/binary_par.py View file @ 83ac50c
... ... @@ -28,29 +28,21 @@
28 28 blocks_return = []
29 29 ref_rep = []
30 30 parities = gpfi.get_parities_from_indices(blocks_to_correct_first_half, tclsh, board_manager, response_length*4)
31   - print "Blocks to correct", blocks_to_correct
32 31 if len(blocks_to_correct[0]) > 2:
33 32 for i, j in enumerate(parities):
34   - print reference_response[i][:block_size/2], j
35 33 if par.parity(reference_response[i][:block_size/2], j):
36   - print "Error is in the first half of the block"
37 34 blocks_return.append(blocks_to_correct[i][:block_size/2])
38 35 ref_rep.append(reference_response[i][:block_size/2])
39 36 else:
40   - print "Error is in the second half of the block"
41 37 blocks_return.append(blocks_to_correct[i][block_size/2:])
42 38 ref_rep.append(reference_response[i][block_size/2:])
43   - print "Blocks return", blocks_return
44 39 return ref_rep, blocks_return
45 40 elif len(blocks_to_correct[0]) == 2:
46 41 for i, j in enumerate(parities):
47 42 if reference_response[i][0] == j:
48   - print "Error is in the first half of the block"
49 43 blocks_return.append(blocks_to_correct[i][1])
50 44 else:
51   - print "Error is in the second half of the block"
52 45 blocks_return.append(blocks_to_correct[i][0])
53   - print "Blocks return", blocks_return
54 46 return ref_rep, blocks_return
55 47  
56 48 if __name__ == "__main__":
CASCADE/cascade.py View file @ 83ac50c
... ... @@ -69,7 +69,6 @@
69 69 else:
70 70 if passe > 0:
71 71 even_parity_blocks.append(indices[block_index])
72   - # Validated until here
73 72 if blocks_to_correct:
74 73 while len(blocks_to_correct[0]) > 2:
75 74 reference_response_to_correct, blocks_to_correct = bi_par.binary_par(reference_response_to_correct, blocks_to_correct, tclsh, board_manager, len(reference_response)*4)
CASCADE/get_parities_from_indices.py View file @ 83ac50c
... ... @@ -23,10 +23,10 @@
23 23 >>> get_parities_from_indices([[1, 5], [7, 2], [3, 6], [4, 0]])
24 24 [0, 1, 1, 0]
25 25 """
26   -
27   - parities = tclsh.eval(board_manager.command_get_parities_from_indices(indices, response_length))
  26 +
  27 + command = board_manager.command_get_parities_from_indices(indices, response_length)
  28 + parities = tclsh.eval(command)
28 29 parities = [int(i) for i in list(parities.replace(" ", ""))]
29   - print "Parities", parities
30 30 return parities
31 31  
32 32  
add_frame_elements.py View file @ 83ac50c
... ... @@ -217,28 +217,38 @@
217 217 text="Modify design",
218 218 state="normal",
219 219 command=self.modify_design)
220   - self.modify_design_button.grid(row=2, column=0)
  220 + self.modify_design_button.grid(row=4, column=0)
221 221 # -------------------------------------------------------
222   - self.generated_design_format_label = Label(self.generate_modified_design_frame,
  222 + self.generate_modified_design_simple_frame = LabelFrame(self.generate_save_modified_design_frame,
  223 + text = "Simple")
  224 + self.generate_modified_design_simple_frame.pack(side="left",
  225 + expand=1,
  226 + fill="both")
  227 + self.generate_modified_design_wrapped_frame = LabelFrame(self.generate_save_modified_design_frame,
  228 + text = "Wrapped")
  229 + self.generate_modified_design_wrapped_frame.pack(side="left",
  230 + expand=1,
  231 + fill="both")
  232 + self.generated_design_format_label = Label(self.generate_modified_design_simple_frame,
223 233 text="Output format:")
224 234 self.generated_design_format_label.grid(row=0,
225 235 column=0,
226 236 sticky=E)
227   - self.generated_design_format_bench = Radiobutton(self.generate_modified_design_frame,
  237 + self.generated_design_format_bench = Radiobutton(self.generate_modified_design_simple_frame,
228 238 text="BENCH (.txt)",
229 239 variable=self.generated_design_format,
230 240 value="bench")
231 241 self.generated_design_format_bench.grid(row=0,
232 242 column=1,
233 243 sticky=W)
234   - self.generated_design_format_vhd = Radiobutton(self.generate_modified_design_frame,
  244 + self.generated_design_format_vhd = Radiobutton(self.generate_modified_design_simple_frame,
235 245 text="VHDL (.vhd)",
236 246 variable=self.generated_design_format,
237 247 value="vhd")
238 248 self.generated_design_format_vhd.grid(row=1,
239 249 column=1,
240 250 sticky=W)
241   - self.generate_modified_design_button=Button(self.generate_modified_design_frame,
  251 + self.generate_modified_design_button=Button(self.generate_modified_design_simple_frame,
242 252 text="Generate and save modified design",
243 253 state="normal",
244 254 command= self.generate_save_modified_design,
245 255  
246 256  
... ... @@ -246,24 +256,79 @@
246 256 self.generate_modified_design_button.grid(row=2,
247 257 column=0,
248 258 sticky=W)
249   - self.modified_design_saved_label = Label(self.generate_modified_design_frame,
  259 + self.modified_design_saved_label = Label(self.generate_modified_design_simple_frame,
250 260 textvariable=self.message_modified_design_saved)
251 261 self.modified_design_saved_label.grid(row=2,
252 262 column=1,
253 263 sticky=W)
254   - self.save_associated_activation_word_button=Button(self.generate_modified_design_frame,
255   - text="Save associated Activation word",
256   - state="normal",
257   - command=self.save_AW,
258   - width=32)
259   - self.save_associated_activation_word_button.grid(row=3,
260   - column=0,
261   - sticky=W)
262   - self.activation_word_saved_label = Label(self.generate_modified_design_frame,
  264 + self.save_associated_activation_word_simple_button=Button(self.generate_modified_design_simple_frame,
  265 + text="Save associated Activation word",
  266 + state="normal",
  267 + command=self.save_AW,
  268 + width=32)
  269 + self.save_associated_activation_word_simple_button.grid(row=3,
  270 + column=0,
  271 + sticky=W)
  272 + self.activation_word_saved_label = Label(self.generate_modified_design_simple_frame,
263 273 textvariable=self.message_AW_saved)
264 274 self.activation_word_saved_label.grid(row=3,
265 275 column=1,
266 276 sticky=W)
  277 + self.crypto_label = Label(self.generate_modified_design_wrapped_frame,
  278 + text="Crypto:")
  279 + self.crypto_label.grid(row=0,
  280 + column=0,
  281 + sticky = E)
  282 + self.select_crypto_OTP = Radiobutton(self.generate_modified_design_wrapped_frame,
  283 + text="One Time Pad",
  284 + variable=self.crypto,
  285 + value="OTP")
  286 + self.select_crypto_OTP.grid(row=0,
  287 + column=1,
  288 + sticky=W)
  289 + self.select_crypto_PRESENT = Radiobutton(self.generate_modified_design_wrapped_frame,
  290 + text="PRESENT",
  291 + variable=self.crypto,
  292 + value="PRESENT")
  293 + self.select_crypto_PRESENT.grid(row=1,
  294 + column=1,
  295 + sticky=W)
  296 + self.key_derivation_label = Label(self.generate_modified_design_wrapped_frame,
  297 + text="Key generation:")
  298 + self.key_derivation_label.grid(row=2,
  299 + column=0,
  300 + sticky = E)
  301 + self.select_key_derivation_none = Radiobutton(self.generate_modified_design_wrapped_frame,
  302 + text="None",
  303 + variable=self.key_derivation,
  304 + value="None")
  305 + self.select_key_derivation_none.grid(row=2,
  306 + column=1,
  307 + sticky=W)
  308 + self.select_key_derivation_blake2 = Radiobutton(self.generate_modified_design_wrapped_frame,
  309 + text="Blake2 hashing",
  310 + variable=self.key_derivation,
  311 + value="Blake2")
  312 + self.select_key_derivation_blake2.grid(row=3,
  313 + column=1,
  314 + sticky=W)
  315 + self.generate_wrapped_design_button=Button(self.generate_modified_design_wrapped_frame,
  316 + text="Generate and save wrapped design",
  317 + state="normal",
  318 + #command= self.generate_save_wrapped_design,
  319 + width=32)
  320 + self.generate_wrapped_design_button.grid(row=4,
  321 + column=0,
  322 + sticky=W)
  323 + self.save_associated_activation_word_wrapped_button=Button(self.generate_modified_design_wrapped_frame,
  324 + text="Save associated Activation word",
  325 + state="normal",
  326 + command=self.save_AW,
  327 + width=32)
  328 + self.save_associated_activation_word_wrapped_button.grid(row=5,
  329 + column=0,
  330 + sticky=W)
  331 +
267 332 # -------------------------------------------------------
268 333 self.activation_word_label = Label(self.activation_word_encryption_frame,
269 334 text="Activation word:")
... ... @@ -57,8 +57,8 @@
57 57  
58 58 self.master = master
59 59  
60   - self.master.maxsize(width=1000, height=370)
61   - self.master.minsize(width=1000, height=370)
  60 + self.master.maxsize(width=800, height=460)
  61 + self.master.minsize(width=800, height=460)
62 62 self.master.resizable(width=False, height=False)
63 63 self.master.title("SALWARE IP protection tool")
64 64 self.master.iconbitmap(default='./contents/icon.ico')
65 65  
66 66  
67 67  
... ... @@ -248,26 +248,27 @@
248 248 self.unlocking_word = ""
249 249 self.unmasking_word = ""
250 250 if self.locking.get():
251   - self.graph_modified, self.unlocking_word = locking(self.g,
252   - self.prim_in,
253   - self.prim_out,
254   - self.nodes,
255   - self.locking_overhead.get())
  251 + self.graph_modified, self.unlocking_word, self.locking_inputs = locking(self.g,
  252 + self.prim_in,
  253 + self.prim_out,
  254 + self.nodes,
  255 + self.locking_overhead.get())
256 256 if self.masking.get():
257   - self.graph_modified, self.unmasking_word = masking(self.graph_modified,
258   - self.prim_in,
259   - self.prim_out,
260   - self.nodes,
261   - self.locking_overhead.get(),
262   - self.masking_heuristic.get())
  257 + self.graph_modified, self.unmasking_word, self.masking_inputs = masking(self.graph_modified,
  258 + self.prim_in,
  259 + self.prim_out,
  260 + self.nodes,
  261 + self.locking_overhead.get(),
  262 + self.masking_heuristic.get())
263 263 elif self.masking.get():
264   - self.graph_modified, self.unmasking_word = masking(self.g,
265   - self.prim_in,
266   - self.prim_out,
267   - self.nodes,
268   - self.masking_overhead.get(),
269   - self.masking_heuristic.get())
  264 + self.graph_modified, self.unmasking_word, self.masking_inputs = masking(self.g,
  265 + self.prim_in,
  266 + self.prim_out,
  267 + self.nodes,
  268 + self.masking_overhead.get(),
  269 + self.masking_heuristic.get())
270 270 print self.unlocking_word, self.unmasking_word
  271 + print self.locking_inputs, self.masking_inputs
271 272  
272 273 def derive_key_from_response(self):
273 274 self.salt = bytes(''.join(random.SystemRandom().choice(["0", "1"]) for _ in range(32)))
274 275  
... ... @@ -311,7 +312,9 @@
311 312 self.tcl_obj.eval(self.board_manager.reset_boards(port=2))
312 313 self.tcl_obj.eval(self.board_manager.generate_response())
313 314 server_before = self.server_reference_response
  315 + print "Server:", str.upper(hex(int(str(self.server_reference_response)[1:-1].replace(", ", ""), 2))[2:-1])
314 316 on_board = response_converter_to_bin_list(self.tcl_obj.eval(self.board_manager.offload_response()))
  317 + print "DBoard:", str.upper(hex(int(str(list(reversed(on_board)))[1:-1].replace(", ", ""), 2))[2:-1])
315 318 print "Differences before/on_board: ", [a for (a, (b, c)) in enumerate(zip(server_before, list(reversed(on_board)))) if b != c]
316 319 self.server_reference_response = cascade(self.server_reference_response,
317 320 0.02,
boards_management/board_commands.py View file @ 83ac50c
... ... @@ -53,6 +53,13 @@
53 53  
54 54 def command_get_parities_from_indices(self, indices, response_length):
55 55  
  56 + def Get_MB_code():
  57 + while True:
  58 + yield "6"
  59 + yield "8"
  60 +
  61 + MB_code_getter = Get_MB_code()
  62 +
56 63 CASCADE_code = {1:"1",
57 64 2:"2",
58 65 4:"3",
... ... @@ -72,10 +79,10 @@
72 79 flat_indices = []
73 80 for i in indices:
74 81 flat_indices.extend(i)
75   - if [i for i in flat_indices if i > response_length-1]:
76   - print flat_indices
77   - print response_length
78   - raise ValueError("Some indexes are out of the response", i)
  82 + # if [i for i in flat_indices if i > response_length-1]:
  83 + # print flat_indices
  84 + # print response_length
  85 + # raise ValueError("Some indexes are out of the response", i, response_length-1)
79 86 if sorted(flat_indices) != sorted(list(set(flat_indices))):
80 87 print flat_indices
81 88 print list(set(flat_indices))
82 89  
83 90  
84 91  
85 92  
86 93  
87 94  
88 95  
... ... @@ -84,58 +91,36 @@
84 91 flat_indices = [i.zfill(2) for i in flat_indices]
85 92 flat_indices = list(reversed([str.upper(i) for i in flat_indices]))
86 93  
87   - if nb_blocks == 1:
88   - # CONFIRM mode
89   - if len(flat_indices) > response_length/4:
90   - raise ValueError("Block is too large with respect to response length")
91   - # else:
92   - # if nb_blocks*len_blocks != 128:
93   - # raise ValueError("Illegal combination of block size and number of blocks")
94   - if len(flat_indices) < 4:
95   - command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices).zfill(6)+CASCADE_code[len_blocks]+"5\"]\n"
96   - elif len(flat_indices) < 8:
97   - temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-3:])+CASCADE_code[len_blocks]+"5\"]\n"
98   - del flat_indices[-3:]
99   - command="sendFabricCommand $dev 8 [fromHEX \""+''.join(flat_indices).zfill(8)+"\"]\n"
100   - command+=temp_command
  94 + command = ""
  95 + if len(flat_indices) < 3:
  96 + command+="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices).zfill(2)+hex(nb_blocks)[2:].zfill(2)+CASCADE_code[len_blocks]+"4\"]\n"
101 97 else:
102   - command=""
103   - if nb_blocks == 1:
104   - temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-3:])+CASCADE_code[len_blocks]+"5\"]\n"
105   - else:
106   - temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-3:])+CASCADE_code[len_blocks]+"4\"]\n"
107   - del flat_indices[-3:]
108   - command+="sendFabricCommand $dev 8 [fromHEX \""+''.join(flat_indices[-4:])+"\"]\n"
  98 + temp_command="sendFabricCommand $dev "+next(MB_code_getter)+" [fromHEX \""+''.join(flat_indices[-2:]).zfill(2)+hex(nb_blocks)[2:].zfill(2)+CASCADE_code[len_blocks]+"4\"]\n"
  99 + del flat_indices[-2:]
  100 + command+="sendFabricCommand $dev "+next(MB_code_getter)+" [fromHEX \""+''.join(flat_indices[-4:]).zfill(8)+"\"]\n"
109 101 command+=temp_command
110 102 del flat_indices[-4:]
111   - while len(flat_indices) > 4:
112   - temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-4:]).zfill(8)+"\"]\n"
  103 + while len(flat_indices) > 5:
  104 + temp_command="sendFabricCommand $dev "+next(MB_code_getter)+" [fromHEX \""+''.join(flat_indices[-4:])+"\"]\n"
113 105 del flat_indices[-4:]
114   - command+="sendFabricCommand $dev 8 [fromHEX \""+''.join(flat_indices[-4:]).zfill(8)+"\"]\n"
  106 + command+="sendFabricCommand $dev "+next(MB_code_getter)+" [fromHEX \""+''.join(flat_indices[-4:]).zfill(8)+"\"]\n"
115 107 command+=temp_command
116 108 del flat_indices[-4:]
117 109 if flat_indices:
118   - command+="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices).zfill(8)+"\"]\n"
119   - command+="sendFabricCommand $dev 6 [fromHEX \"00000006\"]\n"
  110 + command+="sendFabricCommand $dev "+next(MB_code_getter)+" [fromHEX \""+''.join(flat_indices[-4:]).zfill(8)+"\"]\n"
  111 + command+="sendFabricCommand $dev 6 [fromHEX \"00000005\"]\n"
120 112 command+="set par [hex2bin [lindex [sendFabricCommand $dev 10 0] 1]]\n"
121 113 command+="return [string reverse [string range [string reverse $par] 0 "+str(nb_blocks-1)+"]]"
122   - # print command
123 114 return command
124 115  
  116 +
  117 +
125 118 def disconnect(self):
126 119 command = "disconnect $dev\n"
127 120 return command
128 121  
129 122  
130 123 if __name__ == "__main__":
131   -
132   - r = Tkinter.Tcl()
133   - Boardm = Board_manager()
134   - r.eval(Boardm.source_tcl_package())
135   - r.eval(Boardm.connect("COM3"))
136   - # r.eval(Boardm.select_DB_connection(2))
137   - # r.eval(Boardm.reset_boards())
138   - # print(r.eval(Boardm.generate_and_offload_response()))
139   - # r.eval(Boardm.get_parity_from_indices([0, 1, 2, 3]))
140   - # r.eval(Boardm.disconnect())
  124 + import doctest
  125 + doctest.testmod()
boards_management/board_commands.py.back View file @ 83ac50c
  1 +# Author: Brice Colombier
  2 +# Laboratoire Hubert Curien
  3 +# 42000 Saint-Etienne - France
  4 +# Contact: b.colombier@univ-st-etienne.fr
  5 +# Project: Demonstrator
  6 +# File: board_commands.py
  7 +# Date: 2016-10-27
  8 +
  9 +import Tkinter
  10 +import itertools as it
  11 +
  12 +class Board_manager():
  13 +
  14 + """Handle communication with the board
  15 +
  16 + Board-specific commands must be modified in this file
  17 +
  18 + """
  19 +
  20 + def source_tcl_package(self):
  21 + command = "source HECTOR_data_acq.tcl\n"
  22 + return command
  23 +
  24 + def connect(self, COM_port):
  25 + command = "set dev [openDevice "+COM_port+"]\n"
  26 + return command
  27 +
  28 + def reset_boards(self, port):
  29 + command = "softReset $dev\n\
  30 +sendFabricReset $dev\n\
  31 +selectDaughterBoard $dev "+str(port)+"\n\
  32 +sendDaughterReset $dev"
  33 + return command
  34 +
  35 + def generate_response(self):
  36 + command = "sendFabricCommand $dev 6 [fromHEX \"00000001\"]\n"
  37 + return command
  38 +
  39 + def offload_response(self):
  40 + command = "sendFabricCommand $dev 6 [fromHEX \"00000002\"]\n\
  41 +set rep_LSB \"[lindex [sendFabricCommand $dev 9 0] 1] [lindex [sendFabricCommand $dev 10 0] 1]\"\n\
  42 +sendFabricCommand $dev 6 [fromHEX \"00000003\"]\n\
  43 +set rep_MSB \"[lindex [sendFabricCommand $dev 9 0] 1] [lindex [sendFabricCommand $dev 10 0] 1]\"\n\
  44 +set rep $rep_MSB$rep_LSB\n\
  45 +regsub -all { } $rep {} rep\n\
  46 +return $rep"
  47 + return command
  48 +
  49 + def poll_board(self):
  50 + """-1 1 at the beginning if there is a problem"""
  51 + command = "getStatus $dev\n"
  52 + return command
  53 +
  54 + def command_get_parities_from_indices(self, indices, response_length):
  55 +
  56 + CASCADE_code = {1:"1",
  57 + 2:"2",
  58 + 4:"3",
  59 + 8:"4",
  60 + 16:"5",
  61 + 32:"6",
  62 + 64:"7"}
  63 +
  64 + nb_blocks = len(indices)
  65 + len_each_block = [len(i) for i in indices]
  66 + len_blocks = len_each_block[0]
  67 +
  68 + if nb_blocks*[len_blocks] != len_each_block:
  69 + raise ValueError("Blocks have different length", len_blocks, " VS ", len_each_block)
  70 + if len_blocks not in [1, 2, 4, 8, 16, 32, 64]:
  71 + raise ValueError("Illegal block size")
  72 + flat_indices = []
  73 + for i in indices:
  74 + flat_indices.extend(i)
  75 + if [i for i in flat_indices if i > response_length-1]:
  76 + print flat_indices
  77 + print response_length
  78 + raise ValueError("Some indexes are out of the response", i)
  79 + if sorted(flat_indices) != sorted(list(set(flat_indices))):
  80 + print flat_indices
  81 + print list(set(flat_indices))
  82 + raise ValueError("Some indices are repeated")
  83 + flat_indices = [str(hex(i))[2:] for i in flat_indices]
  84 + flat_indices = [i.zfill(2) for i in flat_indices]
  85 + flat_indices = list(reversed([str.upper(i) for i in flat_indices]))
  86 +
  87 + if nb_blocks == 1:
  88 + # CONFIRM mode
  89 + if len(flat_indices) > response_length/4:
  90 + raise ValueError("Block is too large with respect to response length")
  91 + # else:
  92 + # if nb_blocks*len_blocks != 128:
  93 + # raise ValueError("Illegal combination of block size and number of blocks")
  94 + if len(flat_indices) < 4:
  95 + command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices).zfill(6)+CASCADE_code[len_blocks]+"5\"]\n"
  96 + elif len(flat_indices) < 8:
  97 + temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-3:])+CASCADE_code[len_blocks]+"5\"]\n"
  98 + del flat_indices[-3:]
  99 + command="sendFabricCommand $dev 8 [fromHEX \""+''.join(flat_indices).zfill(8)+"\"]\n"
  100 + command+=temp_command
  101 + else:
  102 + command=""
  103 + if nb_blocks == 1:
  104 + temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-3:])+CASCADE_code[len_blocks]+"5\"]\n"
  105 + else:
  106 + temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-3:])+CASCADE_code[len_blocks]+"4\"]\n"
  107 + del flat_indices[-3:]
  108 + command+="sendFabricCommand $dev 8 [fromHEX \""+''.join(flat_indices[-4:])+"\"]\n"
  109 + command+=temp_command
  110 + del flat_indices[-4:]
  111 + while len(flat_indices) > 4:
  112 + temp_command="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices[-4:]).zfill(8)+"\"]\n"
  113 + del flat_indices[-4:]
  114 + command+="sendFabricCommand $dev 8 [fromHEX \""+''.join(flat_indices[-4:]).zfill(8)+"\"]\n"
  115 + command+=temp_command
  116 + del flat_indices[-4:]
  117 + if flat_indices:
  118 + command+="sendFabricCommand $dev 6 [fromHEX \""+''.join(flat_indices).zfill(8)+"\"]\n"
  119 + command+="sendFabricCommand $dev 6 [fromHEX \"00000006\"]\n"
  120 + command+="set par [hex2bin [lindex [sendFabricCommand $dev 10 0] 1]]\n"
  121 + command+="return [string reverse [string range [string reverse $par] 0 "+str(nb_blocks-1)+"]]"
  122 + # print command
  123 + return command
  124 +
  125 + def disconnect(self):
  126 + command = "disconnect $dev\n"
  127 + return command
  128 +
  129 +
  130 +if __name__ == "__main__":
  131 +
  132 + r = Tkinter.Tcl()
  133 + Boardm = Board_manager()
  134 + r.eval(Boardm.source_tcl_package())
  135 + r.eval(Boardm.connect("COM3"))
  136 + # r.eval(Boardm.select_DB_connection(2))
  137 + # r.eval(Boardm.reset_boards())
  138 + # print(r.eval(Boardm.generate_and_offload_response()))
  139 + # r.eval(Boardm.get_parity_from_indices([0, 1, 2, 3]))
  140 + # r.eval(Boardm.disconnect())
boards_management/test_scenario.py View file @ 83ac50c
... ... @@ -4,52 +4,17 @@
4 4 tclsh = Tcl()
5 5 board_manager = board_commands.Board_manager()
6 6  
7   -tclsh.eval(board_manager.source_tcl_package())
8   -tclsh.eval(board_manager.connect("COM6"))
9   -tclsh.eval(board_manager.reset_boards(port=2))
10   -tclsh.eval(board_manager.generate_response())
11   -print tclsh.eval(board_manager.offload_response())
  7 +# tclsh.eval(board_manager.source_tcl_package())
  8 +# tclsh.eval(board_manager.connect("COM6"))
  9 +# tclsh.eval(board_manager.reset_boards(port=2))
  10 +# tclsh.eval(board_manager.generate_response())
  11 +# print tclsh.eval(board_manager.offload_response())
12 12  
13   -print tclsh.eval(board_manager.command_get_parities_from_indices([[0, 1, 2, 3],
14   - [4, 5, 6, 7],
15   - [8, 9, 10, 11],
16   - [12, 13, 14, 15],
17   - [16, 17, 18, 19],
18   - [20, 21, 22, 23],
19   - [24, 25, 26, 27],
20   - [28, 29, 30, 31],
21   - [32, 33, 34, 35],
22   - [36, 37, 38, 39],
23   - [40, 41, 42, 43],
24   - [44, 45, 46, 47],
25   - [48, 49, 50, 51],
26   - [52, 53, 54, 55],
27   - [56, 57, 58, 59],
28   - [60, 61, 62, 63],
29   - [64, 65, 66, 67],
30   - [68, 69, 70, 71],
31   - [72, 73, 74, 75],
32   - [76, 77, 78, 79],
33   - [80, 81, 82, 83],
34   - [84, 85, 86, 87],
35   - [88, 89, 90, 91],
36   - [92, 93, 94, 95],
37   - [96, 97, 98, 99],
38   - [100, 101, 102, 103],
39   - [104, 105, 106, 107],
40   - [108, 109, 110, 111],
41   - [112, 113, 114, 115],
42   - [116, 117, 118, 119],
43   - [120, 121, 122, 123],
44   - [124, 125, 126, 127]], 128))
45   -print tclsh.eval(board_manager.command_get_parities_from_indices([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
46   - [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],
47   - [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47],
48   - [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63],
49   - [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
50   - [80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95],
51   - [96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111],
52   - [112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127]], 128))
53 13  
54   -tclsh.eval(board_manager.disconnect())
  14 +print board_manager.command_get_parities_from_indices([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]], 128)
  15 +print board_manager.command_get_parities_from_indices([[0, 1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14, 15]], 128)
  16 +print board_manager.command_get_parities_from_indices([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]], 128)
  17 +print board_manager.command_get_parities_from_indices([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15]], 128)
  18 +print board_manager.command_get_parities_from_indices([[0], [1], [2], [3], [4], [5], [6], [7],
  19 + [8], [9], [10], [11], [12], [13], [14], [15]], 128)
declare_initialize_variables.py View file @ 83ac50c
... ... @@ -64,4 +64,8 @@
64 64 self.server_reference_response_displayed.set("")
65 65 self.server_reference_response_file = StringVar()
66 66 self.server_reference_response_file.set("")
  67 + self.crypto = StringVar()
  68 + self.crypto.set("OTP")
  69 + self.key_derivation = StringVar()
  70 + self.key_derivation.set("None")
declare_pack_frames.py View file @ 83ac50c
... ... @@ -23,9 +23,9 @@
23 23 self.modify_design_frame = LabelFrame(self.tab_logic_modifier, text="Modify design")
24 24 self.modify_design_frame.pack(fill="x")
25 25  
26   - self.generate_modified_design_frame = LabelFrame(self.tab_logic_modifier,
  26 + self.generate_save_modified_design_frame = LabelFrame(self.tab_logic_modifier,
27 27 text="Generate modified design")
28   - self.generate_modified_design_frame.pack(fill="x")
  28 + self.generate_save_modified_design_frame.pack(fill="x")
29 29  
30 30 # Tab HECTOR board management
31 31  
locking/locking.py View file @ 83ac50c
... ... @@ -37,7 +37,7 @@
37 37 list_nodes_to_lock = [list(elem) for elem in list_nodes_to_lock]
38 38  
39 39 g, list_nodes_to_lock = label_undefined_nodes.label_undefined_nodes(g, list_nodes_to_lock)
40   - key = str(list(reversed(sum(list(zip(*list_nodes_to_lock)[1]),[]))))[1:-1].replace(", ","")
  40 + locking_key = str(list(reversed(sum(list(zip(*list_nodes_to_lock)[1]),[]))))[1:-1].replace(", ","")
41 41  
42 42 print "nodes:", len(nodes)
43 43 print "nodes to lock:", len(list_nodes_to_lock)
44 44  
45 45  
... ... @@ -48,11 +48,11 @@
48 48 print len(list_nodes_to_lock)
49 49 print float(overhead)*len(nodes)/100
50 50 list_nodes_to_lock = list_nodes_to_lock[:overhead * len(nodes)]
51   - h = modify_nodes_lock.modify_nodes_lock(h, list_nodes_to_lock)
  51 + h, locking_inputs = modify_nodes_lock.modify_nodes_lock(h, list_nodes_to_lock)
52 52  
53   - if len(key) != len(list_nodes_to_lock):
  53 + if len(locking_key) != len(list_nodes_to_lock):
54 54 raise Exception("Undefined V_locks, cannot generate the modified netlist.")
55   - return h, key
  55 + return h, locking_key, locking_inputs
56 56  
57 57 if __name__ == "__main__":
58 58 for name in ["c432"]:
locking/modify_nodes_lock.py View file @ 83ac50c
... ... @@ -7,36 +7,38 @@
7 7 # Date: 2016-10-13
8 8  
9 9  
10   -def modify_nodes_lock(self, list_nodes_to_lock):
  10 +def modify_nodes_lock(g, list_nodes_to_lock):
11 11  
12 12 """Modify the graph nodes to make them lockable"""
13 13  
14 14 lock = {0: "and",
15 15 1: "or"}
  16 + locking_inputs = []
16 17  
17 18 # Handle vertices
18 19 for i in list_nodes_to_lock:
19   - attributes = self.vs.find(i[0]).attributes()
  20 + attributes = g.vs.find(i[0]).attributes()
20 21 attributes["name"] = "K"+i[0]
  22 + locking_inputs.append("K"+i[0])
21 23 attributes["label"] = attributes["name"]
22   - self.add_vertex(name=attributes["name"])
  24 + g.add_vertex(name=attributes["name"])
23 25 for j in attributes:
24   - self.vs[len(self.vs)-1][j] = attributes[j]
25   - self.vs[len(self.vs)-1]["color"] = "orange"
26   - self.vs[len(self.vs)-1]["cat"] = "input"
  26 + g.vs[len(g.vs)-1][j] = attributes[j]
  27 + g.vs[len(g.vs)-1]["color"] = "orange"
  28 + g.vs[len(g.vs)-1]["cat"] = "input"
27 29 attributes["name"] = i[0]+"_mod"
28 30 attributes["label"] = attributes["name"]
29   - self.add_vertex(name=attributes["name"])
  31 + g.add_vertex(name=attributes["name"])
30 32 for j in attributes:
31   - self.vs[len(self.vs)-1][j] = attributes[j]
32   - self.vs[len(self.vs)-1]["color"] = "lightblue"
33   - self.vs[len(self.vs)-1]["cat"] = "mod"
  33 + g.vs[len(g.vs)-1][j] = attributes[j]
  34 + g.vs[len(g.vs)-1]["color"] = "lightblue"
  35 + g.vs[len(g.vs)-1]["cat"] = "mod"
34 36 # Handle edges
35 37 for i in list_nodes_to_lock:
36 38 # Copy outgoing edges to mod node
37   - for j in self.incident(self.vs.find(i[0]), mode="OUT"):
38   - self.add_edge(i[0]+"_mod", self.vs[self.es[j].target]["label"],
39   - label=self.es[j]["label"],
  39 + for j in g.incident(g.vs.find(i[0]), mode="OUT"):
  40 + g.add_edge(i[0]+"_mod", g.vs[g.es[j].target]["label"],
  41 + label=g.es[j]["label"],
40 42 width=5,
41 43 arrow_size=2,
42 44 label_size=30,
43 45  
44 46  
... ... @@ -45,21 +47,21 @@
45 47 edges_to_delete = []
46 48 for i in list_nodes_to_lock:
47 49 # Delete copied edges from the original node
48   - for j in self.incident(self.vs.find(i[0]), mode="OUT"):
49   - edges_to_delete.append((i[0], self.vs[self.es[j].target]["label"]))
50   - self.delete_edges(edges_to_delete)
  50 + for j in g.incident(g.vs.find(i[0]), mode="OUT"):
  51 + edges_to_delete.append((i[0], g.vs[g.es[j].target]["label"]))
  52 + g.delete_edges(edges_to_delete)
51 53 for i in list_nodes_to_lock:
52 54 if i[1] in [[0], [1]]:
53 55 # The node should be forced to 0
54 56 # An AND gate will be used
55   - self.add_edge("K"+i[0], i[0]+"_mod",
  57 + g.add_edge("K"+i[0], i[0]+"_mod",
56 58 label=lock[i[1][0]],
57 59 width=5,
58 60 arrow_size=2,
59 61 label_size=30,
60 62 color="#FF0000",
61 63 cat="lock")
62   - self.add_edge(i[0], i[0]+"_mod",
  64 + g.add_edge(i[0], i[0]+"_mod",
63 65 label=lock[i[1][0]],
64 66 width=5,
65 67 arrow_size=2,
... ... @@ -69,5 +71,5 @@
69 71 else:
70 72 raise ValueError("The node has no Vforced value !")
71 73  
72   - return self
  74 + return g, locking_inputs
masking/masking.py View file @ 83ac50c
... ... @@ -68,10 +68,10 @@
68 68 masking_key = []
69 69 for i in list_nodes_to_mask:
70 70 masking_key.append(random.randint(0, 1))
71   - h = modify_nodes_mask.modify_nodes_mask(h, list_nodes_to_mask, masking_key)
72   - masking_key_string = str(masking_key).replace(", ", "").replace("[", "").replace("]", "")
  71 + h, masking_inputs = modify_nodes_mask.modify_nodes_mask(h, list_nodes_to_mask, masking_key)
  72 + masking_key = str(masking_key).replace(", ", "").replace("[", "").replace("]", "")
73 73  
74   - return h, masking_key_string
  74 + return h, masking_key, masking_inputs
75 75  
76 76 if __name__ == "__main__":
77 77 for name in ["c3540"]:
masking/modify_nodes_mask.py View file @ 83ac50c
... ... @@ -14,35 +14,37 @@
14 14 Last update: 2015-04-09
15 15 """
16 16  
17   -def modify_nodes_mask(self, list_nodes_to_mask, masking_key):
  17 +def modify_nodes_mask(g, list_nodes_to_mask, masking_key):
18 18  
19 19 if len(list_nodes_to_mask) != len(masking_key):
20 20 raise ValueError("The key length does not match the number of nodes to mask !")
21 21  
22 22 mask = {0:"xor", 1:"xnor"}
  23 + masking_inputs = []
23 24 #Handle vertices
24 25 for i in list_nodes_to_mask:
25   - attributes = self.vs.find(i).attributes()
  26 + attributes = g.vs.find(i).attributes()
26 27 attributes["name"] = "K"+i
  28 + masking_inputs.append("K"+i)
27 29 attributes["label"] = attributes["name"]
28   - self.add_vertex(name = attributes["name"])
  30 + g.add_vertex(name = attributes["name"])
29 31 for j in attributes:
30   - self.vs[len(self.vs)-1][j] = attributes[j]
31   - self.vs[len(self.vs)-1]["color"] = "orange"
32   - self.vs[len(self.vs)-1]["cat"] = "input"
  32 + g.vs[len(g.vs)-1][j] = attributes[j]
  33 + g.vs[len(g.vs)-1]["color"] = "orange"
  34 + g.vs[len(g.vs)-1]["cat"] = "input"
33 35 attributes["name"] = i+"_mod"
34 36 attributes["label"] = attributes["name"]
35   - self.add_vertex(name = attributes["name"])
  37 + g.add_vertex(name = attributes["name"])
36 38 for j in attributes:
37   - self.vs[len(self.vs)-1][j] = attributes[j]
38   - self.vs[len(self.vs)-1]["color"] = "lightblue"
39   - self.vs[len(self.vs)-1]["cat"] = "mod"
  39 + g.vs[len(g.vs)-1][j] = attributes[j]
  40 + g.vs[len(g.vs)-1]["color"] = "lightblue"
  41 + g.vs[len(g.vs)-1]["cat"] = "mod"
40 42 #Handle edges
41 43 for i in list_nodes_to_mask:
42 44 #Copy outgoing edges to mod node
43   - for j in self.incident(self.vs.find(i), mode = "OUT"):
44   - self.add_edge(i+"_mod", self.vs[self.es[j].target]["label"],
45   - label = self.es[j]["label"],
  45 + for j in g.incident(g.vs.find(i), mode = "OUT"):
  46 + g.add_edge(i+"_mod", g.vs[g.es[j].target]["label"],
  47 + label = g.es[j]["label"],
46 48 width = 5,
47 49 arrow_size = 2,
48 50 label_size = 30,
49 51  
50 52  
... ... @@ -51,21 +53,21 @@
51 53 edges_to_delete = []
52 54 for i in list_nodes_to_mask:
53 55 #Delete copied edges from the original node
54   - for j in self.incident(self.vs.find(i), mode = "OUT"):
55   - edges_to_delete.append((i, self.vs[self.es[j].target]["label"]))
56   - self.delete_edges(edges_to_delete)
  56 + for j in g.incident(g.vs.find(i), mode = "OUT"):
  57 + edges_to_delete.append((i, g.vs[g.es[j].target]["label"]))
  58 + g.delete_edges(edges_to_delete)
57 59 for i in zip(list_nodes_to_mask, masking_key):
58 60 if i[1] in [0, 1]:
59 61 #The node should be forced to 0
60 62 #An AND gate will be used
61   - self.add_edge("K"+i[0], i[0]+"_mod",
  63 + g.add_edge("K"+i[0], i[0]+"_mod",
62 64 label = mask[i[1]],
63 65 width = 5,
64 66 arrow_size = 2,
65 67 label_size = 30,
66 68 color = "#FF0000",
67 69 cat = "mask")
68   - self.add_edge(i[0], i[0]+"_mod",
  70 + g.add_edge(i[0], i[0]+"_mod",
69 71 label = mask[i[1]],
70 72 width = 5,
71 73 arrow_size = 2,
... ... @@ -73,5 +75,5 @@
73 75 color = "#FF0000",
74 76 cat = "mask")
75 77  
76   - return self
  78 + return g, masking_inputs