Commit 8413085ad918d52572814b3423d81318b7dff810

Authored by Brice Colombier
1 parent 9aae160ad1
Exists in master

Improve GUI

Showing 5 changed files with 38 additions and 20 deletions

CASCADE/cascade.py View file @ 8413085
... ... @@ -14,8 +14,9 @@
14 14 import random as rd
15 15 import swap_blocks as sb
16 16 import get_parities_from_indices as gpfi
  17 +import math as math
17 18  
18   -def cascade(reference_response, error_rate, nb_passes, tclsh, board_manager, initial_block_size=0):
  19 +def cascade(reference_response, error_rate, nb_passes, tclsh, board_manager, initial_block_size=0, leakage_threshold = 64):
19 20  
20 21 """Implementation of the CASCADE reconciliation protocol"""
21 22  
... ... @@ -38,6 +39,7 @@
38 39 even_parity_blocks = []
39 40 odd_parity_blocks = []
40 41 indices_to_flip = []
  42 + leakage = 0
41 43  
42 44 indices = list(range(len(reference_response)))
43 45  
... ... @@ -56,6 +58,10 @@
56 58 split.split(reference_response, block_size)
57 59 split.split(indices, block_size)
58 60 parities = gpfi.get_parities_from_indices(indices, tclsh, board_manager, len(reference_response)*4)
  61 + leakage+=len(indices)
  62 + print "Leakage:",leakage
  63 + if leakage > leakage_threshold:
  64 + return False, False
59 65 blocks_to_correct = []
60 66 reference_response_to_correct = []
61 67 for block_index, (reference_response_block, block_parity) in enumerate(zip(reference_response, parities)):
... ... @@ -71,6 +77,10 @@
71 77 even_parity_blocks.append(indices[block_index])
72 78 print "Blocks to correct", blocks_to_correct
73 79 if blocks_to_correct:
  80 + leakage+=sum([int(math.log(len(block), 2)) for block in blocks_to_correct])
  81 + print "Leakage:",leakage
  82 + if leakage > leakage_threshold:
  83 + return False, False
74 84 while len(blocks_to_correct[0]) > 2:
75 85 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)
76 86 # Final BINARY execution where single PUF bits are queried from the board
... ... @@ -94,6 +104,10 @@
94 104 while odd_parity_blocks:
95 105 backtracked_pos = 0
96 106 block_to_correct = min(odd_parity_blocks, key=len) # Get the smallest block
  107 + leakage+=int(math.log(len(block_to_correct), 2))
  108 + print "Leakage:",leakage
  109 + if leakage > leakage_threshold:
  110 + return False, False
97 111 reference_response_block = [reference_response[indices.index(x)] for x in block_to_correct]
98 112 while len(block_to_correct) > 2:
99 113 [reference_response_block], [block_to_correct] = bi_par.binary_par([reference_response_block], [block_to_correct], tclsh, board_manager, len(reference_response)*4)
... ... @@ -107,7 +121,7 @@
107 121 raise ValueError("Blocks are simultaneously in the even and odd group")
108 122 # Un-shuffle
109 123 _, reference_response = zip(*sorted(zip(indices, reference_response)))
110   - return list(reference_response)
  124 + return list(reference_response), leakage
111 125  
112 126 if __name__ == "__main__":
113 127 MSIZE = 256
add_frame_elements.py View file @ 8413085
... ... @@ -201,7 +201,7 @@
201 201 self.masking_heuristic_radio_button_current_flow_closeness=Radiobutton(self.modify_design_frame,
202 202 text="Current-flow closeness",
203 203 variable=self.masking_heuristic,
204   - value="current_flow_loseness")
  204 + value="current_flow_closeness")
205 205 self.masking_heuristic_radio_button_current_flow_closeness.grid(row=2,
206 206 column=4,
207 207 sticky=W,
... ... @@ -94,7 +94,7 @@
94 94 # Logic modifier frame
95 95 self.setState(self.modify_design_frame, state = "disabled")
96 96 self.setState(self.generate_save_modified_design_frame, state = "disabled")
97   - self.setState(self.wrap_modified_design_frame, state = "disabled")
  97 + self.setState(self.wrap_modified_design_frame, state = "enabled")
98 98 # Activation frame
99 99 self.setState(self.CASCADE_frame, state = "disabled")
100 100 self.setState(self.key_derivation_frame, state = "disabled")
... ... @@ -305,7 +305,7 @@
305 305 self.connected.set(True)
306 306 self.board_status.set("Board Connected")
307 307 self.board_status_label.configure(foreground="darkgreen")
308   - self.status.set("")
  308 + self.update_status("")
309 309 self.setState(self.get_PUF_response_frame, state = "normal")
310 310  
311 311 def disconnect(self):
... ... @@ -479,15 +479,19 @@
479 479 self.tcl_obj.eval(self.board_manager.reset_boards(port=2))
480 480 print self.tcl_obj.eval(self.board_manager.generate_response())
481 481 server_before = self.server_reference_response
482   - self.server_reference_response = cascade(self.server_reference_response,
483   - 0.02,
484   - int(self.reconciliation_parameter_number_of_passes_spinbox.get()),
485   - self.tcl_obj,
486   - self.board_manager,
487   - int(self.reconciliation_parameter_initial_block_size_spinbox.get()))
488   - server_after = self.server_reference_response
489   - print "Errors corrected :", [a for (a, (b, c)) in enumerate(zip(server_before, server_after)) if b != c]
490   - self.status.set("Reconciliation done")
  482 + self.server_reference_response, leakage = cascade(self.server_reference_response,
  483 + 0.02,
  484 + int(self.reconciliation_parameter_number_of_passes_spinbox.get()),
  485 + self.tcl_obj,
  486 + self.board_manager,
  487 + int(self.reconciliation_parameter_initial_block_size_spinbox.get()))
  488 + if self.server_reference_response:
  489 +
  490 + server_after = self.server_reference_response
  491 + print "Errors corrected :", [a for (a, (b, c)) in enumerate(zip(server_before, server_after)) if b != c]
  492 + self.update_status("Reconciliation done, "+str(leakage)+" bits leaked", color="darkgreen")
  493 + else:
  494 + self.update_status("Reconciliation failed, too much leakage. Try with other parameters.", color="red")
491 495  
492 496 def encrypt_activation_word(self):
493 497 ref_rep = "".join([str(i) for i in self.server_reference_response])[::-1]
494 498  
495 499  
496 500  
... ... @@ -496,15 +500,15 @@
496 500 encrypted_AW_file_name = self.activation_word_file.replace("formatted", "encrypted")
497 501 with open(encrypted_AW_file_name, "w") as encrypted_AW_file:
498 502 encrypted_AW_file.write(self.encrypted_AW)
499   - self.status.set("Encrypted AW saved under "+encrypted_AW_file_name)
500   -
  503 + self.update_status("Encrypted AW saved under "+encrypted_AW_file_name)
501 504 def start_activation_process(self):
502 505 print self.encrypted_AW
503 506 print self.tcl_obj.eval(self.board_manager.activate_design(self.encrypted_AW))
504   - self.status.set("Activation done")
  507 + self.update_status("Activation done", color="darkgreen")
505 508  
506   - def update_status(self, text):
  509 + def update_status(self, text, color = "black"):
507 510 self.status.set(text)
  511 + self.status_label.configure(foreground=color)
508 512  
509 513 def reset_board(self, port=2):
510 514 self.update_status("")
boards_management/get_response.py View file @ 8413085
... ... @@ -17,7 +17,7 @@
17 17 tclsh = Tkinter.Tcl()
18 18 board_manager = board_commands.Board_manager()
19 19 tclsh.eval(board_manager.source_tcl_package())
20   - tclsh.eval(board_manager.connect("COM7"))
  20 + tclsh.eval(board_manager.connect("COM6"))
21 21 tclsh.eval(board_manager.reset_boards(2))
22 22 for i in range(10):
23 23 response = tclsh.eval(board_manager.generate_response())
declare_initialize_variables.py View file @ 8413085
... ... @@ -26,7 +26,7 @@
26 26 self.modified_design_to_wrap = StringVar()
27 27 self.modified_design_to_wrap.set("No design loaded")
28 28 self.com_port = StringVar()
29   - self.com_port.set("COM4")
  29 + self.com_port.set("COM6")
30 30 self.masking_overhead = IntVar()
31 31 self.masking_overhead.set(5)
32 32 self.locking_overhead = IntVar()