Commit 4a3e457aa3ca5034f48b4da734f888c1160c0c69

Authored by Brice Colombier
1 parent 7f5b270cd1
Exists in master

GUI front-end done, back-end to do

Showing 9 changed files with 276 additions and 209 deletions

GUI/add_frame_elements.py View file @ 4a3e457
... ... @@ -199,22 +199,49 @@
199 199 # -------------------------------------------------------
200 200 self.generate_modified_design_button=Button(self.generate_modified_design_frame,
201 201 text="Generate modified design",
202   - state="normal")
203   - self.generate_modified_design_button.pack(side=LEFT)
  202 + state="normal",
  203 + width=29)
  204 + self.generate_modified_design_button.grid(row=0,
  205 + column=0,
  206 + sticky=W)
  207 + self.save_associated_activation_word_button=Button(self.generate_modified_design_frame,
  208 + text="Save associated Activation word",
  209 + state="normal",
  210 + width=29)
  211 + self.save_associated_activation_word_button.grid(row=1,
  212 + column=0,
  213 + sticky=W)
204 214 # -------------------------------------------------------
205 215 self.label_program=Label(self.program_daughterboard_frame,
206 216 text="Bitstream:")
207   - self.label_program.pack(side=LEFT)
  217 + self.label_program.grid(row=0,column=0,sticky=E)
208 218 self.bitstream_entry = Entry(self.program_daughterboard_frame,
209   - textvariable=self.bitstream)
210   - self.bitstream_entry.pack(side=LEFT,
211   - expand="yes",
212   - fill="x")
  219 + textvariable=self.bitstream,
  220 + width=81)
  221 + self.bitstream_entry.grid(row=0,column=1)
213 222 self.search_bitstream_button=Button(self.program_daughterboard_frame,
214 223 text="Search...",
215 224 command=self.open_bitstream_file)
216   - self.search_bitstream_button.pack(side=LEFT)
  225 + self.search_bitstream_button.grid(row=0,column=2)
217 226 self.program_daughterboard_button=Button(self.program_daughterboard_frame,
218 227 text="Program HECTOR daughterboard")
219   - self.program_daughterboard_button.pack(side=LEFT)
  228 + self.program_daughterboard_button.grid(row=1, column=0)
  229 + # -------------------------------------------------------
  230 + self.activation_word_label = Label(self.activation_word_encryption_frame,
  231 + text="Activation word:")
  232 + self.activation_word_label.grid(sticky=E)
  233 + self.activation_word_entry = Entry(self.activation_word_encryption_frame,
  234 + textvariable=self.activation_word,
  235 + width=90)
  236 + self.activation_word_entry.grid(row=0, column=1)
  237 + self.search_activation_word_button = Button(self.activation_word_encryption_frame,
  238 + text="Search",
  239 + command=self.open_activation_word)
  240 + self.search_activation_word_button.grid(row=0, column=2)
  241 + self.encrypt_activation_word_button = Button(self.activation_word_encryption_frame,
  242 + text="Encrypt Activation word")
  243 + self.encrypt_activation_word_button.grid(row=1)
  244 + self.start_activation_process_button = Button(self.activation_process_frame,
  245 + text="Start activation process")
  246 + self.start_activation_process_button.pack(side=LEFT)
  1 +# -*- coding: utf-8 -*-
  2 +
  3 +# Author: Brice Colombier
  4 +# Laboratoire Hubert Curien
  5 +# 42000 Saint-Etienne - France
  6 +# Contact: b.colombier@univ-st-etienne.fr
  7 +# Project: Demonstrator
  8 +# File: app.py
  9 +# Date: 2016-10-13
  10 +import random
  11 +import sys
  12 +
  13 +import tkFileDialog
  14 +from Tkinter import *
  15 +from ttk import *
  16 +
  17 +import add_frame_elements
  18 +import build_menu
  19 +import build_tabs
  20 +import declare_initialize_variables
  21 +import declare_pack_frames
  22 +import status_bar
  23 +
  24 +
  25 +sys.path.extend(["../Masking/",
  26 + "../Locking/",
  27 + "../Key_derivation"])
  28 +import blake2
  29 +import locking
  30 +import masking
  31 +
  32 +
  33 +class App:
  34 +
  35 + """Main class for the demonstrator GUI app"""
  36 +
  37 + def __init__(self, master):
  38 +
  39 + master.maxsize(width=770, height=280)
  40 + master.minsize(width=770, height=280)
  41 + master.resizable(width=False, height=False)
  42 + master.title("SALWARE IP protection tool")
  43 + master.iconbitmap(default='./contents/icon.ico')
  44 +
  45 + # Tabs
  46 + build_tabs.build_tabs(self, master)
  47 +
  48 + # Menu bar
  49 + build_menu.build_menu(self, master)
  50 +
  51 + # Variables
  52 + declare_initialize_variables.declare_initialize_variables(self)
  53 +
  54 + # Frames
  55 + declare_pack_frames.declare_pack_frames(self)
  56 +
  57 + # Frame elements
  58 + add_frame_elements.add_frame_elements(self)
  59 +
  60 + # Status bar
  61 + status_bar.status_bar(self, master)
  62 +
  63 +
  64 + def open_file(self):
  65 +
  66 + ftypes = [("BENCH files", ".txt"),
  67 + ("BLIF files", ".blif"),
  68 + ("SLIF files", ".slif"),
  69 + ("EDIF files", ".edf"),
  70 + ("Xilinx EDIF files", ".edf"),
  71 + ("RTL VHDL files", ".vhd"),
  72 + ("Structural VHDL files", ".vhd"),
  73 + ("RTL Verilog files", ".v"),
  74 + ("Structural Verilog files", ".v")]
  75 + self.filepath.set(tkFileDialog.askopenfilename(filetypes=ftypes))
  76 + if self.filepath.get():
  77 + self.filename.set(self.filepath.get().split("/")[-1])
  78 +
  79 + def open_bitstream_file(self):
  80 + btypes = [("Xilinx bitstream", ".bit")]
  81 + self.bitstream.set(tkFileDialog.askopenfilename(filetypes=btypes))
  82 +
  83 + def open_activation_word(self):
  84 + ttypes = [("Activation word", ".txt")]
  85 + self.activation_word.set(tkFileDialog.askopenfilename(filetypes=ttypes))
  86 +
  87 + def round_masking(self, _): # Dummy second argument
  88 + self.masking_overhead.set(int(round(self.masking_overhead.get())))
  89 +
  90 + def round_locking(self, _): # Dummy second argument
  91 + self.locking_overhead.set(int(round(self.locking_overhead.get())))
  92 +
  93 + def get_PUF_reference_response(self):
  94 + self.PUF_reference_response = ''.join(random.SystemRandom().choice(["0", "1"]) for _ in range(256))
  95 + self.PUF_reference_response_displayed.set(hex(int(self.PUF_reference_response, 2))[2:-1])
  96 +
  97 + # To be continued
  98 + self.reconciliation_performed.set(False)
  99 + self.reference_response_available.set(True)
  100 + self.message_key_saved.set("")
  101 +
  102 + def check_reference_response_available(self, a, b, c): # a, b, c dummy variables
  103 + if self.reference_response_available.get():
  104 + self.perform_reconciliation_button.configure(state="normal")
  105 + self.reconciliation_parameter_initial_block_size_spinbox.configure(state="normal")
  106 + self.reconciliation_parameter_number_of_passes_spinbox.configure(state="normal")
  107 + self.derive_key_button.configure(state="normal")
  108 +
  109 + def perform_reconciliation(self):
  110 + # To be continued
  111 + self.reconciliation_performed.set(True)
  112 +
  113 + def check_reconciliation_performed(self, a, b, c):
  114 + if self.reconciliation_performed.get():
  115 + self.masking_button.configure(state="normal")
  116 + self.locking_button.configure(state="normal")
  117 + self.masking_overhead_spinbox.configure(state="normal")
  118 + self.locking_overhead_spinbox.configure(state="normal")
  119 + self.modify_design_button.configure(state="normal")
  120 + else:
  121 + self.masking_button.configure(state="disabled")
  122 + self.locking_button.configure(state="disabled")
  123 + self.masking_overhead_spinbox.configure(state="disabled")
  124 + self.locking_overhead_spinbox.configure(state="disabled")
  125 + self.modify_design_button.configure(state="disabled")
  126 +
  127 + def pop_up_about(self):
  128 + self.top = Toplevel(background="White")
  129 + self.top.title("About")
  130 +
  131 + self.msg = Label(self.top, text="This software was realised in the frame of\n\
  132 +the SALWARE project number ANR-13-JS03-0003\n\
  133 +supported by the French \"Agence Nationale de\n\
  134 +la Recherche\" and by the French \"Fondation de\n\
  135 +Recherche pour l'Aéronautique et l'Espace\",\n\
  136 +funding for this project was also provided by\n\
  137 +a grant from \"La Région Rhône-Alpes\".", background="white")
  138 + self.msg.pack()
  139 + self.salware_logo = PhotoImage(file="./contents/Logo_SALWARE.gif")
  140 +
  141 + self.label_salware_logo = Label(self.top,
  142 + image=self.salware_logo,
  143 + background="white")
  144 + self.label_salware_logo.image = self.salware_logo # keep a reference!
  145 + self.label_salware_logo.pack()
  146 + self.logo_RA = PhotoImage(file="./contents/Logo_RA.gif")
  147 + self.label_logo_RA = Label(self.top,
  148 + image=self.logo_RA,
  149 + background="white")
  150 + self.label_logo_RA.image = self.logo_RA # keep a reference!
  151 + self.label_logo_RA.pack()
  152 +
  153 + def pop_up_license(self):
  154 + self.top = Toplevel()
  155 + self.top.title("License")
  156 + try:
  157 + self.License_file = open("LICENSE.txt", 'r')
  158 + self.License_text = self.License_file.read()
  159 + self.License_file.close()
  160 + except:
  161 + self.License_text = "Cannot find LICENSE.txt"
  162 + self.msg = Label(self.top,
  163 + text=self.License_text,
  164 + background="white")
  165 + self.msg.pack()
  166 +
  167 + def connect(self):
  168 + self.com_port_button_connect.configure(state=DISABLED)
  169 + self.com_port_button_disconnect.configure(state=NORMAL)
  170 + self.connected.set(True)
  171 + self.com_port_status_text.configure(text="Connected",
  172 + foreground="darkgreen")
  173 +
  174 + def disconnect(self):
  175 + self.com_port_button_disconnect.configure(state=DISABLED)
  176 + self.com_port_button_connect.configure(state=NORMAL)
  177 + self.connected.set(False)
  178 + self.com_port_status_text.configure(text="Disconnected",
  179 + foreground="red")
  180 +
  181 + def modify_design(self, g, prim_in, prim_out, nodes):
  182 + if self.locking.get():
  183 + locking.locking(g, prim_in, prim_out, nodes, self.locking_overhead)
  184 + if self.masking.get():
  185 + masking.masking(g, prim_in, prim_out, nodes, self.masking_overhead, self.masking_heuristic)
  186 +
  187 + def derive_key_from_response(self):
  188 + self.salt = bytes(''.join(random.SystemRandom().choice(["0", "1"]) for _ in range(32)))
  189 + PRK_f = blake2.BLAKE2s(digest_size=32, key=self.salt)
  190 + PRK_f.update(self.PUF_reference_response)
  191 + self.key = ''.join('{0:08b}'.format(ord(x), 'b') for x in PRK_f.final()).replace("0b", "")
  192 + key_file_name = "./../User_space/key_"+""+".txt"
  193 + with open(key_file_name, "w") as key_file:
  194 + key_file.write("Salt = "+self.salt+"\n")
  195 + key_file.write("Key = "+self.key)
  196 + self.message_key_saved.set("Key saved under "+key_file_name)
  197 +
  198 +def every_second():
  199 + # To be filled
  200 + fenetre.after(1000, every_second)
  201 +
  202 +if __name__ == "__main__":
  203 +
  204 + fenetre = Tk()
  205 +
  206 + app = App(fenetre)
  207 +
  208 + fenetre.after(1000, every_second)
  209 + fenetre.mainloop()
GUI/build_tabs.py View file @ 4a3e457
  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: build_tabs.py
  7 +# Date: 2016-10-24
  8 +
1 9 from Tkinter import *
2 10 from ttk import *
3 11  
4 12  
5 13 def build_tabs(self, master):
6   - self.note = Notebook(master, width = 762)
  14 +
  15 + """Insert tabs"""
  16 +
  17 + self.note = Notebook(master, width = 764)
7 18 self.tab_logic_modifier = Frame(self.note)
8 19 self.note.add(self.tab_logic_modifier,
9 20 text="Logic modifier",
GUI/contents/Logo_RA.gif View file @ 4a3e457

1.11 KB

GUI/declare_initialize_variables.py View file @ 4a3e457
... ... @@ -50,4 +50,6 @@
50 50  
51 51 self.bitstream = StringVar()
52 52 self.bitstream.set("./../User_space/design.bit")
  53 + self.activation_word = StringVar()
  54 + self.activation_word.set("")
GUI/declare_pack_frames.py View file @ 4a3e457
... ... @@ -52,4 +52,10 @@
52 52 self.CASCADE_frame = LabelFrame(self.tab_activation,
53 53 text="CASCADE protocol")
54 54 self.CASCADE_frame.pack(fill="x")
  55 + self.activation_word_encryption_frame = LabelFrame(self.tab_activation,
  56 + text="Activation word encryption")
  57 + self.activation_word_encryption_frame.pack(fill="x")
  58 + self.activation_process_frame = LabelFrame(self.tab_activation,
  59 + text="Activation process")
  60 + self.activation_process_frame.pack(fill="x")
GUI/status_bar.py View file @ 4a3e457
  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: status_bar.py
  7 +# Date: 2016-10-24
  8 +
1 9 from Tkinter import *
2 10 from ttk import *
3 11  
4 12  
5 13 def status_bar(self, master):
  14 +
  15 + """Insert a status bar"""
6 16  
7 17 self.status_bar_frame = Frame(master, borderwidth=1, relief="ridge")
8 18 self.status_bar_frame.pack(side="bottom",fill="x")
GUI/tabbed_app.py View file @ 4a3e457
1   -# -*- coding: utf-8 -*-
2   -
3   -# Author: Brice Colombier
4   -# Laboratoire Hubert Curien
5   -# 42000 Saint-Etienne - France
6   -# Contact: b.colombier@univ-st-etienne.fr
7   -# Project: Demonstrator
8   -# File: app.py
9   -# Date: 2016-10-13
10   -
11   -from Tkinter import *
12   -from ttk import *
13   -import tkFileDialog
14   -import random
15   -
16   -import build_menu
17   -import declare_initialize_variables
18   -import declare_pack_frames
19   -import add_frame_elements
20   -import build_tabs
21   -import status_bar
22   -
23   -
24   -import sys
25   -sys.path.append("../Masking/")
26   -import masking
27   -sys.path.append("../Locking/")
28   -import locking
29   -sys.path.append("../Key_derivation/")
30   -import blake2
31   -
32   -
33   -
34   -class App:
35   -
36   - """Main class for the demonstrator GUI app"""
37   -
38   - def __init__(self, master):
39   -
40   - master.maxsize(width=770, height=280)
41   - master.minsize(width=770, height=280)
42   - master.resizable(width=False, height=False)
43   - master.title("SALWARE IP protection tool")
44   - master.iconbitmap(default='./contents/icon.ico')
45   -
46   - # Tabs and status bar
47   - build_tabs.build_tabs(self, master)
48   -
49   - # Menu bar
50   - build_menu.build_menu(self, master)
51   -
52   - # Variables
53   - declare_initialize_variables.declare_initialize_variables(self)
54   -
55   - # Frames
56   - declare_pack_frames.declare_pack_frames(self)
57   -
58   - # Frame elements
59   - add_frame_elements.add_frame_elements(self)
60   -
61   - # Status bar
62   - status_bar.status_bar(self, master)
63   -
64   -
65   - def open_file(self):
66   -
67   - ftypes = [("BENCH files", ".txt"),
68   - ("BLIF files", ".blif"),
69   - ("SLIF files", ".slif"),
70   - ("EDIF files", ".edf"),
71   - ("Xilinx EDIF files", ".edf"),
72   - ("RTL VHDL files", ".vhd"),
73   - ("Structural VHDL files", ".vhd"),
74   - ("RTL Verilog files", ".v"),
75   - ("Structural Verilog files", ".v")]
76   - self.filepath.set(tkFileDialog.askopenfilename(filetypes=ftypes))
77   - if self.filepath.get():
78   - self.filename.set(self.filepath.get().split("/")[-1])
79   -
80   - def open_bitstream_file(self):
81   - btypes = [("Xilinx bitstream", ".bit")]
82   - self.bitstream.set(tkFileDialog.askopenfilename(filetypes=btypes))
83   -
84   - def round_masking(self, _): # Dummy second argument
85   - self.masking_overhead.set(int(round(self.masking_overhead.get())))
86   -
87   - def round_locking(self, _): # Dummy second argument
88   - self.locking_overhead.set(int(round(self.locking_overhead.get())))
89   -
90   - def get_PUF_reference_response(self):
91   - self.PUF_reference_response = ''.join(random.SystemRandom().choice(["0", "1"]) for _ in range(256))
92   - self.PUF_reference_response_displayed.set(hex(int(self.PUF_reference_response, 2))[2:-1])
93   -
94   - # To be continued
95   - self.reconciliation_performed.set(False)
96   - self.reference_response_available.set(True)
97   - self.message_key_saved.set("")
98   -
99   - def check_reference_response_available(self, a, b, c): # a, b, c dummy variables
100   - if self.reference_response_available.get():
101   - self.perform_reconciliation_button.configure(state="normal")
102   - self.reconciliation_parameter_initial_block_size_spinbox.configure(state="normal")
103   - self.reconciliation_parameter_number_of_passes_spinbox.configure(state="normal")
104   - self.derive_key_button.configure(state="normal")
105   -
106   - def perform_reconciliation(self):
107   - # To be continued
108   - self.reconciliation_performed.set(True)
109   -
110   - def check_reconciliation_performed(self, a, b, c):
111   - if self.reconciliation_performed.get():
112   - self.masking_button.configure(state="normal")
113   - self.locking_button.configure(state="normal")
114   - self.masking_overhead_spinbox.configure(state="normal")
115   - self.locking_overhead_spinbox.configure(state="normal")
116   - self.modify_design_button.configure(state="normal")
117   - else:
118   - self.masking_button.configure(state="disabled")
119   - self.locking_button.configure(state="disabled")
120   - self.masking_overhead_spinbox.configure(state="disabled")
121   - self.locking_overhead_spinbox.configure(state="disabled")
122   - self.modify_design_button.configure(state="disabled")
123   -
124   - def pop_up_about(self):
125   - self.top = Toplevel(background="White")
126   - self.top.title("About")
127   -
128   - self.msg = Label(self.top, text="This software was realised in the frame of\n\
129   -the SALWARE project number ANR-13-JS03-0003\n\
130   -supported by the French \"Agence Nationale de\n\
131   -la Recherche\" and by the French \"Fondation de\n\
132   -Recherche pour l'Aéronautique et l'Espace\",\n\
133   -funding for this project was also provided by\n\
134   -a grant from \"La Région Rhône-Alpes\".", background="white")
135   - self.msg.pack()
136   - self.salware_logo = PhotoImage(file="./contents/Logo_SALWARE.gif")
137   -
138   - self.label = Label(self.top,
139   - image=self.salware_logo)
140   - self.label.image = self.salware_logo # keep a reference!
141   - self.label.pack()
142   -
143   - def pop_up_license(self):
144   - self.top = Toplevel()
145   - self.top.title("License")
146   - try:
147   - self.License_file = open("LICENSE.txt", 'r')
148   - self.License_text = self.License_file.read()
149   - self.License_file.close()
150   - except:
151   - self.License_text = "Cannot find LICENSE.txt"
152   - self.msg = Label(self.top, text=self.License_text, background="white")
153   - self.msg.pack()
154   -
155   - def connect(self):
156   - self.com_port_button_connect.configure(state=DISABLED)
157   - self.com_port_button_disconnect.configure(state=NORMAL)
158   - self.connected.set(True)
159   - self.com_port_status_text.configure(text="Connected",
160   - foreground="darkgreen")
161   -
162   - def disconnect(self):
163   - self.com_port_button_disconnect.configure(state=DISABLED)
164   - self.com_port_button_connect.configure(state=NORMAL)
165   - self.connected.set(False)
166   - self.com_port_status_text.configure(text="Disconnected",
167   - foreground="red")
168   -
169   - def modify_design(self, g, prim_in, prim_out, nodes):
170   - if self.locking.get():
171   - locking.locking(g, prim_in, prim_out, nodes, self.locking_overhead)
172   - if self.masking.get():
173   - masking.masking(g, prim_in, prim_out, nodes, self.masking_overhead, self.masking_heuristic)
174   -
175   - def derive_key_from_response(self):
176   - self.salt = bytes(''.join(random.SystemRandom().choice(["0", "1"]) for _ in range(32)))
177   - PRK_f = blake2.BLAKE2s(digest_size=32, key=self.salt)
178   - PRK_f.update(self.PUF_reference_response)
179   - self.key = ''.join('{0:08b}'.format(ord(x), 'b') for x in PRK_f.final()).replace("0b", "")
180   - key_file_name = "./../User_space/key_"+""+".txt"
181   - with open(key_file_name, "w") as key_file:
182   - key_file.write("Salt = "+self.salt+"\n")
183   - key_file.write("Key = "+self.key)
184   - self.message_key_saved.set("Key saved under "+key_file_name)
185   -
186   -def every_second():
187   - # To be filled
188   - fenetre.after(1000, every_second)
189   -
190   -if __name__ == "__main__":
191   -
192   - fenetre = Tk()
193   -
194   - app = App(fenetre)
195   -
196   - fenetre.after(1000, every_second)
197   - fenetre.mainloop()
1 1 MIT License
2 2  
3   -Copyright (c) 2016 Brice Colombier, Lilian Bossuet, David Hély, Ugo Mureddu
  3 +Copyright (c) 2016 Brice Colombier, Lilian Bossuet, David Hély
4 4  
5 5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 6 of this software and associated documentation files (the "Software"), to deal