Commit 1ca3b2c206e6fd348caedc05e6ecfbf8612f1ebb

Authored by Brice Colombier
1 parent 757796eef5
Exists in master

Save reference response in a file

Showing 4 changed files with 79 additions and 39 deletions

add_frame_elements.py View file @ 1ca3b2c
... ... @@ -69,21 +69,39 @@
69 69 column=3,
70 70 rowspan=2,
71 71 padx=10)
72   - self.get_reference_response_button=Button(self.get_PUF_reference_response_frame,
73   - text="Get/update reference response",
74   - command=self.get_PUF_reference_response,
75   - width=28,
76   - state="normal")
77   - self.get_reference_response_button.pack(side=LEFT)
78   - self.reference_response_label=Label(self.get_PUF_reference_response_frame,
79   - textvariable=self.PUF_reference_response_displayed,
  72 + self.load_server_reference_response_label = Label(self.load_server_reference_response_frame,
  73 + text="Reference response on server:")
  74 + self.load_server_reference_response_label.pack(side=LEFT)
  75 + self.reference_response_label=Label(self.load_server_reference_response_frame,
  76 + textvariable=self.server_reference_response_displayed,
80 77 font=("Courier", 8),
81 78 background="white")
82   - self.reference_response_label.pack(side=LEFT, padx=10, fill="x")
  79 + self.reference_response_label.pack(side=LEFT, padx=10, fill="x", expand="yes")
  80 + self.load_server_reference_response_button=Button(self.load_server_reference_response_frame,
  81 + text="Search...",
  82 + command=self.open_server_reference_response)
  83 + self.load_server_reference_response_button.pack(side=LEFT)
  84 + self.get_PUF_response_button=Button(self.get_PUF_response_frame,
  85 + text="Get PUF response",
  86 + command=self.get_PUF_response,
  87 + state="normal")
  88 + self.get_PUF_response_button.grid(row=0, column=0, sticky = "WE")
  89 + self.PUF_response_label=Label(self.get_PUF_response_frame,
  90 + textvariable=self.PUF_response_displayed,
  91 + font=("Courier", 8),
  92 + background="white")
  93 + self.PUF_response_label.grid(row=0, column=1, sticky="WE", padx=10)
  94 + self.save_as_reference_response_button=Button(self.get_PUF_response_frame,
  95 + text="Save as reference response",
  96 + command=self.save_as_reference_response,
  97 + state="normal")
  98 + self.save_as_reference_response_button.grid(row=1, column=0)
  99 + self.save_as_reference_response_status_label=Label(self.get_PUF_response_frame,
  100 + textvariable=self.save_as_reference_response_status)
  101 + self.save_as_reference_response_status_label.grid(row=1, column=1, sticky="W", padx=10)
83 102 self.derive_key_button=Button(self.key_derivation_frame,
84 103 text="Derive a key from the response",
85 104 command=self.derive_key_from_response,
86   - width=28,
87 105 state="normal")
88 106 self.derive_key_button.pack(side=LEFT)
89 107 self.key_saved_label=Label(self.key_derivation_frame,
90 108  
... ... @@ -251,11 +269,11 @@
251 269 text="Activation word:")
252 270 self.activation_word_label.grid(sticky=E)
253 271 self.activation_word_entry = Entry(self.activation_word_encryption_frame,
254   - textvariable=self.activation_word,
  272 + textvariable=self.activation_word_file,
255 273 width=90)
256 274 self.activation_word_entry.grid(row=0, column=1, sticky="EW")
257 275 self.search_activation_word_button = Button(self.activation_word_encryption_frame,
258   - text="Search",
  276 + text="Search...",
259 277 command=self.open_activation_word)
260 278 self.search_activation_word_button.grid(row=0, column=2)
261 279 self.encrypt_activation_word_button = Button(self.activation_word_encryption_frame,
... ... @@ -33,9 +33,9 @@
33 33 from parsers.build_blif import build as build_blif
34 34 from parsers.build_edif import build as build_edif
35 35 from parsers.build_slif import build as build_slif
36   -from parsers.build_verilog_df import build as build_verilog_df
  36 +from parsers.build_verilog_df import build as build_verilog_df
37 37 from parsers.build_verilog_struct import build as build_verilog_struct
38   -from parsers.build_vhd_df import build as build_vhd_df
  38 +from parsers.build_vhd_df import build as build_vhd_df
39 39 from parsers.build_vhd_struct import build as build_vhd_struct
40 40 from parsers.build_xilinx import build as build_xilinx
41 41  
42 42  
43 43  
... ... @@ -129,17 +129,26 @@
129 129 self.graph_info_label.configure(foreground="red")
130 130 self.master.config(cursor="")
131 131 self.master.update()
132   -
133 132  
134   - def open_bitstream_file(self):
135   - btypes = [("Xilinx", ".bit"),
136   - ("Altera", ".cdf")]
137   - self.bitstream.set(tkFileDialog.askopenfilename(initialdir = "./../User_space/",
138   - filetypes=btypes))
139   -
  133 + def open_server_reference_response(self):
  134 + rrtypes = [("Reference response file", ".txt")]
  135 + self.server_reference_response_file.set(tkFileDialog.askopenfilename(initialdir = "./../User_space/",
  136 + filetypes=rrtypes))
  137 + with open(self.server_reference_response_file.get(), "r") as rrfile:
  138 + line = rrfile.readline()
  139 + if line[:20] != "Reference response: ":
  140 + raise SyntaxError ("The file could not be parsed as a Reference response file")
  141 + else:
  142 + self.server_reference_response = line[20:]
  143 + for i in self.server_reference_response:
  144 + if i not in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]:
  145 + raise SyntaxError ("The reference response contains illegal characters")
  146 + else:
  147 + self.server_reference_response_displayed.set(self.server_reference_response)
  148 +
140 149 def open_activation_word(self):
141 150 ttypes = [("Activation word", ".txt")]
142   - self.activation_word.set(tkFileDialog.askopenfilename(initialdir = "./../User_space/",
  151 + self.activation_word_file.set(tkFileDialog.askopenfilename(initialdir = "./../User_space/",
143 152 filetypes=ttypes))
144 153  
145 154 def round_masking(self, _): # Dummy second argument
146 155  
147 156  
148 157  
149 158  
150 159  
... ... @@ -148,19 +157,24 @@
148 157 def round_locking(self, _): # Dummy second argument
149 158 self.locking_overhead.set(int(round(self.locking_overhead.get())))
150 159  
151   - def get_PUF_reference_response(self):
152   - self.PUF_reference_response_displayed.set("")
  160 + def get_PUF_response(self):
  161 + self.PUF_response_displayed.set("")
153 162 try:
154   - self.PUF_reference_response_displayed.set(self.tcl_obj.eval(self.board_manager.generate_and_offload_response()))
155   - self.PUF_reference_response = self.PUF_reference_response_displayed.get()
  163 + self.PUF_response_displayed.set(self.tcl_obj.eval(self.board_manager.generate_and_offload_response()))
  164 + self.PUF_response = self.PUF_response_displayed.get()
156 165 temporary_response = ""
157   - for i in self.PUF_reference_response:
  166 + for i in self.PUF_response:
158 167 binary = bin(int(i, 16))[2:]
159 168 temporary_response+=((4-len(binary))*"0"+binary)
160   - self.PUF_reference_response = [int(i) for i in temporary_response]
  169 + self.PUF_response = [int(i) for i in temporary_response]
161 170 except:
162   - self.status.set("Reference response could not be obtained")
  171 + self.status.set("Response could not be obtained")
163 172  
  173 + def save_as_reference_response(self):
  174 + with open("./user_space/rr.txt", "w") as rrfile:
  175 + rrfile.write("Reference response: "+self.PUF_response_displayed.get())
  176 + self.save_as_reference_response_status.set("Reference response saved under ./user_space/rr.txt")
  177 +
164 178 def pop_up_about(self):
165 179 self.top = Toplevel(background="White")
166 180 self.top.title("About")
... ... @@ -253,7 +267,7 @@
253 267 def derive_key_from_response(self):
254 268 self.salt = bytes(''.join(random.SystemRandom().choice(["0", "1"]) for _ in range(32)))
255 269 PRK_f = BLAKE2s(digest_size=32, key=self.salt)
256   - PRK_f.update(self.PUF_reference_response_displayed)
  270 + PRK_f.update(self.PUF_response_displayed)
257 271 self.key = ''.join('{0:08b}'.format(ord(x), 'b') for x in PRK_f.final()).replace("0b", "")
258 272 key_file_name = "./user_space/key_"+""+".txt"
259 273 with open(key_file_name, "w") as key_file:
... ... @@ -289,7 +303,7 @@
289 303 self.message_AW_saved.set(str("Activation word saved under "+filename))
290 304  
291 305 def perform_reconciliation(self):
292   - cascade(self.PUF_reference_response,
  306 + cascade(self.PUF_response,
293 307 0.02,
294 308 int(self.reconciliation_parameter_number_of_passes_spinbox.get()),
295 309 self.tcl_obj,
declare_initialize_variables.py View file @ 1ca3b2c
... ... @@ -18,8 +18,8 @@
18 18 self.locking = BooleanVar()
19 19 self.daughter_board = StringVar()
20 20 self.daughter_board.set("S6")
21   - self.PUF_reference_response_displayed = StringVar()
22   - self.PUF_reference_response_displayed.set(256*" ")
  21 + self.PUF_response_displayed = StringVar()
  22 + self.PUF_response_displayed.set(256*" ")
23 23 self.filepath = StringVar()
24 24 self.filename = StringVar()
25 25 self.filename.set("No design loaded")
26 26  
27 27  
... ... @@ -49,13 +49,19 @@
49 49 self.status.set("")
50 50 self.board_status = StringVar()
51 51 self.board_status.set("Board not connected")
  52 + self.save_as_reference_response_status = StringVar()
  53 + self.save_as_reference_response_status.set("")
52 54  
53   - self.activation_word = StringVar()
54   - self.activation_word.set("")
  55 + self.activation_word_file = StringVar()
  56 + self.activation_word_file.set("")
55 57 self.design_format = StringVar()
56 58 self.design_format.set("BENCH")
57 59 self.generated_design_format = StringVar()
58 60 self.generated_design_format.set("bench")
59 61 self.programming_command = StringVar()
60 62 self.programming_command.set("")
  63 + self.server_reference_response_displayed = StringVar()
  64 + self.server_reference_response_displayed.set("")
  65 + self.server_reference_response_file = StringVar()
  66 + self.server_reference_response_file.set("")
declare_pack_frames.py View file @ 1ca3b2c
... ... @@ -34,15 +34,17 @@
34 34  
35 35 # Tab enrolment
36 36  
37   - self.get_PUF_reference_response_frame = LabelFrame(self.tab_enrolment,
38   - text="PUF reference response")
39   - self.get_PUF_reference_response_frame.pack(fill="x", side="top")
  37 + self.get_PUF_response_frame = LabelFrame(self.tab_enrolment,
  38 + text="PUF response")
  39 + self.get_PUF_response_frame.pack(fill="x", side="top")
40 40 self.key_derivation_frame = LabelFrame(self.tab_enrolment,
41 41 text="Key derivation")
42 42 self.key_derivation_frame.pack(fill="x", side="top")
43 43  
44 44 # Tab activation
45   -
  45 + self.load_server_reference_response_frame = LabelFrame(self.tab_activation,
  46 + text="Load server reference response")
  47 + self.load_server_reference_response_frame.pack(fill="x")
46 48 self.CASCADE_frame = LabelFrame(self.tab_activation,
47 49 text="CASCADE protocol")
48 50 self.CASCADE_frame.pack(fill="x")