Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeDisciplina authored Feb 21, 2019
1 parent fd35097 commit 3d995ce
Show file tree
Hide file tree
Showing 44 changed files with 18,456 additions and 16 deletions.
888 changes: 888 additions & 0 deletions AffineMatrixColPEBox.hpp

Large diffs are not rendered by default.

887 changes: 887 additions & 0 deletions AffineMatrixRowPEBox.hpp

Large diffs are not rendered by default.

579 changes: 579 additions & 0 deletions HadamardMatrix.hpp

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
CC=g++ -fopenmp
CFLAGS= -mavx2 -std=c++14 -O3 -Wall -Wextra -pedantic
LDFLAGS=
EXEC=evaluate evaluate_single search_GC_n3 search_GC_n4 search_depth_n3 search_depth_n4 filter_n3 filter_n4 gen_n3 gen_n4

all: $(EXEC)

evaluate: evaluate.o
$(CC) -o $@ $^ $(LDFLAGS) -DEVA

evaluate.o: main.cpp
$(CC) -o $@ -c $< $(CFLAGS) -DEVA

evaluate_single: evaluate_single.o
$(CC) -o $@ $^ $(LDFLAGS) -DEVA_Single

evaluate_single.o: main.cpp
$(CC) -o $@ -c $< $(CFLAGS) -DEVA_Single

search_GC_n3: search_GC_n3.o
$(CC) -o $@ $^ $(LDFLAGS) -DGC -DSIZEINBIT=3

search_GC_n3.o: main.cpp
$(CC) -o $@ -c $< $(CFLAGS) -DGC -DSIZEINBIT=3

search_GC_n4: search_GC_n4.o
$(CC) -o $@ $^ $(LDFLAGS) -DGC -DSIZEINBIT=4

search_GC_n4.o: main.cpp
$(CC) -o $@ -c $< $(CFLAGS) -DGC -DSIZEINBIT=4


search_depth_n3: search_depth_n3.o
$(CC) -o $@ $^ $(LDFLAGS) -DDEPTH -DSIZEINBIT=3

search_depth_n3.o: main.cpp
$(CC) -o $@ -c $< $(CFLAGS) -DDEPTH -DSIZEINBIT=3

search_depth_n4: search_depth_n4.o
$(CC) -o $@ $^ $(LDFLAGS) -DDEPTH -DSIZEINBIT=4

search_depth_n4.o: main.cpp
$(CC) -o $@ -c $< $(CFLAGS) -DDEPTH -DSIZEINBIT=4


filter_n3: filter_n3.o
$(CC) -o $@ $^ $(LDFLAGS) -DFILTER -DSIZEINBIT=3

filter_n3.o: main.cpp
$(CC) -o $@ -c $< $(CFLAGS) -DFILTER -DSIZEINBIT=3

filter_n4: filter_n4.o
$(CC) -o $@ $^ $(LDFLAGS) -DFILTER -DSIZEINBIT=4

filter_n4.o: main.cpp
$(CC) -o $@ -c $< $(CFLAGS) -DFILTER -DSIZEINBIT=4


gen_n3: gen_n3.o
$(CC) -o $@ $^ $(LDFLAGS) -DGEN -DSIZEINBIT=3

gen_n3.o: main.cpp
$(CC) -o $@ -c $< $(CFLAGS) -DGEN -DSIZEINBIT=3

gen_n4: gen_n4.o
$(CC) -o $@ $^ $(LDFLAGS) -DGEN -DSIZEINBIT=4

gen_n4.o: main.cpp
$(CC) -o $@ -c $< $(CFLAGS) -DGEN -DSIZEINBIT=4


clean:
rm -rf *.o

mrproper: clean
rm -rf $(EXEC)
rm test_faster
rm test_lighter

gencheck:
find ./R -maxdepth 1 -name "*.c" -print > results.c
$(CC) $(CFLAGS) genTest.cpp -o genTest && ./genTest

checkfaster:
$(CC) $(CFLAGS) faster_test.cpp -o test_faster && ./test_faster

checklighter:
$(CC) $(CFLAGS) faster_test.cpp -o test_lighter && ./test_lighter
41 changes: 41 additions & 0 deletions MakefileSage
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# To build, rename this file as Makefile
# Compile inside the Sage shell: sage -sh -c make
# Then start Sage: from peigen import Lighter
# : A = Lighter()
# : A.evaluate_4bit()
# Similiar for Faster: from peigen import Faster
CC= g++
CXXFLAGS= -fopenmp -mavx2 -std=c++14 -O3 -fPIC -fwrapv -fno-strict-aliasing \
-Wall -Wextra -pedantic -g -pg \
-I$(SAGE_LOCAL)/include \
-I$(SAGE_LOCAL)/include/python2.7
LDFLAGS = -fopenmp -lm -lstdc++

OUTPUT_OPTION = -MMD -MP -o $@
-include $(DEP)

EXEC = peigen

SRC = peigen.cpp
OBJ = $(SRC:.cpp=.o)
DEP = $(SRC:.cpp=.d)

all: peigen.so

peigen.cpp: peigen.pyx peigen.pxd
cython --cplus $<

$(OBJ):$(SRC)

peigen.so: $(OBJ)
$(CC) -shared -pthread -o peigen.so $^ $(LDFLAGS)

$(EXEC): $(OBJ)
$(CC) $(LDFLAGS) $^ -o $@

clean:
rm -f $(OBJ) $(DEP) $(EXEC)

.PHONY: clean

-include $(DEP)
62 changes: 62 additions & 0 deletions OptimalSboxes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* PEIGEN: a Platform for Evaluation, Implementation, and Generation of S-boxes
*
* Copyright 2019 by
* Zhenzhen Bao <baozhenzhen10[at]gmail.com>
* Jian Guo <guojian[at]ntu.edu.sg>
* San Ling <lingsan[at]ntu.edu.sg>
* Yu Sasaki <yu[dot]sasaki[dot][email protected]>
*
* This platform is developed based on the open source application
* <http://jeremy.jean.free.fr/pub/fse2018_layer_implementations.tar.gz>
* Optimizing Implementations of Lightweight Building Blocks
*
* Copyright 2017 by
* Jade Tourteaux <Jade[dot]Tourteaux[at]gmail.com>
* Jérémy Jean <Jean[dot]Jeremy[at]gmail.com>
*
* We follow the same copyright policy.
*
* This file is part of some open source application.
*
* Some open source application is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* Some open source application is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*
* @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
*/

#ifndef GSBOXES_H__
#define GSBOXES_H__

#define OPTIMAL_G4_N 16

const ALIGNED_TYPE_(uint8_t, 16) G4[OPTIMAL_G4_N][16] = {
/* Optimal_S0 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 11, 12, 9, 3, 14, 10, 5},
/* Optimal_S1 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 11, 14, 3, 5, 9, 10, 12},
/* Optimal_S2 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 11, 14, 3, 10, 12, 5, 9},
/* Optimal_S3 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 12, 5, 3, 10, 14, 11, 9},
/* Optimal_S4 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 12, 9, 11, 10, 14, 5, 3},
/* Optimal_S5 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 12, 11, 9, 10, 14, 3, 5},
/* Optimal_S6 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 12, 11, 9, 10, 14, 5, 3},
/* Optimal_S7 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 12, 14, 11, 10, 9, 3, 5},
/* Optimal_S8 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 14, 9, 5, 10, 11, 3, 12},
/* Optimal_S9 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 14, 11, 3, 5, 9, 10, 12},
/* Optimal_S10 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 14, 11, 5, 10, 9, 3, 12},
/* Optimal_S11 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 14, 11, 10, 5, 9, 12, 3},
/* Optimal_S12 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 14, 11, 10, 9, 3, 12, 5},
/* Optimal_S13 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 14, 12, 9, 5, 11, 10, 3},
/* Optimal_S14 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 14, 12, 11, 3, 9, 5, 10},
/* Optimal_S15 */ {0, 1, 2, 13, 4, 7, 15, 6, 8, 14, 12, 11, 9, 3, 10, 5}
};

#endif //GSBOXES_H__
27 changes: 11 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PEIGEN: a Platform for Evaluation, Implementation, and Generation of S-boxes
# PEIGEN: a Platform for Evaluation, Implementation, and Generation of S-boxes

PEIGEN is a tool for study S-boxes.

Expand Down Expand Up @@ -145,25 +145,25 @@ Concrete usage are as follows.
- same as in [LIGHTER](http://jeremy.jean.free.fr/pub/fse2018_layer_implementations.tar.gz), if `[-a]` is not enabled, available logic gates should be explicitly added in this command line (and weight of each gate should be specified in the provided configure file):

--not1

--and2

--nand2

--or2

--nor2

--nand3

--nor3

--xor2

--xnor2

--maoi1

--moai1

- use `sboxn_GC.pre_compute(args);` to precompute the graph, this will expand the graph from the Identity function, with parameters encoded in `args`, and store the generated graph in binary files. For each configuration (the library of gates `-f <file>` and the limitation for precomputation `-c <value>`), this can be done once for all. Thus, if this has been done, the generated binary files are stored and available, we can directly call the search function.
Expand Down Expand Up @@ -293,33 +293,28 @@ Concrete usage are as follows.
- Sorry for the inconvenience again, but for small efficiency gain, bitslicing of the S-boxes is done in little endian byte and little endian bit order (this is inconsistent with that in [LIGHTER](http://jeremy.jean.free.fr/pub/fse2018_layer_implementations.tar.gz)): the least significant value is placed at the leftmost side in memory and, the least significant bit of the value is placed at the leftmost side in the value, e.g., suppose the LUT:

LUT in hexadecimal (**big endian byte** order and **little endian bit** order):

| 0x0 | 0x1 | 0x2 | 0x3 | 0x4 | 0x5 | 0x6 | 0x7 | 0x8 | 0x9 | 0xa | 0xb | 0xc | 0xd | 0xe | 0xf |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 0xc | 0x5 | 0x6 | 0xb | 0x9 | 0x0 | 0xa | 0xd | 0x3 | 0xe | 0xf | 0x8 | 0x4 | 0x7 | 0x1 | 0x2 |

LUT in binary (**big endian byte** order and **little endian bit** order):

| 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| 1100 | 0101 | 0110 | 1011 | 1001 | 0000 | 1010 | 1101 | 0011 | 1110 | 1111 | 1000 | 0100 | 0111 | 0001 | 0010 |

In PEIGEN, bitslicing is done as follows:

LUT in binary in memory (**little endian byte** order and **little endian bit** order):

| 1111 | 1110 | 1101 | 1100 | 1011 | 1010 | 1001 | 1000 | 0111 | 0110 | 0101 | 0100 | 0011 | 0010 | 0001 | 0000 |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| 0010 | 0001 | 0111 | 0100 | 1000 | 1111 | 1110 | 0011 | 1101 | 1010 | 0000 | 1001 | 1011 | 0110 | 0101 | 1100 |

Bitslicing (**little endian byte** order and **little endian bit** order):

| 1111111100000000 | 1111000011110000 | 1100110011001100 | 1010101010101010 |
| ---------------- | ---------------- | ---------------- | ---------------- |
| 0000111011011001 | 0011011010000111 | 1010011101001100 | 0110010110011010 |

Condensed bitsliced representation (directly indicate memory):

| ff00_f0f0_cccc_aaaa |
| ------------------- |
| 0ed9_3687_a74c_659a |
Expand Down
15 changes: 15 additions & 0 deletions STM65nm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
not1_cost=0.5
and2_cost=1.5
nand2_cost=1.00
or2_cost=1.5
nor2_cost=1.00
xor2_cost=2.00
xnor2_cost=2.00
maoi1_cost=2.50
moai1_cost=2.50
nand3_cost=1.5
nor3_cost=1.5
and3_cost=2
or3_cost=2
andn2_cost=1.5
orn2_cost=1.5
30 changes: 30 additions & 0 deletions TSMC65nm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
not1_cost=0.5
and2_cost=1.5
nand2_cost=1.00
or2_cost=1.5
nor2_cost=1.00
xor2_cost=3.00
xnor2_cost=3.00
maoi1_cost=2.50
moai1_cost=2.50
nand3_cost=1.5
nor3_cost=1.5
and3_cost=2
or3_cost=2
andn2_cost=1.5
orn2_cost=1.5
#not1_cost=0.5
#and2_cost=1.5
#nand2_cost=1.00
#or2_cost=1.5
#nor2_cost=1.00
#xor2_cost=2.00
#xnor2_cost=2.00
#maoi1_cost=2.50
#moai1_cost=2.50
#nand3_cost=1.5
#nor3_cost=1.5
#and3_cost=2
#or3_cost=2
#andn2_cost=1.5
#orn2_cost=1.5
15 changes: 15 additions & 0 deletions UMC180nm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
not1_cost=0.67
and2_cost=1.33
nand2_cost=1.00
or2_cost=1.33
nor2_cost=1.00
xor2_cost=3.00
xnor2_cost=3.00
maoi1_cost=2.67
moai1_cost=2.00
nand3_cost=1.33
nor3_cost=1.33
and3_cost=2.33
or3_cost=2.33
andn2_cost=1.67
orn2_cost=1.67
Loading

0 comments on commit 3d995ce

Please sign in to comment.