HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
functional_candidate.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
31 #pragma once
32 
33 #include "hal_core/defines.h"
34 #include "hal_core/netlist/gate.h"
38 
39 namespace hal
40 {
41  namespace module_identification
42  {
50  {
51  public:
60 
72  u32 max_control_signal,
73  CandidateContext& ctx,
75  const std::vector<std::vector<Gate*>>& registers);
76 
77  // Comparisons
78 
87 
96 
105 
114 
123 
124  // Adder, subtractor, counter
125 
134 
143 
152 
161 
170 
179 
188 
197 
206 
215 
224 
225  // Absolute
226 
235 
236  // Constant Multiplication
237 
245  static FunctionalCandidate add_n_shifted_operands(const FunctionalCandidate& candidate, const std::vector<i32>& shift_vals);
246 
255 
264 
265  // Value check
266 
275 
284 
292  hal::Result<VerifiedCandidate> check(const std::vector<BooleanFunction>& output_functions, const std::vector<std::vector<Gate*>>& registers);
293 
300  void add_additional_data(std::string key, std::string value);
301 
307  std::map<std::string, std::string> get_all_additional_data() const;
308 
314  std::string get_candidate_info() const;
315 
320 
324  std::vector<Gate*> m_gates;
325 
329  std::vector<Gate*> m_base_gates;
330 
335 
339  std::vector<std::vector<Net*>> m_operands;
340 
344  std::vector<Net*> m_control_signals;
345 
349  std::map<Net*, BooleanFunction::Value> m_control_mapping;
350 
354  std::map<u32, std::vector<Net*>> m_influence_count_to_input_nets;
355 
359  std::map<u32, std::vector<Net*>> m_input_count_to_output_nets;
360 
364  std::map<Net*, Net*> m_single_input_to_output;
365 
369  std::vector<std::pair<Net*, Net*>> m_permuted_single_pairs;
370 
374  std::vector<Net*> m_input_nets;
375 
379  std::vector<Net*> m_output_nets;
380 
385 
390 
394  std::map<std::string, std::string> m_additional_data = {};
395 
400 
404  std::vector<Net*> m_sign_nets;
405 
409  std::map<std::string, std::map<std::string, std::map<std::string, std::map<std::string, u64>>>> m_timings;
410  };
411  } // namespace module_identification
412 } // namespace hal
This file contains the CandidateContext struct and that is used for optimization purposes during the ...
Definition: net.h:58
Represents a functional candidate derived from structural candidates.
static hal::Result< std::vector< FunctionalCandidate > > discard_equal_candidate(CandidateContext &ctx, const FunctionalCandidate &candidate)
Discard equal candidates based on their number of input signals.
static hal::Result< std::vector< FunctionalCandidate > > create_input_extension_variants(CandidateContext &ctx, const FunctionalCandidate &candidate)
Create input extension variants for an adder, subtractor, or counter.
std::vector< std::pair< Net *, Net * > > m_permuted_single_pairs
static hal::Result< std::vector< FunctionalCandidate > > build_input_operand(CandidateContext &ctx, const FunctionalCandidate &candidate)
Build an input operand for a functional candidate by including all external input signals of the cand...
static hal::Result< std::vector< FunctionalCandidate > > add_single_input_signals(CandidateContext &ctx, const FunctionalCandidate &candidate)
Add single input signals for an adder, subtractor, or counter.
static hal::Result< std::vector< FunctionalCandidate > > add_selected_shifted_operand(CandidateContext &ctx, const FunctionalCandidate &candidate)
Add shifted operands to the functional candidate based on its input output stats.
std::map< std::string, std::string > get_all_additional_data() const
Get all additional data of the functional candidate.
static hal::Result< std::vector< FunctionalCandidate > > trim_to_single_output_net(CandidateContext &ctx, const FunctionalCandidate &candidate)
Trim a functional candidate to a single output net.
std::map< u32, std::vector< Net * > > m_influence_count_to_input_nets
std::map< std::string, std::map< std::string, std::map< std::string, std::map< std::string, u64 > > > > m_timings
static hal::Result< std::vector< FunctionalCandidate > > add_all_shifted_operand(CandidateContext &ctx, const FunctionalCandidate &candidate)
Add all possible variations of possible shifted operands to the functional candidate.
std::string get_candidate_info() const
Get candidate information as a string.
static hal::Result< std::vector< FunctionalCandidate > > realize_control_signals(CandidateContext &ctx, const FunctionalCandidate &candidate)
Realize control signals for an adder, subtractor, or counter by setting the control signals to concre...
static hal::Result< std::vector< FunctionalCandidate > > permute_single_input_signals(CandidateContext &ctx, const FunctionalCandidate &candidate)
Permute single input signals for an adder, subtractor, or counter.
static hal::Result< std::vector< FunctionalCandidate > > create_sign_bit_variants(CandidateContext &ctx, const FunctionalCandidate &candidate)
Create sign bit variants for an adder, subtractor, or counter.
static hal::Result< std::vector< FunctionalCandidate > > check_output_size(CandidateContext &ctx, const FunctionalCandidate &candidate)
Check the output size of a functional candidate.
static hal::Result< std::vector< FunctionalCandidate > > find_control_signals(CandidateContext &ctx, const FunctionalCandidate &candidate)
Find control signals for a functional candidate.
static hal::Result< std::vector< FunctionalCandidate > > update_input_output_stats(CandidateContext &ctx, const FunctionalCandidate &candidate)
Update input and output statistics for an adder, subtractor, or counter.
static hal::Result< std::vector< FunctionalCandidate > > create_sign_extension_variants(CandidateContext &ctx, const FunctionalCandidate &candidate)
Create sign extension variants of a functional candidate.
static hal::Result< std::vector< FunctionalCandidate > > create_candidates(StructuralCandidate *sc, u32 max_control_signal, CandidateContext &ctx, module_identification::CandidateType candidate_type, const std::vector< std::vector< Gate * >> &registers)
Create functional candidates from a structural candidate.
static hal::Result< std::vector< FunctionalCandidate > > identify_control_signals(CandidateContext &ctx, const FunctionalCandidate &candidate)
Identify control signals for an adder, subtractor, or counter.
std::map< u32, std::vector< Net * > > m_input_count_to_output_nets
static hal::Result< std::vector< FunctionalCandidate > > order_input_operands(CandidateContext &ctx, const FunctionalCandidate &candidate)
Order input operands for a functional candidate.
static FunctionalCandidate add_n_shifted_operands(const FunctionalCandidate &candidate, const std::vector< i32 > &shift_vals)
Add n shifted operands for constant multiplication.
static hal::Result< std::vector< FunctionalCandidate > > order_output_signals(CandidateContext &ctx, const FunctionalCandidate &candidate)
Order output signals for an adder, subtractor, or counter.
std::map< Net *, BooleanFunction::Value > m_control_mapping
static hal::Result< std::vector< FunctionalCandidate > > build_input_operands(CandidateContext &ctx, const FunctionalCandidate &candidate)
Build input operands for an adder, subtractor, or counter.
static hal::Result< std::vector< FunctionalCandidate > > early_abort(CandidateContext &ctx, const FunctionalCandidate &candidate)
Early abort process for a functional candidate.
std::map< std::string, std::string > m_additional_data
module_identification::CandidateType m_candidate_type
static hal::Result< std::vector< FunctionalCandidate > > create_operand_control_variations(CandidateContext &ctx, const FunctionalCandidate &candidate)
Create operand control variations for absolute functional candidates.
FunctionalCandidate(StructuralCandidate *sc, u32 max_control_signal, module_identification::CandidateType candidate_type)
Constructor for FunctionalCandidate.
static hal::Result< std::vector< FunctionalCandidate > > create_output_net_variant(CandidateContext &ctx, const FunctionalCandidate &candidate)
Create output net variants for an adder, subtractor, or counter.
hal::Result< VerifiedCandidate > check(const std::vector< BooleanFunction > &output_functions, const std::vector< std::vector< Gate * >> &registers)
Check whether a functional candidate with the given input operands and output functions is actually i...
void add_additional_data(std::string key, std::string value)
Add additional data to the functional candidate.
std::vector< std::vector< Net * > > m_operands
A class representing a structural candidate for module identification.
uint32_t u32
Definition: defines.h:41
CandidateType
Enumeration of the different candidate types for module identification.
Definition: defines.h:45
This struct manages the context of a candidate during module identification, including caches for all...
This file contains the class for defining and managing structural candidates within the module identi...