-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
320 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// MIT License | ||
// | ||
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved. | ||
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved. | ||
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved. | ||
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
#pragma once | ||
|
||
#include "hal_core/utilities/result.h" | ||
|
||
#include <set> | ||
|
||
namespace hal | ||
{ | ||
class Netlist; | ||
class Gate; | ||
|
||
namespace hawkeye | ||
{ | ||
class Candidate | ||
{ | ||
public: | ||
Candidate() = default; | ||
~Candidate() = default; | ||
|
||
/** | ||
* Construct a crypto candidate from the state register of a round-based implementation. | ||
* | ||
* @param[in] round_reg - The state register. | ||
*/ | ||
Candidate(const std::set<Gate*>& round_reg); | ||
|
||
/** | ||
* Construct a crypto candidate from the state register of a round-based implementation. | ||
* | ||
* @param[in] round_reg - The state register. | ||
*/ | ||
Candidate(std::set<Gate*>&& round_reg); | ||
|
||
/** | ||
* Construct a crypto candidate from the input and output registers from a round of a pipelined implementation. | ||
* | ||
* @param[in] in_reg - The input register. | ||
* @param[in] out_reg - The output register. | ||
*/ | ||
Candidate(const std::set<Gate*>& in_reg, const std::set<Gate*>& out_reg); | ||
|
||
/** | ||
* Construct a crypto candidate from the input and output registers from a round of a pipelined implementation. | ||
* | ||
* @param[in] in_reg - The input register. | ||
* @param[in] out_reg - The output register. | ||
*/ | ||
Candidate(std::set<Gate*>&& in_reg, std::set<Gate*>&& out_reg); | ||
|
||
bool operator==(const Candidate& rhs) const; | ||
bool operator<(const Candidate& rhs) const; | ||
|
||
/** | ||
* Get the netlist associated with the candidate. | ||
* | ||
* @return The netlist of the candidate. | ||
*/ | ||
Netlist* get_netlist() const; | ||
|
||
/** | ||
* Get the size of the candidate, i.e., the width of its registers. | ||
* | ||
* @returns The size of the candidate. | ||
*/ | ||
u32 get_size() const; | ||
|
||
/** | ||
* Check if the candidate is round-based, i.e., input and output register are the same. | ||
* | ||
* @returns `true` if the candidate is round-based, `false` otherwise. | ||
*/ | ||
bool is_round_based() const; | ||
|
||
/** | ||
* Get the candidate's input register. | ||
* | ||
* @returns The input register of the candidate. | ||
*/ | ||
const std::set<Gate*>& get_in_reg() const; | ||
|
||
/** | ||
* Get the candidate's output register. | ||
* | ||
* @returns The output register of the candidate. | ||
*/ | ||
const std::set<Gate*>& get_out_reg() const; | ||
|
||
private: | ||
/** | ||
* The netlist to which the candidate belongs. | ||
*/ | ||
Netlist* m_netlist; | ||
|
||
/** | ||
* The bit-size of the candidate. | ||
*/ | ||
u32 m_size; | ||
|
||
/** | ||
* Is `true` when the the candidate is round-based, i.e., input and output register are the same. | ||
*/ | ||
bool m_is_round_based; | ||
|
||
/** | ||
* The candidate input register. | ||
*/ | ||
std::set<Gate*> m_in_reg; | ||
|
||
/** | ||
* The candidate output register. May be equal to `m_in_reg` for round-based implementations. | ||
*/ | ||
std::set<Gate*> m_out_reg; | ||
}; | ||
} // namespace hawkeye | ||
} // namespace hal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// MIT License | ||
// | ||
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved. | ||
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved. | ||
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved. | ||
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
#pragma once | ||
|
||
#include "hal_core/utilities/result.h" | ||
#include "hawkeye/candidate.h" | ||
|
||
namespace hal | ||
{ | ||
class Netlist; | ||
|
||
namespace hawkeye | ||
{ | ||
struct DetectionConfiguration | ||
{ | ||
enum class Control | ||
{ | ||
CHECK_FF, | ||
CHECK_TYPE, | ||
CHECK_PINS, | ||
CHECK_NETS | ||
} control = Control::CHECK_NETS; | ||
|
||
enum class Components | ||
{ | ||
NONE, | ||
CHECK_SCC | ||
} components = Components::NONE; | ||
|
||
u32 timeout = 10; | ||
u32 min_register_size = 10; | ||
}; | ||
|
||
/** | ||
* TODO description | ||
* | ||
* @param[in] nl - The netlist to operate on. | ||
* @param[in] config - The configurations of the detection approaches to be executed one after another on each start flip-flop. | ||
* @param[in] min_state_size - The minimum size of a register candidate to be considered a cryptographic state register. Defaults to `40`. | ||
* @param[in] start_ffs - The flip-flops to analyze. Defaults to an empty vector, i.e., all flip-flops in the netlist will be analyzed. | ||
* @returns Ok() and a vector of candidates on success, an error otherwise. | ||
*/ | ||
Result<std::vector<Candidate>> detect_candidates(Netlist* nl, const std::vector<DetectionConfiguration>& configs, u32 min_state_size = 40, const std::vector<Gate*>& start_ffs = {}); | ||
} // namespace hawkeye | ||
} // namespace hal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "hawkeye/candidate.h" | ||
|
||
#include "hal_core/netlist/gate.h" | ||
|
||
namespace hal | ||
{ | ||
namespace hawkeye | ||
{ | ||
Candidate::Candidate(const std::set<Gate*>& round_reg) : m_in_reg(round_reg), m_out_reg(round_reg) | ||
{ | ||
m_size = m_out_reg.size(); | ||
m_netlist = (*m_out_reg.begin())->get_netlist(); | ||
m_is_round_based = true; | ||
} | ||
|
||
Candidate::Candidate(std::set<Gate*>&& round_reg) : m_in_reg(std::move(round_reg)) | ||
{ | ||
m_out_reg = m_in_reg; | ||
m_size = m_out_reg.size(); | ||
m_netlist = (*m_out_reg.begin())->get_netlist(); | ||
m_is_round_based = true; | ||
} | ||
|
||
Candidate::Candidate(const std::set<Gate*>& in_reg, const std::set<Gate*>& out_reg) : m_in_reg(in_reg), m_out_reg(out_reg) | ||
{ | ||
m_size = m_out_reg.size(); | ||
m_netlist = (*m_out_reg.begin())->get_netlist(); | ||
m_is_round_based = m_in_reg == m_out_reg; | ||
} | ||
|
||
Candidate::Candidate(std::set<Gate*>&& in_reg, std::set<Gate*>&& out_reg) : m_in_reg(std::move(in_reg)), m_out_reg(std::move(out_reg)) | ||
{ | ||
m_size = m_out_reg.size(); | ||
m_netlist = (*m_out_reg.begin())->get_netlist(); | ||
m_is_round_based = m_in_reg == m_out_reg; | ||
} | ||
|
||
bool Candidate::operator==(const Candidate& rhs) const | ||
{ | ||
return (this->m_size == rhs.m_size) && (this->m_in_reg == rhs.m_in_reg) && (!m_is_round_based & (this->m_out_reg == rhs.m_out_reg)); | ||
} | ||
|
||
bool Candidate::operator<(const Candidate& rhs) const | ||
{ | ||
return (this->m_size > rhs.m_size) || (this->m_size == rhs.m_size && this->m_in_reg > rhs.m_in_reg) | ||
|| (!m_is_round_based & (this->m_size == rhs.m_size && this->m_in_reg == rhs.m_in_reg && this->m_out_reg > rhs.m_out_reg)); | ||
} | ||
|
||
Netlist* Candidate::get_netlist() const | ||
{ | ||
return m_netlist; | ||
} | ||
|
||
u32 Candidate::get_size() const | ||
{ | ||
return m_size; | ||
} | ||
|
||
bool Candidate::is_round_based() const | ||
{ | ||
return m_is_round_based; | ||
} | ||
|
||
const std::set<Gate*>& Candidate::get_in_reg() const | ||
{ | ||
return m_in_reg; | ||
} | ||
|
||
const std::set<Gate*>& Candidate::get_out_reg() const | ||
{ | ||
return m_out_reg; | ||
} | ||
|
||
} // namespace hawkeye | ||
} // namespace hal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "hawkeye/candidate_search.h" | ||
|
||
#include "hal_core/netlist/decorators/netlist_traversal_decorator.h" | ||
|
||
namespace hal | ||
{ | ||
namespace hawkeye | ||
{ | ||
Result<std::vector<Candidate>> detect_candidates(Netlist* nl, const std::vector<DetectionConfiguration>& configs, u32 min_state_size, const std::vector<Gate*>& start_ffs) | ||
{ | ||
if (nl == nullptr) | ||
{ | ||
return ERR("netlist is a nullptr"); | ||
} | ||
|
||
const auto nl_dec = NetlistTraversalDecorator(*nl); | ||
const auto res = nl_dec.get_next_sequential_gates_map(true, {PinType::enable, PinType::reset, PinType::set, PinType::clock}); | ||
if (res.is_error()) | ||
{ | ||
return ERR(res.get_error()); | ||
} | ||
const auto seq_map = res.get(); | ||
|
||
for (const auto& config : configs) | ||
{ | ||
} | ||
|
||
// TODO for each Detection configuration, create a NetlistGraph | ||
|
||
// TODO run neighborhood stuff and potentiall SCC detection on NetlistGraph | ||
// neighborhood: feed all currently considered FFs as start vertices; after every iteration, sort out start vertices of saturating neighborhoods as well as equivalent ones | ||
// SCCs: compute SCCs within neighborhoods | ||
|
||
return ERR("not implemented"); | ||
} | ||
} // namespace hawkeye | ||
} // namespace hal |