sboxgates

sboxgates: A program for finding low gate count implementations of S-boxes - Published in JOSS (2021)

https://github.com/dansarie/sboxgates

Science Score: 93.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 14 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org, zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

cryptanalysis cuda logic-circuit mpi

Scientific Fields

Earth and Environmental Sciences Physical Sciences - 40% confidence
Last synced: 6 months ago · JSON representation

Repository

Program for finding low gate count implementations of S-boxes.

Basic Info
  • Host: GitHub
  • Owner: dansarie
  • License: gpl-3.0
  • Language: C
  • Default Branch: master
  • Homepage:
  • Size: 395 KB
Statistics
  • Stars: 40
  • Watchers: 5
  • Forks: 18
  • Open Issues: 2
  • Releases: 3
Topics
cryptanalysis cuda logic-circuit mpi
Created about 9 years ago · Last pushed over 1 year ago
Metadata Files
Readme License

README.md

sboxgates

DOI DOI License: GPL v3 Build Status Coverage Status

Program for finding low gate count implementations of S-boxes. S-boxes are often the only nonlinear components in modern block ciphers. Thus, low gate count implementations can be useful for cryptanalysis and fast implementations in hardware or software.

The algorithm used is described in Kwan, Matthew: "Reducing the Gate Count of Bitslice DES." IACR Cryptology ePrint Archive 2000 (2000): 51. Improvements from the GitHub project SBOXDiscovery have been added. The program supports searching for gates using any subset of the 16 standard two-input boolean gates. Additionally, the program also supports 3-bit LUTs. The latter can be used to find efficient implementations for use on Nvidia GPUs that support the LOP3.LUT instruction, or on FPGAs.

Graph representation of output bit 0 of DES S1 generated with sboxgates and Graphviz

Graph representation of output bit 0 of DES S1

Dependencies

Build

The following commands will build sboxgates on Debian-based Linux distributions, such as Ubuntu.

sudo apt-get install cmake graphviz libmpich-dev libxml2-dev mpich mkdir build cd build cmake .. make

Test

Tests are run automatically by Travis CI on each new commit. The tests are documented in the testing script .travis.yml. Code coverage reports are available from Coveralls.

Run

This program uses MPI for parallelization and should generally be run with the mpirun utility. Graph generation without LUTs (i.e. without the --lut argument) is not parallelized and the program can safely be run without MPI in those cases. The number of processes to use for the parallelized operations can be selected using the -n flag to mpirun. man mpirun should provide documentation on the options available for controlling execution and parallelization

The --help command line argument will display a brief list of command line options. The only required argument is the path of an S-box file. S-box files are text files that contain an S-box lookup table in hex format, with the values separated by whitespace. See rijndael.txt for how the AES S-box is represented.

Generated graphs are saved as XML files, using the schema specified in gates.xsd. They should be fairly easy to understand since each gate in the generated graph is represented by one tag. The output files are named according to the pattern A-B-C-D-E.xml where A is the number of output bits, B the number of gates, C the SAT metric (if applicable), D the output bit numbers in the order they were added to the graph, and E a simple hash of the particular graph.

The program can convert the XML files to C or CUDA functions. This is enabled by the -c argument. Graphs that include at least one LUT are converted to CUDA functions and graphs without LUTs are converted to C functions. For visualization of the generated graphs, they can be converted to Graphviz DOT format with the -d argument.

Command examples

Generate a logic circuit representation of the Rijndael S-box: ./sboxgates ../sboxes/rijndael.txt

Generate a LUT circuit for output bit 0 of the Rijndael S-box: mpirun ./sboxgates --lut --single-output 0 ../sboxes/rijndael.txt

Generate a LUT circuit for output bit 0 of the Rijndael S-box using 8 processes for the parallelized search: mpirun -n 8 ./sboxgates --lut --single-output 0 ../sboxes/rijndael.txt

Visualize a generated circuit with Graphviz: ./sboxgates -d 1-067-162-3-c32281db.xml | dot -Tpng > 1-067-162-3-c32281db.png

Convert a generated circuit to C/CUDA: ./sboxgates -c 1-067-162-3-c32281db.xml > 1-067-162-3-c32281db.c

Single output

It is possible to generate graphs for just a single output bit of the S-box by using the --single-output argument followed by a bit number. The least significant output bit is bit 0. This can, for example, be used to generate separate functions for each single bit in an S-box to reduce register pressure in bitslicing implementations.

Graphs can be built one output at a time by combining the --single-output with --graph to load a previously generated graph. This can be used to manually control the build order and to keep the total build time down.

Multiple iterations

The --iterations argument can be used to make the program do more than one search iteration for each output bit. This will often result in smaller output graphs being found, at the cost of much longer search time. It is most suitable for use together with --single-output.

Selecting gates

The --available-gates command line argument is used to specify the two-input gates gates that are available for the search. The argument value is a bitfield, where each bit represents one gate type. To specify the gates to be used, add up their values from the table below and pass the sum as the value of the --available-gates argument. If no such argument is specified, the default is 194, i.e. AND, OR, and XOR. The --append-not flag can also be used to increase the number of gates used for the search, by generating versions of the available gates with inverted outputs. This can both increase and decrease the size of generated graphs.

When the --verbose flag is used, the program starts by printing out the 2- and 3-input gates that have been generated and will be used for the search. Generation with LUTs will always include all 3-input gates, regardless of the result of this generation.

| Gate | Value | | ----------- | ----- | | FALSE | 1 | | AND | 2 | | A AND NOT B | 4 | | A | 8 | | NOT A AND B | 16 | | B | 32 | | XOR | 64 | | OR | 128 | | NOR | 256 | | XNOR | 512 | | NOT B | 1024 | | A OR NOT B | 2048 | | NOT A | 4096 | | NOT A OR B | 8192 | | NAND | 16384 | | TRUE | 32768 |

Metrics

The default metric used in the search is the number of gates in the generated graph. An alternative metric can be selected with the --sat-metric argument. Instead of minimizing the number of gates, it attempts to minimize the size of the CNF representation of the generated graph. It is meant to improve the performance when the graph is used with SAT solvers.

Permuting S-boxes

The --permute argument can be used to permute the S-box input by XORing it with a constant value, so that the S-box value for input value I becomes S(I ^ V), where V is the permutation value.

Contributing

Reports on bugs and other issues are welcome. Please don't hesitate to open a new issue.

Likewise, contrubutions to code or documentation in the form of pull requests are welcomed.

Citing

If you use sboxgates in a report or scientific publication, please cite the corresponding article in the Journal of Open Source Software:

Dansarie, M., (2021). sboxgates: A program for finding low gate count implementations of S-boxes. Journal of Open Source Software, 6(62), 2946, https://doi.org/10.21105/joss.02946

@article{Dansarie2021, doi = {10.21105/joss.02946}, url = {https://doi.org/10.21105/joss.02946}, year = {2021}, publisher = {The Open Journal}, volume = {6}, number = {62}, pages = {2946}, author = {Marcus Dansarie}, title = {sboxgates: A program for finding low gate count implementations of S-boxes}, journal = {Journal of Open Source Software} }

License and Copyright

Copyright 2017-2021 Marcus Dansarie.

This project is licensed under the GNU General Public License – see the LICENSE file for details.

Owner

  • Name: Marcus Dansarie
  • Login: dansarie
  • Kind: user
  • Location: Stockholm, Sweden

JOSS Publication

sboxgates: A program for finding low gate count implementations of S-boxes
Published
June 16, 2021
Volume 6, Issue 62, Page 2946
Authors
Marcus Dansarie ORCID
Swedish Defence University, University of Skövde, Sweden
Editor
Viviane Pons ORCID
Tags
S-box cryptography

GitHub Events

Total
  • Issues event: 1
  • Watch event: 3
  • Issue comment event: 2
  • Push event: 1
Last Year
  • Issues event: 1
  • Watch event: 3
  • Issue comment event: 2
  • Push event: 1

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 165
  • Total Committers: 2
  • Avg Commits per committer: 82.5
  • Development Distribution Score (DDS): 0.006
Past Year
  • Commits: 2
  • Committers: 1
  • Avg Commits per committer: 2.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Marcus Dansarie m****s@d****e 164
Aram a****m@f****l 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 17
  • Total pull requests: 2
  • Average time to close issues: 6 months
  • Average time to close pull requests: 23 days
  • Total issue authors: 5
  • Total pull request authors: 2
  • Average comments per issue: 1.59
  • Average comments per pull request: 0.5
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • dansarie (9)
  • richs27 (4)
  • aczid (2)
  • acad2 (1)
  • Pitifulparadox (1)
Pull Request Authors
  • dansarie (1)
  • aczid (1)
Top Labels
Issue Labels
enhancement (3) bug (3)
Pull Request Labels