Commit afe806cde3b40e14b6ec9568f8a020f6a7c31e7c

Authored by Brice Colombier
1 parent 48a1b0ac81
Exists in master

Improved block size

Showing 4 changed files with 99 additions and 87 deletions

CASCADE/cascade.py View file @ afe806c
... ... @@ -47,7 +47,9 @@
47 47 print "Passe:", passe
48 48 block_size_increased = False
49 49 if block_size < len(reference_response)/2:
50   - block_size *= 2
  50 + block_size *= 4
  51 + if block_size > len(reference_response)/2:
  52 + block_size = len(reference_response)/2
51 53 block_size_increased = True
52 54 print "Block size:", block_size
53 55 reference_response_indexed = zip(indices, reference_response)
add_frame_elements.py View file @ afe806c
... ... @@ -276,47 +276,47 @@
276 276 self.activation_word_saved_label.grid(row=3,
277 277 column=1,
278 278 sticky=W)
279   - self.modified_design_to_wrap_label=Label(self.wrap_modified_design_frame,
280   - text="Design to wrap:")
281   - self.modified_design_to_wrap_label.grid(row=0, column=0, sticky=E)
282   - self.modified_design_to_wrap_entry=Entry(self.wrap_modified_design_frame,
283   - width=150,
284   - textvariable=self.modified_design_to_wrap)
285   - self.modified_design_to_wrap_entry.grid(row=0,
286   - column=1,
287   - sticky="EW")
288   - self.button_open_modified_design_to_wrap=Button(self.wrap_modified_design_frame,
289   - text="Search...",
290   - command=self.select_modified_design_to_wrap)
291   - self.button_open_modified_design_to_wrap.grid(row=0, column=2)
292   - self.associated_activation_word_label = Label(self.wrap_modified_design_frame,
293   - text="Associated Activation word:")
294   - self.associated_activation_word_label.grid(sticky=E)
295   - self.associated_activation_word_display_label = Label(self.wrap_modified_design_frame,
296   - textvariable=self.associated_activation_word,
297   - font=("Courier", 8),
298   - background="white",
299   - width=20)
300   - self.associated_activation_word_display_label.grid(row=1, column=1, sticky="EW", padx=10)
  279 + # self.modified_design_to_wrap_label=Label(self.wrap_modified_design_frame,
  280 + # text="Design to wrap:")
  281 + # self.modified_design_to_wrap_label.grid(row=0, column=0, sticky=E)
  282 + # self.modified_design_to_wrap_entry=Entry(self.wrap_modified_design_frame,
  283 + # width=150,
  284 + # textvariable=self.modified_design_to_wrap)
  285 + # self.modified_design_to_wrap_entry.grid(row=0,
  286 + # column=1,
  287 + # sticky="EW")
  288 + # self.button_open_modified_design_to_wrap=Button(self.wrap_modified_design_frame,
  289 + # text="Search...",
  290 + # command=self.select_modified_design_to_wrap)
  291 + # self.button_open_modified_design_to_wrap.grid(row=0, column=2)
  292 + # self.associated_activation_word_label = Label(self.wrap_modified_design_frame,
  293 + # text="Associated Activation word:")
  294 + # self.associated_activation_word_label.grid(sticky=E)
  295 + # self.associated_activation_word_display_label = Label(self.wrap_modified_design_frame,
  296 + # textvariable=self.associated_activation_word,
  297 + # font=("Courier", 8),
  298 + # background="white",
  299 + # width=20)
  300 + # self.associated_activation_word_display_label.grid(row=1, column=1, sticky="EW", padx=10)
301 301  
302   - self.open_associated_activation_word_wrapped_button=Button(self.wrap_modified_design_frame,
303   - text="Search...",
304   - state="normal",
305   - command=self.open_associated_activation_word)
306   - self.open_associated_activation_word_wrapped_button.grid(row=1,
307   - column=2,
308   - sticky=W)
  302 + # self.open_associated_activation_word_wrapped_button=Button(self.wrap_modified_design_frame,
  303 + # text="Search...",
  304 + # state="normal",
  305 + # command=self.open_associated_activation_word)
  306 + # self.open_associated_activation_word_wrapped_button.grid(row=1,
  307 + # column=2,
  308 + # sticky=W)
309 309  
310 310 self.crypto_label = Label(self.wrap_modified_design_frame,
311 311 text="Crypto:")
312   - self.crypto_label.grid(row=2,
  312 + self.crypto_label.grid(row=0,
313 313 column=0,
314 314 sticky = E)
315 315 self.select_crypto_OTP = Radiobutton(self.wrap_modified_design_frame,
316 316 text="One Time Pad",
317 317 variable=self.crypto,
318 318 value="OTP")
319   - self.select_crypto_OTP.grid(row=2,
  319 + self.select_crypto_OTP.grid(row=0,
320 320 column=1,
321 321 sticky=W)
322 322 self.select_crypto_PRESENT = Radiobutton(self.wrap_modified_design_frame,
323 323  
324 324  
... ... @@ -324,19 +324,19 @@
324 324 state=DISABLED,
325 325 variable=self.crypto,
326 326 value="PRESENT")
327   - self.select_crypto_PRESENT.grid(row=3,
  327 + self.select_crypto_PRESENT.grid(row=1,
328 328 column=1,
329 329 sticky=W)
330 330 self.key_derivation_label = Label(self.wrap_modified_design_frame,
331 331 text="Key generation:")
332   - self.key_derivation_label.grid(row=4,
  332 + self.key_derivation_label.grid(row=2,
333 333 column=0,
334 334 sticky = E)
335 335 self.select_key_derivation_none = Radiobutton(self.wrap_modified_design_frame,
336 336 text="None",
337 337 variable=self.key_derivation,
338 338 value="None")
339   - self.select_key_derivation_none.grid(row=4,
  339 + self.select_key_derivation_none.grid(row=2,
340 340 column=1,
341 341 sticky=W)
342 342 self.select_key_derivation_blake2 = Radiobutton(self.wrap_modified_design_frame,
... ... @@ -344,7 +344,7 @@
344 344 state=DISABLED,
345 345 variable=self.key_derivation,
346 346 value="Blake2")
347   - self.select_key_derivation_blake2.grid(row=5,
  347 + self.select_key_derivation_blake2.grid(row=3,
348 348 column=1,
349 349 sticky=W)
350 350 self.generate_wrapped_design_button=Button(self.wrap_modified_design_frame,
... ... @@ -352,7 +352,7 @@
352 352 state="normal",
353 353 command= self.generate_save_wrapped_design,
354 354 width=32)
355   - self.generate_wrapped_design_button.grid(row=6,
  355 + self.generate_wrapped_design_button.grid(row=4,
356 356 column=0,
357 357 sticky=W)
358 358 self.save_associated_activation_word_wrapped_button=Button(self.wrap_modified_design_frame,
... ... @@ -360,7 +360,7 @@
360 360 state="normal",
361 361 command=self.save_formatted_AW,
362 362 width=32)
363   - self.save_associated_activation_word_wrapped_button.grid(row=7,
  363 + self.save_associated_activation_word_wrapped_button.grid(row=5,
364 364 column=0,
365 365 sticky=W)
366 366  
... ... @@ -65,8 +65,8 @@
65 65  
66 66 self.master = master
67 67  
68   - # self.master.maxsize(width=800, height=560)
69   - # self.master.minsize(width=800, height=560)
  68 + self.master.maxsize(width=1184, height=540)
  69 + self.master.minsize(width=1184, height=540)
70 70 self.master.resizable(width=False, height=False)
71 71 self.master.title("SALWARE IP protection tool")
72 72 self.master.iconbitmap(default='./contents/icon.ico')
73 73  
... ... @@ -137,12 +137,12 @@
137 137 self.design_format.set("Verilog Dataflow")
138 138 self.build_graph_button.configure(state = "normal")
139 139  
140   - def select_modified_design_to_wrap(self):
141   - self.update_status("")
  140 + # def select_modified_design_to_wrap(self):
  141 + # self.update_status("")
142 142  
143   - ftypes = [("VHDL files", ".vhd")]
144   - self.modified_design_to_wrap.set(tkFileDialog.askopenfilename(initialdir = "./user_space/",
145   - filetypes=ftypes))
  143 + # ftypes = [("VHDL files", ".vhd")]
  144 + # self.modified_design_to_wrap.set(tkFileDialog.askopenfilename(initialdir = "./user_space/",
  145 + # filetypes=ftypes))
146 146  
147 147 def build_graph(self):
148 148 self.update_status("")
... ... @@ -213,20 +213,20 @@
213 213 self.activation_word.set(line)
214 214 self.encrypt_activation_word_button.configure(state = "enabled")
215 215  
216   - def open_associated_activation_word(self):
217   - self.update_status("")
218   - awtypes = [("Activation word file", ".txt")]
219   - self.associated_activation_word_file = tkFileDialog.askopenfilename(initialdir = "./../User_space/",
220   - filetypes=awtypes)
221   - with open(self.associated_activation_word_file, "r") as awfile:
222   - line = awfile.readline() # First line of the file
223   - line = awfile.readline() # Get the second line
224   - if not set(line) <= {"0", "1", " ", "\n"}:
225   - self.update_status("The file could not be parsed as an Activation Word file")
226   - else:
227   - self.associated_activation_word.set(line)
228   - if self.modified_design_to_wrap.get() != "No design loaded":
229   - self.generate_wrapped_design_button.configure(state = "normal")
  216 + # def open_associated_activation_word(self):
  217 + # self.update_status("")
  218 + # awtypes = [("Activation word file", ".txt")]
  219 + # self.associated_activation_word_file = tkFileDialog.askopenfilename(initialdir = "./../User_space/",
  220 + # filetypes=awtypes)
  221 + # with open(self.associated_activation_word_file, "r") as awfile:
  222 + # line = awfile.readline() # First line of the file
  223 + # line = awfile.readline() # Get the second line
  224 + # if not set(line) <= {"0", "1", " ", "\n"}:
  225 + # self.update_status("The file could not be parsed as an Activation Word file")
  226 + # else:
  227 + # self.associated_activation_word.set(line)
  228 + # if self.modified_design_to_wrap.get() != "No design loaded":
  229 + # self.generate_wrapped_design_button.configure(state = "normal")
230 230  
231 231 def round_masking(self, _): # Dummy second argument
232 232 self.masking_overhead.set(int(round(self.masking_overhead.get())))
... ... @@ -253,6 +253,7 @@
253 253 self.update_status("")
254 254 with open("./user_space/rr.txt", "w") as rrfile:
255 255 rrfile.write("Reference response: "+self.PUF_response_displayed.get())
  256 + # rrfile.write(self.PUF_response_displayed.get()+"\n")
256 257 self.update_status("Reference response saved under ./user_space/rr.txt")
257 258  
258 259 def pop_up_about(self):
... ... @@ -335,8 +336,7 @@
335 336  
336 337 def modify_design(self):
337 338 self.update_status("")
338   - self.unlocking_word = ""
339   - self.unmasking_word = ""
  339 + self.associated_activation_word = ""
340 340 self.update_status("Modifying the design...")
341 341 self.master.config(cursor="wait")
342 342 self.graph_info_label.configure(foreground="black")
343 343  
... ... @@ -346,18 +346,18 @@
346 346  
347 347 message = "" # Locking message, in case the overhead is too low to allow for total locking
348 348 if self.modify_design_mode.get() == "locking":
349   - self.graph_modified, self.unlocking_word, self.locking_inputs, list_nodes_to_lock, message = locking(self.g,
350   - self.prim_in,
351   - self.prim_out,
352   - self.nodes,
353   - self.locking_overhead.get())
  349 + self.graph_modified, self.associated_activation_word, self.locking_inputs, list_nodes_to_lock, message = locking(self.g,
  350 + self.prim_in,
  351 + self.prim_out,
  352 + self.nodes,
  353 + self.locking_overhead.get())
354 354 elif self.modify_design_mode.get() == "masking":
355   - self.graph_modified, self.unmasking_word, self.masking_inputs = masking(self.g,
356   - self.prim_in,
357   - self.prim_out,
358   - self.nodes,
359   - self.masking_overhead.get(),
360   - self.masking_heuristic.get())
  355 + self.graph_modified, self.associated_activation_word, self.masking_inputs = masking(self.g,
  356 + self.prim_in,
  357 + self.prim_out,
  358 + self.nodes,
  359 + self.masking_overhead.get(),
  360 + self.masking_heuristic.get())
361 361 self.setState(self.generate_save_modified_design_frame, state = "normal")
362 362 self.save_associated_activation_word_simple_button.configure(state = "enabled")
363 363 self.setState(self.modify_design_frame, state = "enabled")
... ... @@ -401,6 +401,7 @@
401 401 self.update_status(str("Modified design saved under ./user_space/"+filename.split("/")[-1]))
402 402 self.save_associated_activation_word_simple_button.configure(state = "normal")
403 403 self.generate_modified_design_button.configure(state = "enabled")
  404 + self.path_to_modified_design = self.filename.get()
404 405  
405 406 def save_associated_AW(self):
406 407 self.update_status("")
407 408  
408 409  
409 410  
410 411  
411 412  
412 413  
... ... @@ -411,22 +412,29 @@
411 412 filename = ".".join(filename)
412 413 filename = "/".join(self.filename.get().split("/")[:-1])+"/"+filename
413 414 with open(filename, "w") as aw_file:
414   - aw_file.write("Unlocking word concatenated with unmasking word\n"+self.unlocking_word+" "+self.unmasking_word)
  415 + aw_file.write("Activation word\n"+self.associated_activation_word)
415 416 self.update_status(str("Associated activation word saved under ./user_space/"+filename.split("/")[-1]))
416 417 self.setState(self.wrap_modified_design_frame, state = "normal")
417 418 self.select_crypto_PRESENT.configure(state = "disabled")
418 419 self.select_key_derivation_blake2.configure(state = "disabled")
419 420 self.setState(self.generate_save_modified_design_frame, state = "enabled")
  421 + print self.filename.get()
420 422  
421 423  
422 424 def save_formatted_AW(self):
423 425 self.update_status("")
424   - filename = self.modified_design_to_wrap.get().split("/")[-1]
  426 + filename = self.filename.get().split("/")[-1]
  427 + print "Filename:", filename
425 428 filename = filename.split(".")
  429 + print "Filename:", filename
426 430 filename[0]+="_formatted_AW"
  431 + print "Filename:", filename
427 432 filename[1] = "txt"
  433 + print "Filename:", filename
428 434 filename = ".".join(filename)
429   - filename = "/".join(self.modified_design_to_wrap.get().split("/")[:-1])+"/"+filename
  435 + print "Filename:", filename
  436 + filename = "/".join(self.filename.get().split("/")[:-1])+"/"+filename
  437 + print "Filename:", filename
430 438 # print filename
431 439 with open(filename, "w") as aw_file:
432 440 aw_file.write("Formatted Activation Word\n"+self.formatted_AW)
433 441  
434 442  
435 443  
436 444  
437 445  
... ... @@ -442,26 +450,22 @@
442 450 self.master.config(cursor="wait")
443 451 self.graph_info_label.configure(foreground="black")
444 452 self.master.update()
445   - print self.associated_activation_word.get()[-1]
446   - if self.associated_activation_word.get()[-1] == " ":
447   - self.associated_activation_word.set(self.associated_activation_word.get().strip())
  453 + # print self.associated_activation_word.get()[-1]
  454 + if self.modify_design_mode.get() == "locking":
448 455 locking = True
449 456 masking = False
450   - elif self.associated_activation_word.get()[0] == " ":
451   - self.associated_activation_word.set(self.associated_activation_word.get().strip())
452   - masking = True
  457 + elif self.modify_design_mode.get() == "masking":
453 458 locking = False
454   - elif len(self.associated_activation_word.get().split(" ")) == 2:
455 459 masking = True
456   - locking = True
457 460 try: #Generate AW
458   - print self.associated_activation_word.get()
459   - self.formatted_AW = gen_AW_decoder(self.associated_activation_word.get(),
  461 + # print self.associated_activation_word.get()
  462 + self.formatted_AW = gen_AW_decoder(self.associated_activation_word,
460 463 128, #128-bit responses
461 464 locking = locking,
462 465 masking = masking,
463 466 path = "./user_space/")
464 467 except:
  468 + print "An error occured while generating the AW decoder"
465 469 self.update_status("An error occured while generating the AW decoder")
466 470 try: #Generate activable design
467 471 generate_activable_design("./user_space/"+self.filename.get().split("/")[-1].split(".")[0]+"_mod.vhd",
... ... @@ -480,6 +484,7 @@
480 484 except Exception as e:
481 485 print e
482 486 self.update_status("An error occured while generating the wrapped design")
  487 + print self.formatted_AW
483 488 self.master.config(cursor="")
484 489 self.master.update()
485 490  
... ... @@ -515,8 +520,8 @@
515 520 self.setState(self.activation_process_frame, state = "enabled")
516 521  
517 522 def start_activation_process(self):
518   - # print self.encrypted_AW
519   - # print self.tcl_obj.eval(self.board_manager.activate_design(self.encrypted_AW))
  523 + print self.encrypted_AW
  524 + print self.tcl_obj.eval(self.board_manager.activate_design(self.encrypted_AW))
520 525 self.update_status("Activation done", color="darkgreen")
521 526  
522 527 def update_status(self, text, color = "black"):
build_tabs.py View file @ afe806c
... ... @@ -31,4 +31,9 @@
31 31 self.note.add(self.tab_activation, text="Activation",
32 32 padding=[0, 2, 0, 0])
33 33 self.note.pack(side = "top", fill="both", expand="yes")
  34 +
  35 + def handle_tab_changed(event):
  36 + self.update_status("")
  37 +
  38 + self.note.bind("<<NotebookTabChanged>>", handle_tab_changed)