Skip to content

Commit

Permalink
changed architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
SJulianS committed May 21, 2024
1 parent 0c357f1 commit 2312184
Show file tree
Hide file tree
Showing 8 changed files with 585 additions and 312 deletions.
4 changes: 2 additions & 2 deletions plugins/hawkeye/include/hawkeye/candidate_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "hal_core/utilities/enums.h"
#include "hal_core/utilities/result.h"
#include "hawkeye/candidate.h"
#include "hawkeye/register_candidate.h"

namespace hal
{
Expand Down Expand Up @@ -64,7 +64,7 @@ namespace hal
* @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 = {});
Result<std::vector<RegisterCandidate>> detect_candidates(Netlist* nl, const std::vector<DetectionConfiguration>& configs, u32 min_state_size = 40, const std::vector<Gate*>& start_ffs = {});
} // namespace hawkeye

template<>
Expand Down
141 changes: 141 additions & 0 deletions plugins/hawkeye/include/hawkeye/register_candidate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// 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;
class Net;

namespace hawkeye
{
class RegisterCandidate
{
public:
RegisterCandidate() = default;
~RegisterCandidate() = default;

/**
* Construct a state register candidate from the state register of a round-based implementation.
*
* @param[in] round_reg - The state register.
*/
RegisterCandidate(const std::set<Gate*>& round_reg);

/**
* Construct a state register candidate from the state register of a round-based implementation.
*
* @param[in] round_reg - The state register.
*/
RegisterCandidate(std::set<Gate*>&& round_reg);

/**
* Construct a state register 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.
*/
RegisterCandidate(const std::set<Gate*>& in_reg, const std::set<Gate*>& out_reg);

/**
* Construct a state register 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.
*/
RegisterCandidate(std::set<Gate*>&& in_reg, std::set<Gate*>&& out_reg);

bool operator==(const RegisterCandidate& rhs) const;
bool operator<(const RegisterCandidate& 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_input_reg() const;

/**
* Get the candidate's output register.
*
* @returns The output register of the candidate.
*/
const std::set<Gate*>& get_output_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
Original file line number Diff line number Diff line change
Expand Up @@ -25,61 +25,32 @@

#pragma once

#include "hal_core/utilities/result.h"

#include <set>
#include "hal_core/defines.h"
#include "hawkeye/register_candidate.h"

namespace hal
{
class Netlist;
class Gate;
class Net;

namespace hawkeye
{
class Candidate
class StateCandidate
{
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);
StateCandidate() = default;
~StateCandidate() = default;

/**
* Construct a crypto candidate from the state register of a round-based implementation.
* Computes a state candidate from the previously identified register candidate.
* The netlist of this candidate will be a partial copy of the original netlist, comprising only the gates belonging to the registers and the logic computing the next state.
*
* @param[in] round_reg - The state register.
* @param[in] candidate - The register candidate.
* @returns The state candidate on success, an error otherwise.
*/
Candidate(std::set<Gate*>&& round_reg);
static Result<std::unique_ptr<StateCandidate>> from_register_candidate(RegisterCandidate* candidate);

/**
* 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.
* Get the netlist of the state candidate. The netlist will be a partial copy of the netlist of the register candidate.
*
* @return The netlist of the candidate.
* @returns The netlist.
*/
Netlist* get_netlist() const;

Expand All @@ -90,13 +61,6 @@ namespace hal
*/
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.
*
Expand Down Expand Up @@ -146,27 +110,17 @@ namespace hal
*/
const std::set<Net*>& get_state_outputs() const;

/**
* Isolate the round function including the input and output registers as well as the combinational logic in between.
*/
void isolate_round_function();

private:
/**
* The netlist to which the candidate belongs.
*/
Netlist* m_netlist;
std::unique_ptr<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.
*/
Expand Down
Loading

0 comments on commit 2312184

Please sign in to comment.