51 namespace graph_algorithm
188 detect(
Netlist* nl,
const std::vector<DetectionConfiguration>& configs,
u32 min_state_size = 40,
const std::vector<Gate*>& start_ffs = {});
427 bool m_is_round_based =
false;
430 std::vector<Gate*> m_in_reg;
433 std::vector<Gate*> m_out_reg;
442 std::vector<u32> m_in_reg_ids, m_out_reg_ids;
445 std::vector<Gate*> m_round_logic;
448 std::unique_ptr<graph_algorithm::NetlistGraph> m_graph;
451 std::set<Net*> m_state_inputs, m_state_outputs, m_control_inputs, m_other_inputs;
462 mutable std::map<Gate*, std::set<Gate*>> m_input_ffs_of_gate;
463 mutable std::map<u32, std::set<Gate*>> m_longest_distance_to_gate;
466 mutable bool m_has_gate_dependencies =
false;
472 void compute_gate_dependencies()
const;
480 std::vector<std::unique_ptr<SBox>> m_sboxes;
483 bool m_has_round_function =
false;
This file contains the struct for configuring HAWKEYE's candidate search, see CipherCandidate::detect...
A directed graph corresponding to a netlist.
A candidate for a symmetric cryptographic implementation within a netlist.
const std::map< u32, std::set< Gate * > > & get_longest_distance_to_gate() const
Get a map from a distance to all gates reachable within at most that distance from any input flip-flo...
std::vector< Gate * > get_gates() const
Get all gates of the candidate, i.e., its registers together with its round function,...
CipherCandidate & operator=(CipherCandidate &&)=default
const std::set< Net * > & get_control_inputs() const
Get the control inputs of the round function.
std::vector< SBox * > get_sboxes() const
Get the S-boxes located within the round function of the candidate.
Result< u32 > identify_sboxes(const SBoxDatabase &db)
Try to identify all S-boxes of the candidate by matching them against a database of known S-boxes.
graph_algorithm::NetlistGraph * get_graph() const
Get the graph of the round function, in which the gates of the state register are represented by a pr...
Result< std::vector< SBox * > > locate_sboxes()
Try to locate S-boxes within the round function of the candidate.
void clear_sboxes()
Discard the S-boxes located so far.
const std::set< Net * > & get_state_outputs() const
Get the state outputs of the round function.
const std::vector< Gate * > & get_input_reg() const
Get the input register of the candidate, ordered by gate ID.
const std::vector< Gate * > & get_round_logic() const
Get the combinational logic computing the next state, ordered by gate ID.
CipherCandidate()=default
~CipherCandidate()=default
Result< Module * > create_modules()
Write the candidate back into the netlist as a module hierarchy.
Result< std::monostate > build_round_function()
Determine the round function of the candidate, i.e., the combinational logic computing the next state...
const std::set< Net * > & get_state_inputs() const
Get the state inputs of the round function.
CipherCandidate & operator=(const CipherCandidate &)=delete
bool operator==(const CipherCandidate &rhs) const
Check whether two candidates have the same size and the same registers.
Netlist * get_netlist() const
Get the netlist that the candidate belongs to.
CipherCandidate(const CipherCandidate &)=delete
const std::set< Net * > & get_other_inputs() const
Get the remaining inputs of the round function.
bool is_round_based() const
Check whether the candidate is round-based, i.e., whether its input and output register are the same.
static Result< std::vector< CipherCandidate > > detect(Netlist *nl, const std::vector< DetectionConfiguration > &configs, u32 min_state_size=40, const std::vector< Gate * > &start_ffs={})
Attempt to locate candidates for symmetric cryptographic SPN, Feistel, and ARX implementations within...
Result< std::string > identify_sbox(const SBox *sbox, const SBoxDatabase &db) const
Try to identify a single S-box of this candidate by matching it against a database of known S-boxes u...
u32 get_size() const
Get the size of the candidate, i.e., the width of its state register.
bool operator<(const CipherCandidate &rhs) const
Compare two candidates.
const std::vector< Gate * > & get_output_reg() const
Get the output register of the candidate, ordered by gate ID. Equal to the input register for a round...
bool has_round_function() const
Check whether the round function of the candidate has been computed, see build_round_function.
CipherCandidate(CipherCandidate &&)=default
const std::map< Gate *, std::set< Gate * > > & get_input_ffs_of_gate() const
Get a map from each gate of the round function to the input flip-flops it depends on.
Database of known S-boxes.
SBoxStatus
The outcome of trying to identify an S-box, see CipherCandidate::identify_sboxes.
This file contains the S-box database class that holds and manages known cryptographic S-boxes up to ...
An S-box located within the round function of a CipherCandidate.
std::string identified_as
The name of the S-box in the database it was identified as, empty unless status is identified.
std::vector< Gate * > output_gates
The output gates of the S-box, ordered by gate ID. Usually combinational gates feeding the linear lay...
std::vector< Gate * > component
The gates of the connected component that the S-box was located in, including its input flip-flops.
std::vector< Gate * > input_gates
The input flip-flops of the S-box, ordered by gate ID.
SBoxStatus status
The outcome of trying to identify the S-box, unidentified until identify_sboxes ran.
std::vector< Gate * > get_combinational_gates() const
Get the combinational gates computing the outputs of the S-box from its input flip-flops.