Commit 48a1b0ac81970e8bbd4d444f66017ebbeab9f03b

Authored by Brice Colombier
1 parent 8413085ad9
Exists in master

Fixed display of parts

Showing 12 changed files with 188 additions and 354 deletions

AW_decoder/gen_AW_decoder.py View file @ 48a1b0a
... ... @@ -234,9 +234,9 @@
234 234 if __name__ == "__main__":
235 235 # print gen_AW_decoder("0101 1100", 16, locking=True, masking=True)
236 236 # print gen_AW_decoder("01011100", 16, locking=True, masking=False)
237   - print gen_AW_decoder("01011100", 16, locking=False, masking=True)
  237 + # print gen_AW_decoder("01011100", 16, locking=False, masking=True)
238 238 # print gen_AW_decoder("0101 1100", 8, locking=True, masking=True)
239   - # print gen_AW_decoder("01011100", 8, locking=True, masking=False)
  239 + print gen_AW_decoder("01011100", 8, locking=True, masking=False)
240 240 # print gen_AW_decoder("01011100", 8, locking=False, masking=True)
241 241 # print gen_AW_decoder("0101 1100", 4, locking=True, masking=True)
242 242 # print gen_AW_decoder("01011100", 4, locking=True, masking=False)
Doc/auto/doc_demonstrator.el View file @ 48a1b0a
1   -(TeX-add-style-hook
2   - "doc_demonstrator"
3   - (lambda ()
4   - (TeX-add-to-alist 'LaTeX-provided-class-options
5   - '(("article" "a4paper" "11pt")))
6   - (TeX-add-to-alist 'LaTeX-provided-package-options
7   - '(("geometry" "margin=3cm") ("biblatex" "style=ieee" "doi=false" "isbn=false" "url=false")))
8   - (add-to-list 'LaTeX-verbatim-macros-with-braces-local "path")
9   - (add-to-list 'LaTeX-verbatim-macros-with-braces-local "url")
10   - (add-to-list 'LaTeX-verbatim-macros-with-delims-local "path")
11   - (add-to-list 'LaTeX-verbatim-macros-with-delims-local "url")
12   - (TeX-run-style-hooks
13   - "latex2e"
14   - "article"
15   - "art11"
16   - "libertine"
17   - "geometry"
18   - "biblatex")
19   - (LaTeX-add-labels
20   - "sec:requirements"
21   - "sec:hardw-requ"
22   - "sec:softw-requ"
23   - "sec:theory"
24   - "sec:logic-locking"
25   - "sec:logic-masking"
26   - "sec:cascade-protocool"
27   - "sec:usage"
28   - "sec:parsers"
29   - "sec:gui")
30   - (LaTeX-add-bibliographies
31   - "F:/biblio"))
32   - :latex)
Doc/doc_demonstrator.pdf View file @ 48a1b0a

No preview for this file type

Doc/doc_demonstrator.tex View file @ 48a1b0a
1   -\documentclass[a4paper, 11pt]{article}
2   -\usepackage{libertine}
3   -\usepackage[margin = 3cm]{geometry}
4   -
5   -\usepackage[style=ieee,doi=false,isbn=false,url=false]{biblatex}
6   -\bibliography{F:/biblio}
7   -
8   -
9   -\title{Documentation}
10   -\author{Brice \textsc{Colombier}\\~\\
11   - Univ Lyon, UJM-Saint-Etienne, CNRS\\
12   - Laboratoire Hubert Curien UMR 5516\\
13   - F-42023, Saint-\'Etienne, France\\
14   - \texttt{b.colombier@univ-st-etienne.fr}}
15   -
16   -
17   -\begin{document}
18   -\maketitle
19   -\thispagestyle{empty}
20   -
21   -\tableofcontents
22   -
23   -\newpage
24   -
25   -\section{Requirements}
26   -\label{sec:requirements}
27   -
28   -\subsection{Hardware requirements}
29   -\label{sec:hardw-requ}
30   -
31   -\subsection{Software requirements}
32   -\label{sec:softw-requ}
33   -
34   -\section{Theory}
35   -\label{sec:theory}
36   -
37   -\subsection{Logic locking}
38   -\label{sec:logic-locking}
39   -
40   -\cite{Colombier2015c}
41   -
42   -\subsection{Logic masking}
43   -\label{sec:logic-masking}
44   -
45   -\subsection{CASCADE protocool}
46   -\label{sec:cascade-protocool}
47   -
48   -\section{Usage}
49   -\label{sec:usage}
50   -
51   -\subsection{Parsers}
52   -\label{sec:parsers}
53   -
54   -Example design file
55   -Cells dictionnary
56   -
57   -\subsection{GUI}
58   -\label{sec:gui}
59   -
60   -VHDL code should not include comments
61   -Describe strict syntax from example files in Parsers
62   -
63   -
64   -\printbibliography
65   -
66   -\end{document}
activable_design/generate_activable_design.py View file @ 48a1b0a
... ... @@ -104,11 +104,9 @@
104 104 locking,
105 105 masking):
106 106 target_file_name = modified_design_file_name.replace("mod", "activable")
107   - print modified_design_file_name
108 107  
109 108 with open(target_file_name, "w") as target_file:
110 109 entity_name = get_entity(modified_design_file_name)
111   - print entity_name
112 110 inputs, outputs = write_entity(target_file, modified_design_file_name, entity_name, locking[1], masking[1])
113 111 write_architecture(target_file, entity_name, locking, masking, inputs, outputs)
114 112  
add_frame_elements.py View file @ 48a1b0a
... ... @@ -37,19 +37,22 @@
37 37 self.com_port_button_disconnect.pack(side=LEFT)
38 38 # ------------------------------------------------------
39 39 self.reconciliation_parameters_label = Label(self.CASCADE_frame,
  40 + state = "disabled",
40 41 text="Parameters:")
41 42 self.reconciliation_parameters_label.grid(row=0, column=0)
42 43 self.reconciliation_parameter_initial_block_size_label = Label(self.CASCADE_frame,
  44 + state = "disabled",
43 45 text="Initial block size (bits):")
44 46 self.reconciliation_parameter_initial_block_size_label.grid(row=0,
45 47 column=1)
46 48 self.reconciliation_parameter_initial_block_size_spinbox = Spinbox(self.CASCADE_frame,
47 49 values=(4, 8, 16, 32, 64),
48 50 width=3,
49   - state="normal")
  51 + state="disabled")
50 52 self.reconciliation_parameter_initial_block_size_spinbox.grid(row=0,
51 53 column=2)
52 54 self.reconciliation_parameter_number_of_passes_label=Label(self.CASCADE_frame,
  55 + state = "disabled",
53 56 text="Number of passes:")
54 57 self.reconciliation_parameter_number_of_passes_label.grid(row=1,
55 58 column=1,
56 59  
57 60  
58 61  
59 62  
60 63  
... ... @@ -58,33 +61,36 @@
58 61 from_=1,
59 62 to=25,
60 63 width=3,
61   - state="normal")
  64 + state="disabled")
62 65 self.reconciliation_parameter_number_of_passes_spinbox.grid(row=1,
63 66 column=2)
64 67 self.perform_reconciliation_button=Button(self.CASCADE_frame,
65 68 text="Perform reconciliation",
66   - state="normal",
  69 + state="disabled",
67 70 command=self.perform_reconciliation)
68 71 self.perform_reconciliation_button.grid(row=0,
69 72 column=3,
70 73 rowspan=2,
71 74 padx=10)
72 75 self.load_server_reference_response_label = Label(self.load_server_reference_response_frame,
  76 + state = "disabled",
73 77 text="Reference response on server:")
74 78 self.load_server_reference_response_label.pack(side=LEFT)
75 79 self.reference_response_label=Label(self.load_server_reference_response_frame,
76 80 textvariable=self.server_reference_response_displayed,
  81 + state = "disabled",
77 82 font=("Courier", 8),
78 83 background="white")
79 84 self.reference_response_label.pack(side=LEFT, padx=10, fill="x", expand="yes")
80 85 self.load_server_reference_response_button=Button(self.load_server_reference_response_frame,
  86 + state = "disabled",
81 87 text="Search...",
82 88 command=self.open_server_reference_response)
83 89 self.load_server_reference_response_button.pack(side=LEFT)
84 90 self.get_PUF_response_button=Button(self.get_PUF_response_frame,
85 91 text="Get PUF response",
86 92 command=self.get_PUF_response,
87   - state="normal")
  93 + state="disabled")
88 94 self.get_PUF_response_button.grid(row=0, column=0, sticky = "WE")
89 95 self.PUF_response_label=Label(self.get_PUF_response_frame,
90 96 textvariable=self.PUF_response_displayed,
... ... @@ -102,7 +108,7 @@
102 108 self.derive_key_button=Button(self.key_derivation_frame,
103 109 text="Derive a key from the response",
104 110 command=self.derive_key_from_response,
105   - state="normal")
  111 + state="disabled")
106 112 self.derive_key_button.pack(side=LEFT)
107 113 self.key_saved_label=Label(self.key_derivation_frame,
108 114 textvariable=self.message_key_saved)
109 115  
110 116  
... ... @@ -130,21 +136,21 @@
130 136 self.build_graph_button=Button(self.file_frame,
131 137 text="Build graph",
132 138 command=self.build_graph,
133   - state="disabled")
  139 + state="enabled")
134 140 self.build_graph_button.grid(row=2, column=0)
135 141 self.graph_info_label=Label(self.file_frame,
136 142 textvariable=self.graph_info)
137 143 self.graph_info_label.grid(row=2, column=1, sticky=W)
138 144 # -------------------------------------------------------
139   - self.locking_button=Checkbutton(self.modify_design_frame,
140   - text="Locking with",
141   - variable=self.locking,
142   - state="normal")
  145 + self.locking_button=Radiobutton(self.modify_design_frame,
  146 + text="Locking with",
  147 + variable=self.modify_design_mode,
  148 + value="locking")
143 149 self.locking_button.grid(row=0, column=0, sticky=W)
144   - self.masking_button=Checkbutton(self.modify_design_frame,
145   - text="Masking with",
146   - variable=self.masking,
147   - state="normal")
  150 + self.masking_button=Radiobutton(self.modify_design_frame,
  151 + text="Masking with",
  152 + variable=self.modify_design_mode,
  153 + value="masking")
148 154 self.masking_button.grid(row=1, column=0, sticky=W)
149 155 self.locking_overhead_spinbox=Spinbox(self.modify_design_frame,
150 156 from_=1,
... ... @@ -259,7 +265,7 @@
259 265 sticky=W)
260 266 self.save_associated_activation_word_simple_button=Button(self.generate_save_modified_design_frame,
261 267 text="Save associated Activation word",
262   - state="disabled",
  268 + state="enabled",
263 269 command=self.save_associated_AW,
264 270 width=32)
265 271 self.save_associated_activation_word_simple_button.grid(row=3,
... ... @@ -360,7 +366,8 @@
360 366  
361 367 # -------------------------------------------------------
362 368 self.activation_word_label = Label(self.activation_word_encryption_frame,
363   - text="Activation word:")
  369 + text="Activation word:",
  370 + state = "disabled")
364 371 self.activation_word_label.grid(sticky=E)
365 372 self.activation_word_display_label = Label(self.activation_word_encryption_frame,
366 373 textvariable=self.activation_word,
367 374  
368 375  
... ... @@ -369,14 +376,17 @@
369 376 self.activation_word_display_label.grid(row=0, column=1, sticky="EW", padx=10)
370 377 self.search_activation_word_button = Button(self.activation_word_encryption_frame,
371 378 text="Search...",
  379 + state = "disabled",
372 380 command=self.open_activation_word)
373 381 self.search_activation_word_button.grid(row=0, column=2)
374 382 self.encrypt_activation_word_button = Button(self.activation_word_encryption_frame,
375 383 text="Encrypt Activation word",
  384 + state = "disabled",
376 385 command = self.encrypt_activation_word)
377 386 self.encrypt_activation_word_button.grid(row=1)
378 387 self.start_activation_process_button = Button(self.activation_process_frame,
379 388 text="Start activation process",
  389 + state = "disabled",
380 390 command=self.start_activation_process)
381 391 self.start_activation_process_button.pack(side=LEFT)
... ... @@ -55,6 +55,8 @@
55 55  
56 56 from OTP.otp import otp
57 57  
  58 +from wrapper.generate_wrapper import generate_wrapper
  59 +
58 60 class App:
59 61  
60 62 """Main class for the demonstrator GUI app"""
61 63  
62 64  
... ... @@ -94,14 +96,14 @@
94 96 # Logic modifier frame
95 97 self.setState(self.modify_design_frame, state = "disabled")
96 98 self.setState(self.generate_save_modified_design_frame, state = "disabled")
97   - self.setState(self.wrap_modified_design_frame, state = "enabled")
  99 + self.setState(self.wrap_modified_design_frame, state = "disabled")
98 100 # Activation frame
99   - self.setState(self.CASCADE_frame, state = "disabled")
100   - self.setState(self.key_derivation_frame, state = "disabled")
101   - # self.setState(self.activation_word_encryption_frame, state = "disabled")
102   - # self.setState(self.activation_process_frame, state = "disabled")
  101 + # self.setState(self.CASCADE_frame, state = "enabled")
  102 + # self.setState(self.key_derivation_frame, state = "enabled")
  103 + # self.setState(self.activation_word_encryption_frame, state = "enabled")
  104 + # self.setState(self.activation_process_frame, state = "enabled")
103 105 # Enrolment frame
104   - self.setState(self.get_PUF_response_frame, state = "disabled")
  106 + # self.setState(self.get_PUF_response_frame, state = "enabled")
105 107  
106 108 def select_file(self):
107 109 self.update_status("")
... ... @@ -144,6 +146,7 @@
144 146  
145 147 def build_graph(self):
146 148 self.update_status("")
  149 + self.graph_info.set("")
147 150 self.update_status("Building the graph from file "+self.filename.get().split("/")[-1]+"...")
148 151 self.master.config(cursor="wait")
149 152 self.graph_info_label.configure(foreground="black")
... ... @@ -174,8 +177,8 @@
174 177 self.setState(self.modify_design_frame, state = "normal")
175 178 except:
176 179 self.update_status("Error in building the graph")
177   - self.setState(self.generate_save_modified_design_frame, state = "disabled")
178   - self.setState(self.wrap_modified_design_frame, state = "disabled")
  180 + # self.setState(self.generate_save_modified_design_frame, state = "enabled")
  181 + # self.setState(self.wrap_modified_design_frame, state = "enabled")
179 182 self.master.config(cursor="")
180 183 self.master.update()
181 184  
... ... @@ -208,6 +211,7 @@
208 211 self.update_status("The file could not be parsed as an Activation Word file")
209 212 else:
210 213 self.activation_word.set(line)
  214 + self.encrypt_activation_word_button.configure(state = "enabled")
211 215  
212 216 def open_associated_activation_word(self):
213 217 self.update_status("")
... ... @@ -242,6 +246,8 @@
242 246 else:
243 247 self.PUF_response = list(reversed(response_converter_to_bin_list(temp_hex_response)))
244 248 self.PUF_response_displayed.set(response_converter_to_hex(self.PUF_response))
  249 + self.PUF_response_label.configure(state = "enabled")
  250 + self.save_as_reference_response_button.configure(state = "enabled")
245 251  
246 252 def save_as_reference_response(self):
247 253 self.update_status("")
... ... @@ -306,7 +312,9 @@
306 312 self.board_status.set("Board Connected")
307 313 self.board_status_label.configure(foreground="darkgreen")
308 314 self.update_status("")
309   - self.setState(self.get_PUF_response_frame, state = "normal")
  315 + self.get_PUF_response_button.configure(state="enabled")
  316 + self.load_server_reference_response_button.configure(state="enabled")
  317 + self.setState(self.load_server_reference_response_frame, state = "enabled")
310 318  
311 319 def disconnect(self):
312 320 self.update_status("")
313 321  
... ... @@ -318,11 +326,10 @@
318 326 self.connected.set(False)
319 327 self.board_status.set("Board not connected")
320 328 self.board_status_label.configure(foreground="red")
321   - self.setState(self.CASCADE_frame, state = "disabled")
322   - self.setState(self.key_derivation_frame, state = "disabled")
323   - self.setState(self.activation_word_encryption_frame, state = "disabled")
324   - self.setState(self.activation_process_frame, state = "disabled")
325 329 self.setState(self.get_PUF_response_frame, state = "disabled")
  330 + self.setState(self.tab_activation, state = "disabled")
  331 + self.server_reference_response_displayed.set("")
  332 + self.activation_word.set("")
326 333 except:
327 334 pass
328 335  
... ... @@ -336,24 +343,15 @@
336 343 self.master.update()
337 344 self.locking_inputs = []
338 345 self.masking_inputs = []
339   -
340   - if self.locking.get():
341   - self.graph_modified, self.unlocking_word, self.locking_inputs, list_nodes_to_lock = locking(self.g,
342   - self.prim_in,
343   - self.prim_out,
344   - self.nodes,
345   - self.locking_overhead.get())
346   - if self.masking.get():
347   - self.graph_modified, self.unmasking_word, self.masking_inputs = masking(self.graph_modified,
348   - self.prim_in,
349   - self.prim_out,
350   - self.nodes,
351   - self.locking_overhead.get(),
352   - self.masking_heuristic.get(),
353   - list_nodes_to_lock)
354   - if [i for i in self.locking_inputs if i in self.masking_inputs]:
355   - raise ValueError("Some nodes will be masked and locked")
356   - elif self.masking.get():
  346 +
  347 + message = "" # Locking message, in case the overhead is too low to allow for total locking
  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())
  354 + elif self.modify_design_mode.get() == "masking":
357 355 self.graph_modified, self.unmasking_word, self.masking_inputs = masking(self.g,
358 356 self.prim_in,
359 357 self.prim_out,
... ... @@ -361,9 +359,12 @@
361 359 self.masking_overhead.get(),
362 360 self.masking_heuristic.get())
363 361 self.setState(self.generate_save_modified_design_frame, state = "normal")
364   - self.save_associated_activation_word_simple_button.configure(state = "disabled")
365   - self.setState(self.modify_design_frame, state = "disabled")
366   - self.update_status("Modifications done")
  362 + self.save_associated_activation_word_simple_button.configure(state = "enabled")
  363 + self.setState(self.modify_design_frame, state = "enabled")
  364 + if message:
  365 + self.update_status("Modifications done but "+message)
  366 + else:
  367 + self.update_status("Modifications done")
367 368 self.master.config(cursor="")
368 369 self.master.update()
369 370  
370 371  
... ... @@ -397,9 +398,9 @@
397 398 filename = ".".join(filename)
398 399 filename = "/".join(self.filename.get().split("/")[:-1])+"/"+filename
399 400 convert_back_bench(self.graph_modified, filename)
400   - self.update_status(str("Modified design saved under "+filename))
  401 + self.update_status(str("Modified design saved under ./user_space/"+filename.split("/")[-1]))
401 402 self.save_associated_activation_word_simple_button.configure(state = "normal")
402   - self.generate_modified_design_button.configure(state = "disabled")
  403 + self.generate_modified_design_button.configure(state = "enabled")
403 404  
404 405 def save_associated_AW(self):
405 406 self.update_status("")
406 407  
... ... @@ -411,11 +412,11 @@
411 412 filename = "/".join(self.filename.get().split("/")[:-1])+"/"+filename
412 413 with open(filename, "w") as aw_file:
413 414 aw_file.write("Unlocking word concatenated with unmasking word\n"+self.unlocking_word+" "+self.unmasking_word)
414   - self.update_status(str("Associated activation word saved under "+filename))
  415 + self.update_status(str("Associated activation word saved under ./user_space/"+filename.split("/")[-1]))
415 416 self.setState(self.wrap_modified_design_frame, state = "normal")
416 417 self.select_crypto_PRESENT.configure(state = "disabled")
417 418 self.select_key_derivation_blake2.configure(state = "disabled")
418   - self.setState(self.generate_save_modified_design_frame, state = "disabled")
  419 + self.setState(self.generate_save_modified_design_frame, state = "enabled")
419 420  
420 421  
421 422 def save_formatted_AW(self):
... ... @@ -453,7 +454,7 @@
453 454 elif len(self.associated_activation_word.get().split(" ")) == 2:
454 455 masking = True
455 456 locking = True
456   - try:
  457 + try: #Generate AW
457 458 print self.associated_activation_word.get()
458 459 self.formatted_AW = gen_AW_decoder(self.associated_activation_word.get(),
459 460 128, #128-bit responses
460 461  
461 462  
... ... @@ -462,15 +463,23 @@
462 463 path = "./user_space/")
463 464 except:
464 465 self.update_status("An error occured while generating the AW decoder")
465   - try:
  466 + try: #Generate activable design
466 467 generate_activable_design("./user_space/"+self.filename.get().split("/")[-1].split(".")[0]+"_mod.vhd",
467   - "./user_space/AW_decoder.vhd",
468   - (locking, self.locking_inputs),
469   - (masking, self.masking_inputs))
470   - self.update_status("Activable design generated")
  468 + "./user_space/AW_decoder.vhd",
  469 + (locking, self.locking_inputs),
  470 + (masking, self.masking_inputs))
471 471 except Exception as e:
472 472 print e
473 473 self.update_status("An error occured while generating the activable design")
  474 + try: #Generate wrapped design
  475 + generate_wrapper("./user_space/"+self.filename.get().split("/")[-1].split(".")[0]+"_activable.vhd",
  476 + "./wrapper/ref_design.vhd",
  477 + "db_top_inst",
  478 + "./user_space/db_top_inst.vhd")
  479 + self.update_status("Wrapped design generated successfully and saved under user_space/db_top_inst.vhd")
  480 + except Exception as e:
  481 + print e
  482 + self.update_status("An error occured while generating the wrapped design")
474 483 self.master.config(cursor="")
475 484 self.master.update()
476 485  
... ... @@ -490,6 +499,8 @@
490 499 server_after = self.server_reference_response
491 500 print "Errors corrected :", [a for (a, (b, c)) in enumerate(zip(server_before, server_after)) if b != c]
492 501 self.update_status("Reconciliation done, "+str(leakage)+" bits leaked", color="darkgreen")
  502 + self.setState(self.activation_word_encryption_frame, state = "enabled")
  503 + self.encrypt_activation_word_button.configure(state = "disabled")
493 504 else:
494 505 self.update_status("Reconciliation failed, too much leakage. Try with other parameters.", color="red")
495 506  
496 507  
... ... @@ -500,10 +511,12 @@
500 511 encrypted_AW_file_name = self.activation_word_file.replace("formatted", "encrypted")
501 512 with open(encrypted_AW_file_name, "w") as encrypted_AW_file:
502 513 encrypted_AW_file.write(self.encrypted_AW)
503   - self.update_status("Encrypted AW saved under "+encrypted_AW_file_name)
  514 + self.update_status("Encrypted AW saved under ./user_space/"+encrypted_AW_file_name.split("/")[-1])
  515 + self.setState(self.activation_process_frame, state = "enabled")
  516 +
504 517 def start_activation_process(self):
505   - print self.encrypted_AW
506   - print self.tcl_obj.eval(self.board_manager.activate_design(self.encrypted_AW))
  518 + # print self.encrypted_AW
  519 + # print self.tcl_obj.eval(self.board_manager.activate_design(self.encrypted_AW))
507 520 self.update_status("Activation done", color="darkgreen")
508 521  
509 522 def update_status(self, text, color = "black"):
510 523  
511 524  
512 525  
... ... @@ -517,18 +530,18 @@
517 530 def reset(self):
518 531 declare_initialize_variables(self)
519 532 self.update_status("")
520   - self.setState(self.modify_design_frame, state = "disabled")
521   - self.setState(self.generate_save_modified_design_frame, state = "disabled")
522   - self.setState(self.wrap_modified_design_frame, state = "disabled")
  533 + self.setState(self.modify_design_frame, state = "enabled")
  534 + self.setState(self.generate_save_modified_design_frame, state = "enabled")
  535 + self.setState(self.wrap_modified_design_frame, state = "enabled")
523 536 # Activation frame
524   - self.setState(self.CASCADE_frame, state = "disabled")
525   - self.setState(self.key_derivation_frame, state = "disabled")
526   - self.setState(self.activation_word_encryption_frame, state = "disabled")
527   - self.setState(self.activation_process_frame, state = "disabled")
  537 + self.setState(self.CASCADE_frame, state = "enabled")
  538 + self.setState(self.key_derivation_frame, state = "enabled")
  539 + self.setState(self.activation_word_encryption_frame, state = "enabled")
  540 + self.setState(self.activation_process_frame, state = "enabled")
528 541 # Enrolment frame
529   - self.setState(self.get_PUF_response_frame, state = "disabled")
  542 + self.setState(self.get_PUF_response_frame, state = "enabled")
530 543  
531   - def setState(self, widget, state='disabled'):
  544 + def setState(self, widget, state='enabled'):
532 545 try:
533 546 widget.configure(state=state)
534 547 except TclError:
boards_management/board_commands.py.back View file @ 48a1b0a
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())
build_menu.py View file @ 48a1b0a
... ... @@ -17,7 +17,7 @@
17 17 self.menubar = Menu(self.master)
18 18  
19 19 self.filemenu = Menu(self.menubar, tearoff=0)
20   - self.filemenu.add_command(label="Reset", command=self.reset)
  20 + # self.filemenu.add_command(label="Reset", command=self.reset)
21 21 self.filemenu.add_command(label="Exit", command=self.master.quit)
22 22 self.menubar.add_cascade(label="File", menu=self.filemenu)
23 23  
declare_initialize_variables.py View file @ 48a1b0a
... ... @@ -14,8 +14,7 @@
14 14  
15 15 """Declare and initialize the GUI variables"""
16 16  
17   - self.masking = BooleanVar()
18   - self.locking = BooleanVar()
  17 + self.modify_design_mode = StringVar() # Masking or locking
19 18 self.daughter_board = StringVar()
20 19 self.daughter_board.set("S6")
21 20 self.PUF_response_displayed = StringVar()
... ... @@ -26,7 +25,7 @@
26 25 self.modified_design_to_wrap = StringVar()
27 26 self.modified_design_to_wrap.set("No design loaded")
28 27 self.com_port = StringVar()
29   - self.com_port.set("COM6")
  28 + self.com_port.set("COM5")
30 29 self.masking_overhead = IntVar()
31 30 self.masking_overhead.set(5)
32 31 self.locking_overhead = IntVar()
locking/locking.py View file @ 48a1b0a
... ... @@ -11,6 +11,7 @@
11 11 import find_optimal_nodes
12 12 import label_undefined_nodes
13 13 import modify_nodes_lock
  14 +import math
14 15  
15 16 # import sys
16 17 # sys.path.append("../parsers/")
17 18  
18 19  
... ... @@ -37,22 +38,21 @@
37 38 list_nodes_to_lock = [list(elem) for elem in list_nodes_to_lock]
38 39  
39 40 g, list_nodes_to_lock = label_undefined_nodes.label_undefined_nodes(g, list_nodes_to_lock)
  41 +
  42 + message = ""
  43 +
  44 + if len(list_nodes_to_lock) > (float(overhead)/100) * len(nodes):
  45 + message = "the overhead is too low to allow total locking, some outputs will remain unaltered."
  46 + list_nodes_to_lock = list_nodes_to_lock[:int(math.floor(float(overhead)*len(nodes)/100))]
40 47 locking_key = str(list(reversed(sum(list(zip(*list_nodes_to_lock)[1]),[]))))[1:-1].replace(", ","")
41 48  
42   - print "nodes:", len(nodes)
43   - print "nodes to lock:", len(list_nodes_to_lock)
44   -
45   - if len(list_nodes_to_lock) > (float(overhead)/100) * len(nodes):
46   - print "Overhead is too low to allow total locking"
47   - print "some outputs will remain unaltered."
48   - print len(list_nodes_to_lock)
49   - print float(overhead)*len(nodes)/100
50   - list_nodes_to_lock = list_nodes_to_lock[:overhead * len(nodes)]
  49 + # print "nodes:", len(nodes)
  50 + # print "nodes to lock:", len(list_nodes_to_lock)
51 51 h, locking_inputs = modify_nodes_lock.modify_nodes_lock(h, list_nodes_to_lock)
52 52  
53   - if len(locking_key) != len(list_nodes_to_lock):
54   - raise Exception("Undefined V_locks, cannot generate the modified netlist.")
55   - return h, locking_key, locking_inputs, list_nodes_to_lock
  53 + # if len(locking_key) != len(list_nodes_to_lock):
  54 + # raise Exception("Undefined V_locks, cannot generate the modified netlist.")
  55 + return h, locking_key, locking_inputs, list_nodes_to_lock, message
56 56  
57 57 if __name__ == "__main__":
58 58 for name in ["c432"]:
wrapper/generate_wrapper.py View file @ 48a1b0a
... ... @@ -8,12 +8,12 @@
8 8  
9 9 inputs = []
10 10 outputs = []
11   - input_vectors = []
12   - output_vectors = []
13 11  
14 12 with open(design_to_wrap, "r") as design_to_wrap_file:
15 13 no_entity_found = True
16 14 for line in design_to_wrap_file:
  15 + if "ARCHITECTURE" in line:
  16 + break #ENTITY is finished
17 17 if no_entity_found:
18 18 if "ENTITY" in line.upper():
19 19 entity_name = line.split("ENTITY")[1].split("IS")[0].strip()
20 20  
21 21  
22 22  
23 23  
24 24  
25 25  
26 26  
... ... @@ -22,42 +22,92 @@
22 22 if "VECTOR" in line.upper():
23 23 vector_range = re.search('\([0-9]* DOWNTO [0-9]*\)', line.upper()).group(0)[1:-1].replace(" ", "").split("DOWNTO")
24 24 if "IN " in line.upper():
25   - input_vectors.append([line.split(":")[0], vector_range])
  25 + inputs.append([line.split(":")[0], vector_range])
26 26 elif "OUT " in line.upper():
27   - output_vectors.append([line.split(":")[0], vector_range])
  27 + outputs.append([line.split(":")[0], vector_range])
28 28 else:
29 29 if "IN " in line.upper():
30 30 if "," in line.split(":")[0]:
31   - inputs.extend(line.split(":")[0].split(","))
  31 + inputs.extend([[i, 0] for i in line.split(":")[0].split(",")])
32 32 else:
33   - inputs.append(line.split(":")[0])
  33 + inputs.append([line.split(":")[0], 0])
34 34 elif "OUT " in line.upper():
35 35 if "," in line.split(":")[0]:
36   - outputs.extend(line.split(":")[0].split(","))
  36 + outputs.extend([[i, 0] for i in line.split(":")[0].split(",")])
37 37 else:
38   - outputs.append(line.split(":")[0])
39   - inputs = [i.strip() for i in inputs]
40   - outputs = [i.strip() for i in outputs]
41   - input_vectors = [[i[0].strip(), i[1]] for i in input_vectors]
42   - output_vectors = [[i[0].strip(), i[1]] for i in output_vectors]
43   - return entity_name, inputs, outputs, input_vectors, output_vectors
  38 + outputs.append([line.split(":")[0], 0])
  39 + inputs = [[i[0].strip(), i[1]] for i in inputs]
  40 + outputs = [[i[0].strip(), i[1]] for i in outputs]
  41 + return entity_name, inputs, outputs
44 42  
45 43 def generate_wrapper(design_to_wrap, ref_design_file_name, wrapped_design_name, target_file_name):
46 44  
47 45 """Wrapps a vhd design in a SALWARE wrapper"""
48 46  
49   - entity_name, inputs, outputs, input_vectors, output_vectors = identify_interface_signals(design_to_wrap)
50   - print inputs
51   - print outputs
52   - print input_vectors
53   - print output_vectors
  47 + entity_name, inputs, outputs = identify_interface_signals(design_to_wrap)
  48 +
  49 + available_inputs = 1024
  50 + available_outputs = 1024
  51 + current_input_index = 0
  52 + current_output_index = 0
  53 +
  54 + output_width = sum([1 for i in outputs if i[1] == 0])
  55 + all_ranges = [i[1] for i in outputs if type(i[1]) is list]
  56 + output_width += sum([abs(int(a) - int(b))+1 for [a, b] in all_ranges])
  57 + if output_width > 128:
  58 + raise ValueError("Cannot output more than 128 bits")
  59 +
54 60  
55 61 with open(ref_design_file_name, "r") as ref_design_file, open(target_file_name, "w") as target_file:
56 62 for line in ref_design_file:
57   - if "$$COMB_DATA_OUT$$" in line:
58   - print line
59   - elif "$$COMB_DATA_IN$$" in line:
60   - print line
  63 + if "$$COMB_DATA_IN$$" in line:
  64 + for i in inputs:
  65 + if i[1] == 0: #1-bit input
  66 + target_file.write(" "+i[0]+" => Data_to_DB("+str(current_input_index)+"),\n")
  67 + current_input_index += 1
  68 + if current_input_index > available_inputs:
  69 + raise ValueError("I cannot handle so many inputs! There are more than "+str(available_inputs)+" of them!")
  70 + elif type(i[1]) is list: #n-bit input
  71 + if i[0] == "key":
  72 + target_file.write(" key => key,\n")
  73 + else:
  74 + range = abs(int(i[1][1]) - int(i[1][0]))
  75 + target_file.write(" "+i[0]+" => Data_to_DB("+
  76 + str(current_input_index + range)+
  77 + " DOWNTO "+
  78 + str(current_input_index)+"),\n")
  79 + current_input_index += range+1
  80 + if current_input_index > available_inputs:
  81 + raise ValueError("I cannot handle so many inputs! There are more than "+str(available_inputs)+" of them!")
  82 + elif "$$COMB_DATA_OUT$$" in line:
  83 + for i in outputs:
  84 + if i[1] == 0: #1-bit output
  85 + if i == outputs[-1]: #last output
  86 + target_file.write(" "+i[0]+" => comb_out("+str(current_output_index)+"));\n")
  87 + else:
  88 + target_file.write(" "+i[0]+" => comb_out("+str(current_output_index)+"),\n")
  89 + current_output_index += 1
  90 + if current_output_index > available_outputs:
  91 + raise ValueError("I cannot handle so many outputs! There are more than "+str(available_outputs)+" of them!")
  92 + elif type(i[1]) is list: #n-bit output
  93 + range = abs(int(i[1][1]) - int(i[1][0]))
  94 + if i == outputs[-1]: #last output
  95 + target_file.write(" "+i[0]+" => comb_out("+
  96 + str(current_output_index + range)+
  97 + " DOWNTO "+
  98 + str(current_output_index)+"));\n")
  99 + else:
  100 + target_file.write(" "+i[0]+" => comb_out("+
  101 + str(current_output_index + range)+
  102 + " DOWNTO "+
  103 + str(current_output_index)+"),\n")
  104 + current_output_index += range+1
  105 + if current_output_index > available_outputs:
  106 + raise ValueError("I cannot handle so many outputs! There are more than "+str(available_outputs)+" of them!")
  107 + elif "$$COMB_OUT_WIDTH$$" in line:
  108 + target_file.write(line.replace("$$COMB_OUT_WIDTH$$", str(output_width-1)))
  109 + elif "$$PADDED_COMB_OUT$$" in line:
  110 + target_file.write(line.replace("$$PADDED_COMB_OUT$$", "\""+(128-output_width)*"0"+"\" & comb_out"))
61 111 elif "$$ENTITY_NAME$$" in line:
62 112 target_file.write(line.replace("$$ENTITY_NAME$$", entity_name))
63 113 elif "$$WRAPPED_DESIGN_NAME$$" in line:
... ... @@ -67,5 +117,8 @@
67 117  
68 118  
69 119 if __name__ == "__main__":
70   - generate_wrapper("multiplier.vhd", "ref_design.vhd", "top", "top.vhd")
  120 + # generate_wrapper("test.vhd", "ref_design.vhd", "top", "top.vhd")
  121 + # generate_wrapper("c432_activable.vhd", "ref_design.vhd", "top", "top.vhd")
  122 + # generate_wrapper("multiplier.vhd", "ref_design.vhd", "top", "top.vhd")
  123 + generate_wrapper("multiplier_activable.vhd", "ref_design.vhd", "top", "top.vhd")