Commit 82190d6525d5cf76c5e1e3b4b5d959b11f2ae1a8

Authored by Brice Colombier
1 parent 2993939d24
Exists in master

Add folders

Showing 6 changed files with 189 additions and 106 deletions

CASCADE/get_parities_from_indices.py View file @ 82190d6
... ... @@ -8,7 +8,6 @@
8 8  
9 9 import Tkinter
10 10  
11   -
12 11 def get_parities_from_indices(indices, response_on_board):
13 12  
14 13 """Get the parities of the on-board response blocks.
15 14  
... ... @@ -28,14 +27,12 @@
28 27 tclsh.eval("sendFabricReset $dev")
29 28 tclsh.eval("sendFabricCommand $dev 4 4") # generate automatic response
30 29 tclsh.eval("sendFabricCommand $dev 4 3") # offload response to MB
31   - tclsh.eval("puts [sendFabricCommand $dev 5 0]") # Display response block 0
32   - tclsh.eval("puts [sendFabricCommand $dev 5 1]") # Display response block 1
33   - tclsh.eval("puts [sendFabricCommand $dev 5 2]") # Display response block 2
34   - tclsh.eval("puts [sendFabricCommand $dev 5 3]") # Display response block 3
35   - for i in indices:
36   - parities.append(reduce(lambda a, b: a ^ b, [response_on_board[j] for j in i]))
37   - return parities
  30 + tclsh.eval("set rep \"[sendFabricCommand $dev 5 3] [sendFabricCommand $dev 5 2] [sendFabricCommand $dev 5 1] [sendFabricCommand $dev 5 0]\"") # Display response block 0
  31 + tclsh.eval("regsub -all { } $rep {} rep")
  32 + response = tclsh.eval("exit $rep")
  33 + print response
  34 +
38 35  
39 36 if __name__ == "__main__":
40   - print get_parities_from_indices([[0, 1], [2, 3]], [0, 1, 0, 0])
  37 + print get_parities_from_indices([0, 1, 2, 3])
GUI/add_frame_elements.py View file @ 82190d6
... ... @@ -61,10 +61,10 @@
61 61 self.reference_response_frame.pack(side=TOP)
62 62 self.CASCADE_frame = LabelFrame(self.PUF_frame,
63 63 text="CASCADE protocol",
64   - selftyle="Green.TLabelframe")
  64 + style="Green.TLabelframe")
65 65 self.CASCADE_frame.pack(side=LEFT)
66 66 self.reconciliation_parameters_label = Label(self.CASCADE_frame,
67   - # TODO: ext="Parameters:")
  67 + text="Parameters:")
68 68 self.reconciliation_parameters_label.grid(row=0, column=0)
69 69 self.reconciliation_parameter_initial_block_size_label = Label(self.CASCADE_frame,
70 70 text="Initial block size (bits):")
Generate_modified_netlist/convert_back.py View file @ 82190d6
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: convert_back.py
7   -# Date: 2016-10-13
8   -
9   -
10   -def convert_back(self, name):
11   -
12   - """Convert a graph into a vhd netlist"""
13   -
14   - dest_file = "./"+name+"_mod.vhd"
15   - dest = open(dest_file, "w")
16   - # LIBRARY
17   - dest.write("LIBRARY IEEE;\nUSE IEEE.STD_LOGIC_1164.ALL;\n\n")
18   - # ENTITY
19   - dest.write("ENTITY "+name+" IS\n\n")
20   - # PORTS
21   - dest.write(" PORT (\n")
22   -
23   - # Preprocessing
24   - for i in self.vs:
25   - if i["cat"] == "node" and i.predecessors() == []:
26   - print "Error in convert_back"
27   - i["cat"] = "input"
28   -
29   - for i in self.vs:
30   - if i["cat"] == "input":
31   - dest.write(" "+i["name"]+" : IN STD_LOGIC;\n")
32   -
33   - for i in self.vs:
34   - if i["cat"] == "output":
35   - dest.write(" "+i["name"]+" : OUT STD_LOGIC;\n")
36   -
37   - dest.seek(-3, 2)
38   - dest.write("\n );\n\n")
39   - dest.write("END ENTITY "+name+";\n\n")
40   - dest.write("ARCHITECTURE rtl OF "+name+" IS\n\n")
41   -
42   - for i in self.vs:
43   - if i["cat"] in ["node", "mod"]:
44   - dest.write(" SIGNAL "+i["name"]+" : STD_LOGIC;\n")
45   -
46   - dest.write("\nBEGIN\n\n")
47   -
48   - for i in self.vs:
49   - if i["cat"] in ["node", "output", "mod"]:
50   - dest.write(" ")
51   - first = True
52   -
53   - for j in i.predecessors():
54   - function = self.es[self.get_eid(self.vs.find(j["name"]), self.vs.find(i["name"]))]["label"].lower()
55   - if function == "not":
56   - dest.write(i["name"]+" <= "+function.upper()+"("+j["name"]+")")
57   - if function == "buf":
58   - dest.write(i["name"]+" <= "+j["name"])
59   - elif function in ["and", "or", "xnor", "xor"]:
60   - if first:
61   - dest.write(i["name"])
62   - dest.write(" <= ")
63   - dest.write(j["name"])
64   - dest.write(" "+function.upper()+" ")
65   - first = False
66   - else:
67   - dest.write(j["name"])
68   - dest.write(" "+function.upper()+" ")
69   - elif function in ["nand", "nor"]:
70   - if first:
71   - dest.write(i["name"])
72   - dest.write(" <= ")
73   - dest.write("NOT(")
74   - dest.write(j["name"])
75   - first = False
76   - else:
77   - dest.write(" "+function[1:].upper()+" "+j["name"])
78   -
79   - if function in ["and", "xor"]:
80   - dest.seek(-5, 2)
81   - elif function == "xnor":
82   - dest.seek(-6, 2)
83   - elif function == "or":
84   - dest.seek(-4, 2)
85   - elif function == "nand":
86   - dest.seek(0, 2)
87   - dest.write(")")
88   - elif function == "nor":
89   - dest.seek(0, 2)
90   - dest.write(")")
91   - dest.write(";\n")
92   -
93   - dest.write("\nEND ARCHITECTURE rtl;\n")
94   - dest.close()
Generate_modified_netlist/convert_back_bench.py View file @ 82190d6
  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: convert_back_bench.py
  7 +# Date: 2016-10-19
  8 +
  9 +
  10 +def convert_back(self, name):
  11 +
  12 + """Convert a grand into a bench netlist"""
  13 +
  14 + dest_file = "./" + name + ".bench"
  15 + dest = open(dest_file, "w")
  16 +
  17 + # Preprocessing
  18 + for i in self.vs:
  19 + if i["cat"] == "node" and i.predecessors() == []:
  20 + print "Error in convert_back"
  21 + i["cat"] = "input"
  22 +
  23 + for i in self.vs:
  24 + if i["cat"] == "input":
  25 + dest.write("INPUT(" + i["name"] + ")\n")
  26 +
  27 + for i in self.vs:
  28 + if i["cat"] == "output":
  29 + dest.write("OUTPUT(" + i["name"] + ")\n")
  30 +
  31 + dest.write("\n")
  32 + for i in self.vs:
  33 + if i["cat"] in ["node", "output", "mod"]:
  34 + first = True
  35 +
  36 + for j in i.predecessors():
  37 + function = self.es[self.get_eid(self.vs.find(j["name"]), self.vs.find(i["name"]))]["label"].lower()
  38 + if function in ["not", "buf"]:
  39 + dest.write(i["name"] + " = " + function + "(" + j["name"])
  40 + elif function in ["and", "or", "xnor", "xor", "nand", "nor"]:
  41 + if first:
  42 + dest.write(i["name"])
  43 + dest.write(" = ")
  44 + dest.write(function + "(")
  45 + dest.write(j["name"])
  46 + first = False
  47 + else:
  48 + dest.write("," + j["name"])
  49 + dest.write(")\n")
  50 + dest.close()
Generate_modified_netlist/convert_back_vhd.py View file @ 82190d6
  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: convert_back.py
  7 +# Date: 2016-10-13
  8 +
  9 +
  10 +def convert_back(self, name):
  11 +
  12 + """Convert a graph into a vhd netlist"""
  13 +
  14 + dest_file = "./" + name + ".vhd"
  15 + dest = open(dest_file, "w")
  16 + # LIBRARY
  17 + dest.write("LIBRARY IEEE;\nUSE IEEE.STD_LOGIC_1164.ALL;\n\n")
  18 + # ENTITY
  19 + dest.write("ENTITY " + name + " IS\n\n")
  20 + # PORTS
  21 + dest.write(" PORT (\n")
  22 +
  23 + # Preprocessing
  24 + for i in self.vs:
  25 + if i["cat"] == "node" and i.predecessors() == []:
  26 + print "Error in convert_back"
  27 + i["cat"] = "input"
  28 +
  29 + for i in self.vs:
  30 + if i["cat"] == "input":
  31 + dest.write(" " + i["name"] + " : IN STD_LOGIC;\n")
  32 +
  33 + for i in self.vs:
  34 + if i["cat"] == "output":
  35 + dest.write(" " + i["name"] + " : OUT STD_LOGIC;\n")
  36 +
  37 + dest.seek(-3, 2)
  38 + dest.write("\n );\n\n")
  39 + dest.write("END ENTITY " + name + ";\n\n")
  40 + dest.write("ARCHITECTURE rtl OF " + name + " IS\n\n")
  41 +
  42 + for i in self.vs:
  43 + if i["cat"] in ["node", "mod"]:
  44 + dest.write(" SIGNAL " + i["name"] + " : STD_LOGIC;\n")
  45 +
  46 + dest.write("\nBEGIN\n\n")
  47 +
  48 + for i in self.vs:
  49 + if i["cat"] in ["node", "output", "mod"]:
  50 + dest.write(" ")
  51 + first = True
  52 +
  53 + for j in i.predecessors():
  54 + function = self.es[self.get_eid(self.vs.find(j["name"]), self.vs.find(i["name"]))]["label"].lower()
  55 + if function == "not":
  56 + dest.write(i["name"] + " <= " + function.upper() + "(" + j["name"] + ")")
  57 + if function == "buf":
  58 + dest.write(i["name"] + " <= " + j["name"])
  59 + elif function in ["and", "or", "xnor", "xor"]:
  60 + if first:
  61 + dest.write(i["name"])
  62 + dest.write(" <= ")
  63 + dest.write(j["name"])
  64 + dest.write(" " + function.upper() + " ")
  65 + first = False
  66 + else:
  67 + dest.write(j["name"])
  68 + dest.write(" " + function.upper() + " ")
  69 + elif function in ["nand", "nor"]:
  70 + if first:
  71 + dest.write(i["name"])
  72 + dest.write(" <= ")
  73 + dest.write("NOT(")
  74 + dest.write(j["name"])
  75 + first = False
  76 + else:
  77 + dest.write(" " + function[1:].upper() + " " + j["name"])
  78 +
  79 + if function in ["and", "xor"]:
  80 + dest.seek(-5, 2)
  81 + elif function == "xnor":
  82 + dest.seek(-6, 2)
  83 + elif function == "or":
  84 + dest.seek(-4, 2)
  85 + elif function == "nand":
  86 + dest.seek(0, 2)
  87 + dest.write(")")
  88 + elif function == "nor":
  89 + dest.seek(0, 2)
  90 + dest.write(")")
  91 + dest.write(";\n")
  92 +
  93 + dest.write("\nEND ARCHITECTURE rtl;\n")
  94 + dest.close()
PUF/get_full_response.py View file @ 82190d6
  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: get_full_response.py
  7 +# Date : 2016-10-15
  8 +
  9 +import Tkinter
  10 +
  11 +def get_full_response(indices, response_on_board):
  12 +
  13 + """Get the parities of the on-board response blocks.
  14 +
  15 + Hardware-specific implementation.
  16 + >>> get_parities_from_indices([[1, 5], [7, 2], [3, 6], [4, 0]])
  17 + [0, 1, 1, 0]
  18 + """
  19 +
  20 + tclsh = Tkinter.Tcl()
  21 + parities = []
  22 + tclsh.eval("source {HECTOR_data_acq.tcl}")
  23 + tclsh.eval("set dev [openDevice COM3]")
  24 + tclsh.eval("puts \"Resetting the board\"")
  25 + tclsh.eval("softReset $dev")
  26 + tclsh.eval("sendDaughterReset $dev")
  27 + tclsh.eval("sendFabricReset $dev")
  28 + tclsh.eval("sendFabricCommand $dev 4 4") # generate automatic response
  29 + tclsh.eval("sendFabricCommand $dev 4 3") # offload response to MB
  30 + tclsh.eval("set rep \"[sendFabricCommand $dev 5 3] [sendFabricCommand $dev 5 2] [sendFabricCommand $dev 5 1] [sendFabricCommand $dev 5 0]\"") # Display response block 0
  31 + tclsh.eval("regsub -all { } $rep {} rep")
  32 + response = tclsh.eval("exit $rep")
  33 + print response
  34 +
  35 +
  36 +if __name__ == "__main__":
  37 + print get_full_response([0, 1, 2, 3])