-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
242 lines (197 loc) · 7.67 KB
/
main.c
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
The eXtended Keccak Code Package (XKCP)
https://github.com/XKCP/XKCP
Implementation by Gilles Van Assche and Ronny Van Keer, hereby denoted as "the implementer".
For more information, feedback or questions, please refer to the Keccak Team website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "testPerformance.h"
#include "testXooPerformance.h"
#define MEASURE_PERF
#if defined(EMBEDDED)
void assert(int condition)
{
if (!condition)
{
for ( ; ; ) ;
}
}
#endif
#if defined(EMBEDDED) && defined(__ARMCC_VERSION) && defined(MEASURE_PERF)
void CycleMeasureRestart( void );
uint32_t CycleMeasureGet( void );
struct
{
uint32_t overhead;
uint32_t Xoodoo_6;
uint32_t Xoodoo_12;
uint32_t Xoofff_MaskDerivation;
uint32_t Xoofff_Compress1;
uint32_t Xoofff_Compress2;
uint32_t Xoofff_Compress4;
uint32_t Xoofff_CompressL;
uint32_t Xoofff_Expand1;
uint32_t Xoofff_Expand2;
uint32_t Xoofff_Expand4;
uint32_t Xoofff_ExpandL;
uint32_t XoofffWBC_Enc1;
uint32_t XoofffWBC_Enc2;
uint32_t XoofffWBC_Enc4;
uint32_t XoofffWBC_EncL;
} performanceInCycles;
#endif
int Xoo( void )
{
#if !defined(EMBEDDED)
testXooPerformance();
#endif
#if defined(EMBEDDED) && defined(__ARMCC_VERSION) && defined(MEASURE_PERF)
{
CycleMeasureRestart();
performanceInCycles.overhead = CycleMeasureGet();
{
ALIGN(Xoodoo_stateAlignment) uint8_t state[Xoodoo_stateSizeInBytes];
Xoodoo_StaticInitialize();
Xoodoo_Initialize(state);
CycleMeasureRestart();
Xoodoo_Permute_6rounds(state);
performanceInCycles.Xoodoo_6 = CycleMeasureGet();
performanceInCycles.Xoodoo_6 -= performanceInCycles.overhead;
CycleMeasureRestart();
Xoodoo_Permute_12rounds(state);
performanceInCycles.Xoodoo_12 = CycleMeasureGet();
performanceInCycles.Xoodoo_12 -= performanceInCycles.overhead;
}
{
#define Xoofff_Block (3*4*32)
Xoofff_Instance xp;
BitSequence k[128/8];
BitSequence AD[16];
BitSequence tag[32];
BitSequence data[4*Xoofff_Block];
BitSequence input[4*Xoofff_Block];
BitSequence output[4*Xoofff_Block];
memset(k, 0x55, sizeof(k));
memset(data, 0xAA, sizeof(data));
memset(input, 0x33, sizeof(data));
memset(output, 0x88, sizeof(data));
memset(AD, 0xCC, sizeof(AD));
memset(tag, 0x22, sizeof(tag));
CycleMeasureRestart();
Xoofff_MaskDerivation(&xp, k, 128);
performanceInCycles.Xoofff_MaskDerivation = CycleMeasureGet();
performanceInCycles.Xoofff_MaskDerivation -= performanceInCycles.overhead;
/*
** Compress
*/
CycleMeasureRestart();
Xoofff_Compress(&xp, data, 1*Xoofff_Block-8, Xoofff_FlagInit|Xoofff_FlagLastPart);
performanceInCycles.Xoofff_Compress1 = CycleMeasureGet();
performanceInCycles.Xoofff_Compress1 -= performanceInCycles.overhead;
CycleMeasureRestart();
Xoofff_Compress(&xp, data, 2*Xoofff_Block-8, Xoofff_FlagInit|Xoofff_FlagLastPart);
performanceInCycles.Xoofff_Compress2 = CycleMeasureGet();
performanceInCycles.Xoofff_Compress2 -= performanceInCycles.overhead;
CycleMeasureRestart();
Xoofff_Compress(&xp, data, 4*Xoofff_Block-8, Xoofff_FlagInit|Xoofff_FlagLastPart);
performanceInCycles.Xoofff_Compress4 = CycleMeasureGet();
performanceInCycles.Xoofff_Compress4 -= performanceInCycles.overhead;
performanceInCycles.Xoofff_CompressL = (performanceInCycles.Xoofff_Compress4 - performanceInCycles.Xoofff_Compress2) / 2;
/*
** Expand
*/
Xoofff_Compress(&xp, data, 1*Xoofff_Block-8, Xoofff_FlagInit|Xoofff_FlagLastPart);
CycleMeasureRestart();
Xoofff_Expand(&xp, data, 1*Xoofff_Block-8, Xoofff_FlagLastPart);
performanceInCycles.Xoofff_Expand1 = CycleMeasureGet();
performanceInCycles.Xoofff_Expand1 -= performanceInCycles.overhead;
Xoofff_Compress(&xp, data, 1*Xoofff_Block-8, Xoofff_FlagInit|Xoofff_FlagLastPart);
CycleMeasureRestart();
Xoofff_Expand(&xp, data, 2*Xoofff_Block-8, Xoofff_FlagLastPart);
performanceInCycles.Xoofff_Expand2 = CycleMeasureGet();
performanceInCycles.Xoofff_Expand2 -= performanceInCycles.overhead;
Xoofff_Compress(&xp, data, 1*Xoofff_Block-8, Xoofff_FlagInit|Xoofff_FlagLastPart);
CycleMeasureRestart();
Xoofff_Expand(&xp, data, 4*Xoofff_Block-8, Xoofff_FlagLastPart);
performanceInCycles.Xoofff_Expand4 = CycleMeasureGet();
performanceInCycles.Xoofff_Expand4 -= performanceInCycles.overhead;
performanceInCycles.Xoofff_ExpandL = (performanceInCycles.Xoofff_Expand4 - performanceInCycles.Xoofff_Expand2) / 2;
/*
** WBC
*/
CycleMeasureRestart();
XoofffWBC_Encipher(&xp, input, output, 1*Xoofff_Block-8, AD, sizeof(AD)*8);
performanceInCycles.XoofffWBC_Enc1 = CycleMeasureGet();
performanceInCycles.XoofffWBC_Enc1 -= performanceInCycles.overhead;
CycleMeasureRestart();
XoofffWBC_Encipher(&xp, input, output, 2*Xoofff_Block-8, AD, sizeof(AD)*8);
performanceInCycles.XoofffWBC_Enc2 = CycleMeasureGet();
performanceInCycles.XoofffWBC_Enc2 -= performanceInCycles.overhead;
CycleMeasureRestart();
XoofffWBC_Encipher(&xp, input, output, 4*Xoofff_Block-8, AD, sizeof(AD)*8);
performanceInCycles.XoofffWBC_Enc4 = CycleMeasureGet();
performanceInCycles.XoofffWBC_Enc4 -= performanceInCycles.overhead;
performanceInCycles.XoofffWBC_EncL = (performanceInCycles.XoofffWBC_Enc4 - performanceInCycles.XoofffWBC_Enc2) / 2;
#undef Xoofff_Block
}
}
#endif
#if defined(EMBEDDED)
for (;;);
#else
return ( 0 );
#endif
}
void printHelp()
{
printf("Usage: Benchmarks command(s), where the commands can be\n");
printf(" --help or -h To display this page\n");
printf(" --all or -a All benchmarsk\n");
printf(" --Keccak Benchmark of all Keccak-p-based functions\n");
printf(" --Xoodoo Benchmark of all Xoodoo-based functions\n");
}
int process(int argc, char* argv[])
{
int i;
int help = 0;
int K = 0;
int X = 0;
if (argc == 1)
help = 1;
for(i=1; i<argc; i++) {
if ((strcmp("--help", argv[i]) == 0) || (strcmp("-h", argv[i]) == 0))
help = 1;
else if ((strcmp("--all", argv[i]) == 0) || (strcmp("-a", argv[i]) == 0))
K = X = 1;
else if ((strcmp("--Keccak", argv[i]) == 0) || (strcmp("-c", argv[i]) == 0))
K = 1;
else if (strcmp("--Xoodoo", argv[i]) == 0)
X = 1;
else {
printf("Unrecognized command '%s'\n", argv[i]);
return -1;
}
}
if (help) {
printHelp();
return 0;
}
if (K) {
testPerformance();
}
if (X) {
Xoo();
}
return 0;
}
int main(int argc, char* argv[])
{
return process(argc, argv);
}