-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_genlist.py
158 lines (116 loc) · 5.2 KB
/
test_genlist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python3
"""
test_genlist.py
Copyright (c) 2023 Raccoon Signature Team. See LICENSE.
=== Extract and prettyprint parameters for C code and LaTeX.
Usage:
python3 test_genlist.py c > ../ref-c/param_list.h
python3 test_genlist.py tex > param_table.tex
mv param_table.tex ../../../documents/submissions/nist-pqc-2023/sections/
"""
import sys
from racc_api import raccoon_all
if (__name__ == "__main__"):
# python3 test_genlist.py c > ../ref-c/param_list.h
if sys.argv[-1] == 'c':
print('//\tgenerated by', sys.argv[0])
for iut in raccoon_all:
print()
macro = iut.name.upper().replace('-','_')
print(f'#if defined({macro})')
print(f'#define RACC_(s) {macro}_##s')
print(f'#define RACC_NAME "{iut.name}"')
print(f'#define RACC_KAPPA {iut.bitsec}')
print(f'#define RACC_Q {iut.q}')
print(f'#define RACC_NUT {iut.nut}')
print(f'#define RACC_NUW {iut.nuw}')
print(f'#define RACC_REP {iut.rep}')
print(f'#define RACC_UT {iut.ut}')
print(f'#define RACC_UW {iut.uw}')
print(f'#define RACC_N {iut.n}')
print(f'#define RACC_K {iut.k}')
print(f'#define RACC_ELL {iut.ell}')
print(f'#define RACC_W {iut.w}')
print(f'#define RACC_D {iut.d}')
print(f'#define RACC_B22 {iut.B22}')
print(f'#define RACC_BOO {iut.Boo}')
print(f'#define RACC_PK_SZ {iut.pk_sz}')
print(f'#define RACC_SK_SZ {iut.sk_sz}')
print(f'#define RACC_SIG_SZ {iut.sig_sz}')
print(f'#endif')
# python3 test_genlist.py tex > param_table.tex
# mv param_table.tex ../../../documents/submissions/nist-pqc-2023/sections/
elif sys.argv[-1] == 'tex':
print('%\tgenerated by', sys.argv[0])
def _find_param(sec,d):
for iut in raccoon_all:
if iut.bitsec == sec and iut.d == d:
return iut
def _rowstr(l,rep_dash=True):
s = f'& {l[0]}'.ljust(18)
for i in range(1, len(l)):
if rep_dash and l[i] == l[i-1]:
s += '& ='.ljust(8)
else:
s += f'& {l[i]}'.ljust(8)
return s
# kappa is shared with all parameters
for sec in [128,192,256]:
print()
col = []
for d in [1,2,4,8,16,32]:
col += [_find_param(sec, d)]
print('\\begin{table}[H]')
print('\\begin{center}')
print('\\caption{Parameters for \\raccoon-' + str(sec)
+ ', NIST Post-Quantum security strength category '
+ str((sec-128)//32+1) + '.}')
print('\\label{tab:param-' + str(sec)+'}')
print('\n\\medskip')
print('\\begin{tabular}{c' + ('|c' * len(col)) + '}')
l = [ f'\\raccoon-{col[0].bitsec}' ]
l += [ f'{t.bitsec}-{t.d}' for t in col[1:] ]
print('Parameter'.ljust(16) + _rowstr(l) + '\\\\')
print('\\hline')
l = [ t.bitsec for t in col ]
print('$\\bitsec$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ '$2^{'+str(t.nsigqs)+'}$' for t in col ]
print('$\\nsigqueries$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.q for t in col ]
print('$q$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.n for t in col ]
print('$n$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.k for t in col ]
print('$k$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.ell for t in col ]
print('$\\ell$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.nut for t in col ]
print('$\\shiftvk$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.nuw for t in col ]
print('$\\shiftcom$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.w for t in col ]
print('$\\chalweight$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.B22 for t in col ]
print('$2^{-64}B_2^2$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.Boo for t in col ]
print('$\Boo$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.sig_sz for t in col ]
print('$|\\sig|$ (bytes)'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.pk_sz for t in col ]
print('$|\\vk|$ (bytes)'.ljust(16) + _rowstr(l) + '\\\\')
print('\\hline')
l = [ t.d for t in col ]
print('$d$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.rep for t in col ]
print('$\\rep$'.ljust(16) + _rowstr(l) + '\\\\')
l = [ t.ut for t in col ]
print('$\\ut$'.ljust(16) + _rowstr(l, False) + '\\\\')
l = [ t.uw for t in col ]
print('$\\uw$'.ljust(16) + _rowstr(l, False) + '\\\\')
l = [ t.sk_sz for t in col ]
print('$|\\sk|$ (bytes)'.ljust(16) + _rowstr(l) + '\\\\')
print('\\end{tabular}')
print('\\end{center}')
print('\\end{table}')
else:
print("use 'c' or 'tex' parameter to create parameter tables.")