Skip to content

Commit 0f71a57

Browse files
Large rewrites and improvements
1 parent f193b91 commit 0f71a57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+76736
-2958
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.o/
2+
/.rpsc.out
3+
/.vraps.out
4+
/srcTest/.transform.expected.*

README.md

+64-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,75 @@
1-
# Random Probing Security checker
1+
# Random Probing Security Checker
22

3-
To get the coefficient:
3+
This tool checks the random probing security properties of a given gadget.
44

5-
./exec.sh -s 'file gadget .sage' -c 'max coefficient' --rps --rpc='t'
5+
## Execution
66

7-
To generate the ISW multiplications, inside ./gadgets/:
7+
To compile
88

9-
./isw_mul_generator.py 'num shares' > 'output file'
9+
./compile.sh
1010

11-
To directly get the coefficient for a ISW multiplication (at least in bash):
11+
To get the coefficient for Random Probing Security:
1212

13-
./exec.sh -s <(gadgets/isw_mul_generator.py 'num shares') -c 'max coefficient' --rps --rpc='t'
13+
./rpsc --sage 'file gadget .sage' -c 'max coefficient' 'op'
1414

15+
Where op can be either '--rpsCor1', '--rpsCor2', '--rpsCor3'.
16+
17+
To get the coefficient for Random Probing Composability:
18+
19+
./rpsc --sage 'file gadget .sage' -c 'max coefficient' 'op' -t 'max number of safely leaking shares'
20+
21+
Where op can be either '--rpcCor1', '--rpcCor2'.
22+
23+
To get informations on a gadget and an internal representation that can be used to check if it was read correctly do:
24+
25+
./rpsc --sage 'file gadget .sage' --printGadget
26+
27+
For the .py that generate .sage, it's possible to do (at least in bash):
28+
29+
./rpsc --sage <('generator.py' 'parameters') -c 'max coefficient' 'op'
30+
31+
The '--help' prints this readme and terminates, the '--license' prints the GPLv3 and terminates.
32+
33+
34+
TODO: is the -c mandatory?
1535

1636
Note: In the .sage files:
1737
- all assignments must have exactly one operation (+ or *)
18-
- no input must be used directly as output
38+
- no input must be used directly as output TODO: is it still valid?
1939
- no input must be written to
40+
41+
42+
## Graphs
43+
44+
the paper's graphs were made with (and by fiddling the internal parameters):
45+
46+
./plot_test_fn.py vraps/otpoePaper_add.py__3/rpsVraps/*.success
47+
48+
./plot_time_acc.py rps isw_mul.py__3:{3:green,5:blue,6:orange,8:black}
49+
./plot_time_acc.py rps vrapsPaper_mul.sage:{3:green,4:blue,5:orange,6:black}
50+
51+
./plot_time_acc.py rps vrapsPaper_add_v3.sage:{3:green,5:blue,7:orange,9:black,12:fuchsia,14:purple}
52+
./plot_time_acc.py rps otpoePaper_small_add.sage:{3:green,5:blue,7:orange,9:black}
53+
./plot_time_acc.py rps otpoePaper_add.py__3:{3:green,5:blue,7:orange,9:black}
54+
55+
./plot_time_acc.py rps vrapsPaper_copy.sage:{3:green,5:blue,7:orange,12:fuchsia,13:black}
56+
./plot_test_fn.py {test,vraps}/vrapsPaper_copy.sage/rps*/13.success
57+
58+
The 'plot_time_acc.py' script will create the file 'toDelete_out.png'
59+
60+
TODO: what about the vraps's result?
61+
62+
## Tests
63+
64+
TODO
65+
66+
## Copyright
67+
68+
Copyright (C) 2022 Giuseppe Manzoni.
69+
70+
This program 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.
71+
72+
This program 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.
73+
74+
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
75+

compile.sh

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/bin/sh
2+
#This file is part of the program Random Probing Security Checker, which checks the random probing security properties of a given gadget
3+
#Copyright (C) 2022 Giuseppe Manzoni
4+
#This program 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.
5+
#This program 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.
6+
#You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
7+
8+
9+
oDir='.o'
10+
srcDir='src'
11+
out='rpsc'
12+
13+
14+
if [ "$1" = "--dbg" ] ; then
15+
isDbg=1
16+
else
17+
isDbg=0
18+
fi
19+
20+
if [ "$1" = "--check" ] ; then
21+
isCheck=1
22+
else
23+
isCheck=0
24+
fi
25+
26+
27+
mkdir ${oDir} 2>/dev/null
28+
touch ${oDir}/toDelete
29+
rm ${oDir}/*
30+
31+
supportedChar="-_a-zA-Z0-9 :/<>.,:;\`\"'(){}#?+*"
32+
if [ $(cat gpl-3.0.txt | sed "s/[${supportedChar}]//g" | grep -v "^$" | wc -l) -ne 0 ] ; then
33+
echo "The license was modified, and now it has unsupported characters."
34+
cat gpl-3.0.txt | sed "s/[${supportedChar}]//g" | grep -v "^$"
35+
exit 1
36+
fi
37+
echo "char license[] = \\" > ${oDir}/license.c
38+
cat gpl-3.0.txt | sed 's/"/\\"/g;s/^/ "/;s/$/\\n"\\/' >> ${oDir}/license.c
39+
echo ";" >> ${oDir}/license.c
40+
41+
42+
if [ $(cat README.md | sed "s/[${supportedChar}]//g" | grep -v "^$" | wc -l) -ne 0 ] ; then
43+
echo "The README.md was modified, and now it has unsupported characters."
44+
cat README.md | sed "s/[${supportedChar}]//g" | grep -v "^$"
45+
exit 1
46+
fi
47+
echo "char help[] = \\" > ${oDir}/help.c
48+
cat README.md | sed 's/"/\\"/g;s/^/ "/;s/$/\\n"\\/' >> ${oDir}/help.c
49+
echo ";" >> ${oDir}/help.c
50+
51+
52+
# MAX_NUM_MASKED_INS must be <= 64
53+
54+
preprocFlags=""
55+
preprocFlags="${preprocFlags} -DMAX_NUM_TOT_INS=126"
56+
preprocFlags="${preprocFlags} -DMEM_NUM_ALLOCS=10000"
57+
preprocFlags="${preprocFlags} -DHASHMAP_INITIAL_BITS=7"
58+
preprocFlags="${preprocFlags} -DHASHMAP_CONTIGUOUS_BITS=3"
59+
preprocFlags="${preprocFlags} -DHASHMAP_HASH_ATTEMPTS=5"
60+
preprocFlags="${preprocFlags} -DHASHMAP_SAVE_HASH_RATIO=5"
61+
preprocFlags="${preprocFlags} -DHASHCACHE_BITS=22"
62+
preprocFlags="${preprocFlags} -DHASHCACHE_WAYS=4"
63+
preprocFlags="${preprocFlags} -DFN_CMP_STEP=0.0001"
64+
preprocFlags="${preprocFlags} -DMAX_LEN_VAR_NAMES=100"
65+
preprocFlags="${preprocFlags} -DMAX_FILE_SIZE=1000000"
66+
67+
if [ "$isDbg" -eq 1 ] ; then
68+
dbgLvl="DBG_LVL_MAX"
69+
dbgLvl="DBG_LVL_DETAILED"
70+
preprocFlags="${preprocFlags} -DDBG_MEM=${dbgLvl}"
71+
dbgLvl="DBG_LVL_MINIMAL"
72+
preprocFlags="${preprocFlags} -DDBG_HASHMAP=${dbgLvl}"
73+
dbgLvl="DBG_LVL_TOFIX"
74+
preprocFlags="${preprocFlags} -DDBG_WRAPPER=${dbgLvl}"
75+
preprocFlags="${preprocFlags} -DDBG_ROWHASHED=${dbgLvl}"
76+
preprocFlags="${preprocFlags} -DDBG_HASH=${dbgLvl}"
77+
preprocFlags="${preprocFlags} -DDBG_BDD=${dbgLvl}"
78+
preprocFlags="${preprocFlags} -DDBG_HASHCACHE=${dbgLvl}"
79+
preprocFlags="${preprocFlags} -DDBG_BITARRAY=${dbgLvl}"
80+
preprocFlags="${preprocFlags} -DDBG_ROWINFO=${dbgLvl}"
81+
preprocFlags="${preprocFlags} -DDBG_SUBROWHASHED=${dbgLvl}"
82+
preprocFlags="${preprocFlags} -DDBG_ROWINDEXEDSET=${dbgLvl}"
83+
preprocFlags="${preprocFlags} -DDBG_TRANSFORMGENERATOR=${dbgLvl}"
84+
dbgLvl="DBG_LVL_NONE"
85+
elif [ "$isCheck" -eq 1 ] ; then
86+
preprocFlags="${preprocFlags} -DDBG_HASHMAP=DBG_LVL_TOFIX"
87+
preprocFlags="${preprocFlags} -DDBG_MEM=DBG_LVL_TOFIX"
88+
preprocFlags="${preprocFlags} -DDBG_HASH=DBG_LVL_TOFIX"
89+
preprocFlags="${preprocFlags} -DDBG_BDD=DBG_LVL_TOFIX"
90+
preprocFlags="${preprocFlags} -DDBG_HASHCACHE=DBG_LVL_TOFIX"
91+
preprocFlags="${preprocFlags} -DDBG_BITARRAY=DBG_LVL_TOFIX"
92+
preprocFlags="${preprocFlags} -DDBG_WRAPPER=DBG_LVL_TOFIX"
93+
preprocFlags="${preprocFlags} -DDBG_ROWHASHED=DBG_LVL_TOFIX"
94+
preprocFlags="${preprocFlags} -DDBG_ROWINFO=DBG_LVL_TOFIX"
95+
preprocFlags="${preprocFlags} -DDBG_SUBROWHASHED=DBG_LVL_TOFIX"
96+
preprocFlags="${preprocFlags} -DDBG_ROWINDEXEDSET=DBG_LVL_TOFIX"
97+
preprocFlags="${preprocFlags} -DDBG_TRANSFORMGENERATOR=DBG_LVL_TOFIX"
98+
else
99+
preprocFlags="${preprocFlags} -DDBG_HASHMAP=DBG_LVL_NONE"
100+
preprocFlags="${preprocFlags} -DDBG_MEM=DBG_LVL_NONE"
101+
preprocFlags="${preprocFlags} -DDBG_HASH=DBG_LVL_NONE"
102+
preprocFlags="${preprocFlags} -DDBG_BDD=DBG_LVL_NONE"
103+
preprocFlags="${preprocFlags} -DDBG_HASHCACHE=DBG_LVL_NONE"
104+
preprocFlags="${preprocFlags} -DDBG_BITARRAY=DBG_LVL_NONE"
105+
preprocFlags="${preprocFlags} -DDBG_WRAPPER=DBG_LVL_NONE"
106+
preprocFlags="${preprocFlags} -DDBG_ROWHASHED=DBG_LVL_NONE"
107+
preprocFlags="${preprocFlags} -DDBG_ROWINFO=DBG_LVL_NONE"
108+
preprocFlags="${preprocFlags} -DDBG_SUBROWHASHED=DBG_LVL_NONE"
109+
preprocFlags="${preprocFlags} -DDBG_ROWINDEXEDSET=DBG_LVL_NONE"
110+
preprocFlags="${preprocFlags} -DDBG_TRANSFORMGENERATOR=DBG_LVL_NONE"
111+
fi
112+
113+
optimizeFlag=""
114+
optimizeFlag="${optimizeFlag} -march=native"
115+
optimizeFlag="${optimizeFlag} -mtune=native"
116+
optimizeFlag="${optimizeFlag} -flto"
117+
optimizeFlag="${optimizeFlag} -O3"
118+
optimizeFlag="${optimizeFlag} -fwhole-program"
119+
120+
warningFlag=""
121+
warningFlag="${warningFlag} -Wall"
122+
warningFlag="${warningFlag} -Wextra"
123+
warningFlag="${warningFlag} -Winline"
124+
warningFlag="${warningFlag} -Werror"
125+
126+
standardFlag="--std=gnu2x"
127+
128+
libFlag=""
129+
libFlag="${libFlag} -lpthread"
130+
131+
for name in $(cd ${srcDir} ; ls *.c | sed 's/.c$//') ; do
132+
gcc -c $optimizeFlag $warningFlag $standardFlag $preprocFlags "${srcDir}/${name}.c" -o "${oDir}/src_${name}.o" || exit 1
133+
done
134+
for name in $(cd ${oDir} ; ls *.c | sed 's/.c$//') ; do
135+
gcc -c $optimizeFlag $warningFlag $standardFlag $preprocFlags "${oDir}/${name}.c" -o "${oDir}/o_${name}.o" || exit 1
136+
done
137+
138+
gcc $optimizeFlag $warningFlag $standardFlag ${oDir}/*.o $libFlag -o $out || exit 1
139+
140+
echo "Done."

0 commit comments

Comments
 (0)