HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
hal::hawkeye::SBoxDatabase Class Reference

Database of known S-boxes. More...

#include </home/runner/work/hal/hal/plugins/hawkeye/include/hawkeye/sbox_database.h>

Collaboration diagram for hal::hawkeye::SBoxDatabase:
Collaboration graph

Public Member Functions

 SBoxDatabase ()=default
 Construct an empty S-box database. More...
 
 SBoxDatabase (const std::map< std::string, std::vector< u8 >> &sboxes)
 Construct an S-box database from the given S-boxes. More...
 
 ~SBoxDatabase ()=default
 Destruct the S-box database. More...
 
Result< std::monostate > add (const std::string &name, const std::vector< u8 > &sbox)
 Add an S-box to the database. More...
 
Result< std::monostate > add (const std::map< std::string, std::vector< u8 >> &sboxes)
 Add multiple S-boxes to the database. More...
 
Result< std::monostate > load (const std::filesystem::path &file_path, bool overwrite=false)
 Load S-boxes from a file and add them to the existing database. More...
 
Result< std::monostate > store (const std::filesystem::path &file_path) const
 Store the S-box database to a database file. More...
 
Result< std::string > lookup (const std::vector< u8 > &sbox) const
 Attempt to look up an S-box in the database. More...
 
void print () const
 Print the database. More...
 

Static Public Member Functions

static Result< SBoxDatabasefrom_file (const std::filesystem::path &file_path)
 Construct an S-box database from file. More...
 
static std::vector< u8compute_linear_representative (const std::vector< u8 > &sbox)
 Compute the linear representative of the given S-box. More...
 

Detailed Description

Database of known S-boxes.

This class holds and manages known S-boxes and allows to perform efficient S-box lookups in the database.

Definition at line 49 of file sbox_database.h.

Constructor & Destructor Documentation

◆ SBoxDatabase() [1/2]

hal::hawkeye::SBoxDatabase::SBoxDatabase ( )
default

Construct an empty S-box database.

Referenced by from_file().

◆ SBoxDatabase() [2/2]

hal::hawkeye::SBoxDatabase::SBoxDatabase ( const std::map< std::string, std::vector< u8 >> &  sboxes)

Construct an S-box database from the given S-boxes.

Parameters
[in]sboxes- A map from S-box name to the respective S-box.

Definition at line 279 of file sbox_database.cpp.

References add().

◆ ~SBoxDatabase()

hal::hawkeye::SBoxDatabase::~SBoxDatabase ( )
default

Destruct the S-box database.

Member Function Documentation

◆ add() [1/2]

Result< std::monostate > hal::hawkeye::SBoxDatabase::add ( const std::map< std::string, std::vector< u8 >> &  sboxes)

Add multiple S-boxes to the database.

Parameters
[in]sboxes- A map from S-box name to the respective S-box.
Returns
Ok() on success, an error otherwise.

Definition at line 320 of file sbox_database.cpp.

References add(), ERR, name, and OK.

◆ add() [2/2]

Result< std::monostate > hal::hawkeye::SBoxDatabase::add ( const std::string &  name,
const std::vector< u8 > &  sbox 
)

Add an S-box to the database.

Parameters
[in]name- The name of the S-box.
[in]sbox- The S-box.
Returns
Ok() on success, an error otherwise.

Definition at line 297 of file sbox_database.cpp.

References compute_linear_representative(), ERR, name, and OK.

Referenced by add(), and SBoxDatabase().

◆ compute_linear_representative()

std::vector< u8 > hal::hawkeye::SBoxDatabase::compute_linear_representative ( const std::vector< u8 > &  sbox)
static

Compute the linear representative of the given S-box.

Parameters
[in]sbox- The S-box.
Returns
The linear representative.

Definition at line 1174 of file sbox_database.cpp.

References hal::state, x, and y.

Referenced by add(), lookup(), and hal::PYBIND11_PLUGIN().

◆ from_file()

Result< SBoxDatabase > hal::hawkeye::SBoxDatabase::from_file ( const std::filesystem::path &  file_path)
static

Construct an S-box database from file.

Parameters
[in]file_path- The path from which to load the S-box database file.
Returns
The S-box database on success, an error otherwise.

Definition at line 284 of file sbox_database.cpp.

References ERR, OK, and SBoxDatabase().

Referenced by hal::PYBIND11_PLUGIN().

◆ load()

Result< std::monostate > hal::hawkeye::SBoxDatabase::load ( const std::filesystem::path &  file_path,
bool  overwrite = false 
)

Load S-boxes from a file and add them to the existing database.

Parameters
[in]file_path- The path from which to load the S-box database file.
[in]overwrite- Set true to overwrite existing database, false otherwise. Defaults to false.
Returns
Ok() on success, an error otherwise.

Definition at line 332 of file sbox_database.cpp.

References ERR, and OK.

◆ lookup()

Result< std::string > hal::hawkeye::SBoxDatabase::lookup ( const std::vector< u8 > &  sbox) const

Attempt to look up an S-box in the database.

Parameters
[in]sbox- The S-box to look for.
Returns
Ok() and the S-box name on success, an error otherwise.

Definition at line 439 of file sbox_database.cpp.

References compute_linear_representative(), ERR, and OK.

Referenced by hal::hawkeye::identify_sbox().

◆ print()

void hal::hawkeye::SBoxDatabase::print ( ) const

Print the database.

Definition at line 474 of file sbox_database.cpp.

References name.

Referenced by hal::PYBIND11_PLUGIN().

◆ store()

Result< std::monostate > hal::hawkeye::SBoxDatabase::store ( const std::filesystem::path &  file_path) const

Store the S-box database to a database file.

Parameters
[in]file_path- The path to where to store the S-box database file.
Returns
Ok() on success, an error otherwise.

Definition at line 385 of file sbox_database.cpp.

References ERR, and name.


The documentation for this class was generated from the following files: