-
Notifications
You must be signed in to change notification settings - Fork 0
/
EncryptedCircuit.h
85 lines (62 loc) · 1.97 KB
/
EncryptedCircuit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef ENCRYPTEDCIRCUIT_H
#define ENCRYPTEDCIRCUIT_H
#include "Circuit.h"
typedef std::string Key;
/*!
* Encryption algorithms will not obfucate primary (or latch) input/output wires.
*/
class EncryptedCircuit : public Circuit {
public:
EncryptedCircuit(std::string filename, TechLibrary* library_) :
Circuit(filename, library_) {}
/*!
* Adds XOR locking gates randomly to the circuit. There will
* be an error if one attempts to add too many XORs.
*/
void add_random_xors(int num_xors);
/*!
* Adds MUXes between two signals to preserve testing.
*/
void add_test_mux(int num_muxes, bool get_cands);
/*!
* Prints the key wire and its unlocking value.
*/
void print_keys();
/*!
* Set the key to a value.
*/
void toggle_key(unsigned int key_id);
/*!
* Randomly set the value of all of the keys.
*/
void randomly_set_keys();
/*!
* Correctly set keys.
*/
void correctly_set_keys();
void set_key_value(unsigned int key_id, int val);
void print_testability_prob(std::tr1::unordered_set<Inst*>& stuck0,
std::tr1::unordered_set<Inst*>& stuck1);
int get_num_keys() const
{
return key_wires.size();
}
bool get_key_value(unsigned int id);
bool get_current_key_value(unsigned int id);
void levelize();
std::vector<Inst*> get_new_gates()
{
return new_gates;
}
private:
Inst* create_cover(Inst* inst_correct, Inst* inst_cover, CoverType cover);
void insert_mux(Inst* inst, Inst* cover, std::string key_name, int value);
void insert_xor(Inst* inst, std::string name, int value);
CoverType find_cover(Wire* wire1, Wire* wire2, Circuit& validation_circuit);
//! these are new inputs to the circuit (not in base class PI list)
std::vector<Wire*> key_wires;
//! the unlocking key
std::tr1::unordered_map<Key, int> key_values;
std::vector<Inst*> new_gates;
};
#endif