-
Notifications
You must be signed in to change notification settings - Fork 99
/
Makefile
executable file
·368 lines (303 loc) · 14.6 KB
/
Makefile
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#### Makefile for compilation on Unix-like operative systems ####
CC=clang
ifeq "$(CC)" "gcc"
COMPILER=gcc
else ifeq "$(CC)" "clang"
COMPILER=clang
endif
ARCHITECTURE=_AMD64_
USE_OPT_LEVEL=_FAST_
ifeq "$(ARCH)" "x64"
ARCHITECTURE=_AMD64_
USE_OPT_LEVEL=_FAST_
else ifeq "$(ARCH)" "x86"
ARCHITECTURE=_X86_
USE_OPT_LEVEL=_GENERIC_
else ifeq "$(ARCH)" "s390x"
ARCHITECTURE=_S390X_
USE_OPT_LEVEL=_GENERIC_
else ifeq "$(ARCH)" "ARM"
ARCHITECTURE=_ARM_
USE_OPT_LEVEL=_GENERIC_
ARM_TARGET=YES
else ifeq "$(ARCH)" "ARM64"
ARCHITECTURE=_ARM64_
USE_OPT_LEVEL=_FAST_
ARM_TARGET=YES
else ifeq "$(ARCH)" "M1"
ARCHITECTURE=_ARM64_
USE_OPT_LEVEL=_FAST_
endif
ifeq "$(OPT_LEVEL)" "GENERIC"
USE_OPT_LEVEL=_GENERIC_
endif
ifeq "$(ARM_TARGET)" "YES"
ARM_SETTING=-lrt
endif
ifeq "$(ARCHITECTURE)" "_AMD64_"
ifeq "$(USE_OPT_LEVEL)" "_FAST_"
MULX=-D _MULX_
ifeq "$(USE_MULX)" "FALSE"
MULX=
else
ADX=-D _ADX_
ifeq "$(USE_ADX)" "FALSE"
ADX=
endif
endif
endif
endif
AR=ar rcs
RANLIB=ranlib
ADDITIONAL_SETTINGS=-march=native
ifeq "$(CC)" "clang"
ifeq "$(ARM_TARGET)" "YES"
ADDITIONAL_SETTINGS=
endif
endif
ifeq "$(ARCHITECTURE)" "_S390X_"
ADDITIONAL_SETTINGS=-march=z10
endif
VALGRIND_CFLAGS=
ifeq "$(DO_VALGRIND_CHECK)" "TRUE"
VALGRIND_CFLAGS= -g -O0 -DDO_VALGRIND_CHECK
endif
ifeq "$(EXTRA_CFLAGS)" ""
CFLAGS= -O3 # Optimization option by default
else
CFLAGS= $(EXTRA_CFLAGS)
endif
CFLAGS+= $(VALGRIND_CFLAGS)
CFLAGS+= -std=gnu11 -Wall $(ADDITIONAL_SETTINGS) -D $(ARCHITECTURE) -D __NIX__ -D $(USE_OPT_LEVEL) $(MULX) $(ADX) -Wno-missing-braces -Wno-logical-not-parentheses
LDFLAGS=-lm
ifeq "$(USE_OPT_LEVEL)" "_GENERIC_"
EXTRA_OBJECTS_434=objs434/fp_generic.o
EXTRA_OBJECTS_503=objs503/fp_generic.o
EXTRA_OBJECTS_610=objs610/fp_generic.o
EXTRA_OBJECTS_751=objs751/fp_generic.o
else ifeq "$(USE_OPT_LEVEL)" "_FAST_"
ifeq "$(ARCHITECTURE)" "_AMD64_"
EXTRA_OBJECTS_434=objs434/fp_x64.o objs434/fp_x64_asm.o
EXTRA_OBJECTS_503=objs503/fp_x64.o objs503/fp_x64_asm.o
EXTRA_OBJECTS_610=objs610/fp_x64.o objs610/fp_x64_asm.o
EXTRA_OBJECTS_751=objs751/fp_x64.o objs751/fp_x64_asm.o
else ifeq "$(ARCHITECTURE)" "_ARM64_"
EXTRA_OBJECTS_434=objs434/fp_arm64.o objs434/fp_arm64_asm.o
EXTRA_OBJECTS_503=objs503/fp_arm64.o objs503/fp_arm64_asm.o
EXTRA_OBJECTS_610=objs610/fp_arm64.o objs610/fp_arm64_asm.o
EXTRA_OBJECTS_751=objs751/fp_arm64.o objs751/fp_arm64_asm.o
endif
endif
OBJECTS_434=objs434/P434.o $(EXTRA_OBJECTS_434) objs/random.o objs/fips202.o
OBJECTS_503=objs503/P503.o $(EXTRA_OBJECTS_503) objs/random.o objs/fips202.o
OBJECTS_610=objs610/P610.o $(EXTRA_OBJECTS_610) objs/random.o objs/fips202.o
OBJECTS_751=objs751/P751.o $(EXTRA_OBJECTS_751) objs/random.o objs/fips202.o
OBJECTS_434_COMP=objs434comp/P434_compressed.o $(EXTRA_OBJECTS_434) objs/random.o objs/fips202.o
OBJECTS_503_COMP=objs503comp/P503_compressed.o $(EXTRA_OBJECTS_503) objs/random.o objs/fips202.o
OBJECTS_610_COMP=objs610comp/P610_compressed.o $(EXTRA_OBJECTS_610) objs/random.o objs/fips202.o
OBJECTS_751_COMP=objs751comp/P751_compressed.o $(EXTRA_OBJECTS_751) objs/random.o objs/fips202.o
all: lib434 lib503 lib610 lib751 lib434comp lib503comp lib610comp lib751comp tests_p434 tests_p503 tests_p610 tests_p751
objs434/%.o: src/P434/%.c
@mkdir -p $(@D)
$(CC) -c $(CFLAGS) $< -o $@
objs503/%.o: src/P503/%.c
@mkdir -p $(@D)
$(CC) -c $(CFLAGS) $< -o $@
objs610/%.o: src/P610/%.c
@mkdir -p $(@D)
$(CC) -c $(CFLAGS) $< -o $@
objs751/%.o: src/P751/%.c
@mkdir -p $(@D)
$(CC) -c $(CFLAGS) $< -o $@
objs434comp/%.o: src/P434/%.c
@mkdir -p $(@D)
$(CC) -c $(CFLAGS) $< -o $@
objs503comp/%.o: src/P503/%.c
@mkdir -p $(@D)
$(CC) -c $(CFLAGS) $< -o $@
objs610comp/%.o: src/P610/%.c
@mkdir -p $(@D)
$(CC) -c $(CFLAGS) $< -o $@
objs751comp/%.o: src/P751/%.c
@mkdir -p $(@D)
$(CC) -c $(CFLAGS) $< -o $@
ifeq "$(USE_OPT_LEVEL)" "_GENERIC_"
objs434/fp_generic.o: src/P434/generic/fp_generic.c
$(CC) -c $(CFLAGS) src/P434/generic/fp_generic.c -o objs434/fp_generic.o
objs503/fp_generic.o: src/P503/generic/fp_generic.c
$(CC) -c $(CFLAGS) src/P503/generic/fp_generic.c -o objs503/fp_generic.o
objs610/fp_generic.o: src/P610/generic/fp_generic.c
$(CC) -c $(CFLAGS) src/P610/generic/fp_generic.c -o objs610/fp_generic.o
objs751/fp_generic.o: src/P751/generic/fp_generic.c
$(CC) -c $(CFLAGS) src/P751/generic/fp_generic.c -o objs751/fp_generic.o
else ifeq "$(USE_OPT_LEVEL)" "_FAST_"
ifeq "$(ARCHITECTURE)" "_AMD64_"
objs434/fp_x64.o: src/P434/AMD64/fp_x64.c
$(CC) -c $(CFLAGS) src/P434/AMD64/fp_x64.c -o objs434/fp_x64.o
objs434/fp_x64_asm.o: src/P434/AMD64/fp_x64_asm.S
$(CC) -c $(CFLAGS) src/P434/AMD64/fp_x64_asm.S -o objs434/fp_x64_asm.o
objs503/fp_x64.o: src/P503/AMD64/fp_x64.c
$(CC) -c $(CFLAGS) src/P503/AMD64/fp_x64.c -o objs503/fp_x64.o
objs503/fp_x64_asm.o: src/P503/AMD64/fp_x64_asm.S
$(CC) -c $(CFLAGS) src/P503/AMD64/fp_x64_asm.S -o objs503/fp_x64_asm.o
objs610/fp_x64.o: src/P610/AMD64/fp_x64.c
$(CC) -c $(CFLAGS) src/P610/AMD64/fp_x64.c -o objs610/fp_x64.o
objs610/fp_x64_asm.o: src/P610/AMD64/fp_x64_asm.S
$(CC) -c $(CFLAGS) src/P610/AMD64/fp_x64_asm.S -o objs610/fp_x64_asm.o
objs751/fp_x64.o: src/P751/AMD64/fp_x64.c
$(CC) -c $(CFLAGS) src/P751/AMD64/fp_x64.c -o objs751/fp_x64.o
objs751/fp_x64_asm.o: src/P751/AMD64/fp_x64_asm.S
$(CC) -c $(CFLAGS) src/P751/AMD64/fp_x64_asm.S -o objs751/fp_x64_asm.o
else ifeq "$(ARCHITECTURE)" "_ARM64_"
objs434/fp_arm64.o: src/P434/ARM64/fp_arm64.c
$(CC) -c $(CFLAGS) src/P434/ARM64/fp_arm64.c -o objs434/fp_arm64.o
objs434/fp_arm64_asm.o: src/P434/ARM64/fp_arm64_asm.S
$(CC) -c $(CFLAGS) src/P434/ARM64/fp_arm64_asm.S -o objs434/fp_arm64_asm.o
objs503/fp_arm64.o: src/P503/ARM64/fp_arm64.c
$(CC) -c $(CFLAGS) src/P503/ARM64/fp_arm64.c -o objs503/fp_arm64.o
objs503/fp_arm64_asm.o: src/P503/ARM64/fp_arm64_asm.S
$(CC) -c $(CFLAGS) src/P503/ARM64/fp_arm64_asm.S -o objs503/fp_arm64_asm.o
objs610/fp_arm64.o: src/P610/ARM64/fp_arm64.c
$(CC) -c $(CFLAGS) src/P610/ARM64/fp_arm64.c -o objs610/fp_arm64.o
objs610/fp_arm64_asm.o: src/P610/ARM64/fp_arm64_asm.S
$(CC) -c $(CFLAGS) src/P610/ARM64/fp_arm64_asm.S -o objs610/fp_arm64_asm.o
objs751/fp_arm64.o: src/P751/ARM64/fp_arm64.c
$(CC) -c $(CFLAGS) src/P751/ARM64/fp_arm64.c -o objs751/fp_arm64.o
objs751/fp_arm64_asm.o: src/P751/ARM64/fp_arm64_asm.S
$(CC) -c $(CFLAGS) src/P751/ARM64/fp_arm64_asm.S -o objs751/fp_arm64_asm.o
endif
endif
objs/random.o: src/random/random.c
@mkdir -p $(@D)
$(CC) -c $(CFLAGS) src/random/random.c -o objs/random.o
objs/fips202.o: src/sha3/fips202.c
$(CC) -c $(CFLAGS) src/sha3/fips202.c -o objs/fips202.o
lib434: $(OBJECTS_434)
rm -rf lib434 sike434 sidh434
mkdir lib434 sike434 sidh434
$(AR) lib434/libsidh.a $^
$(RANLIB) lib434/libsidh.a
lib503: $(OBJECTS_503)
rm -rf lib503 sike503 sidh503
mkdir lib503 sike503 sidh503
$(AR) lib503/libsidh.a $^
$(RANLIB) lib503/libsidh.a
lib610: $(OBJECTS_610)
rm -rf lib610 sike610 sidh610
mkdir lib610 sike610 sidh610
$(AR) lib610/libsidh.a $^
$(RANLIB) lib610/libsidh.a
lib751: $(OBJECTS_751)
rm -rf lib751 sike751 sidh751
mkdir lib751 sike751 sidh751
$(AR) lib751/libsidh.a $^
$(RANLIB) lib751/libsidh.a
lib434comp: $(OBJECTS_434_COMP)
rm -rf lib434comp sike434_compressed sidh434_compressed
mkdir lib434comp sike434_compressed sidh434_compressed
$(AR) lib434comp/libsidh.a $^
$(RANLIB) lib434comp/libsidh.a
lib503comp: $(OBJECTS_503_COMP)
rm -rf lib503comp sike503_compressed sidh503_compressed
mkdir lib503comp sike503_compressed sidh503_compressed
$(AR) lib503comp/libsidh.a $^
$(RANLIB) lib503comp/libsidh.a
lib610comp: $(OBJECTS_610_COMP)
rm -rf lib610comp sike610_compressed sidh610_compressed
mkdir lib610comp sike610_compressed sidh610_compressed
$(AR) lib610comp/libsidh.a $^
$(RANLIB) lib610comp/libsidh.a
lib751comp: $(OBJECTS_751_COMP)
rm -rf lib751comp sike751_compressed sidh751_compressed
mkdir lib751comp sike751_compressed sidh751_compressed
$(AR) lib751comp/libsidh.a $^
$(RANLIB) lib751comp/libsidh.a
# AES
AES_OBJS=objs/aes.o objs/aes_c.o
objs/%.o: tests/aes/%.c
@mkdir -p $(@D)
$(CC) -c $(CFLAGS) $< -o $@
lib434_for_KATs: $(OBJECTS_434) $(AES_OBJS)
$(AR) lib434/libsidh_for_testing.a $^
$(RANLIB) lib434/libsidh_for_testing.a
lib503_for_KATs: $(OBJECTS_503) $(AES_OBJS)
$(AR) lib503/libsidh_for_testing.a $^
$(RANLIB) lib503/libsidh_for_testing.a
lib610_for_KATs: $(OBJECTS_610) $(AES_OBJS)
$(AR) lib610/libsidh_for_testing.a $^
$(RANLIB) lib610/libsidh_for_testing.a
lib751_for_KATs: $(OBJECTS_751) $(AES_OBJS)
$(AR) lib751/libsidh_for_testing.a $^
$(RANLIB) lib751/libsidh_for_testing.a
lib434comp_for_KATs: $(OBJECTS_434_COMP) $(AES_OBJS)
$(AR) lib434comp/libsidh_for_testing.a $^
$(RANLIB) lib434comp/libsidh_for_testing.a
lib503comp_for_KATs: $(OBJECTS_503_COMP) $(AES_OBJS)
$(AR) lib503comp/libsidh_for_testing.a $^
$(RANLIB) lib503comp/libsidh_for_testing.a
lib610comp_for_KATs: $(OBJECTS_610_COMP) $(AES_OBJS)
$(AR) lib610comp/libsidh_for_testing.a $^
$(RANLIB) lib610comp/libsidh_for_testing.a
lib751comp_for_KATs: $(OBJECTS_751_COMP) $(AES_OBJS)
$(AR) lib751comp/libsidh_for_testing.a $^
$(RANLIB) lib751comp/libsidh_for_testing.a
tests_p434: lib434 lib434comp lib434_for_KATs lib434comp_for_KATs
$(CC) $(CFLAGS) -L./lib434 tests/arith_tests-p434.c tests/test_extras.c -lsidh $(LDFLAGS) -o arith_tests-p434 $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib434 tests/test_SIDHp434.c tests/test_extras.c -lsidh $(LDFLAGS) -o sidh434/test_SIDH $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib434 tests/test_SIKEp434.c tests/test_extras.c -lsidh $(LDFLAGS) -o sike434/test_SIKE $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib434comp tests/test_SIDHp434_compressed.c tests/test_extras.c -lsidh $(LDFLAGS) -o sidh434_compressed/test_SIDH $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib434comp tests/test_SIKEp434_compressed.c tests/test_extras.c -lsidh $(LDFLAGS) -o sike434_compressed/test_SIKE $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib434 tests/PQCtestKAT_kem434.c tests/rng/rng.c -lsidh_for_testing $(LDFLAGS) -o sike434/PQCtestKAT_kem $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib434comp tests/PQCtestKAT_kem434_compressed.c tests/rng/rng.c -lsidh_for_testing $(LDFLAGS) -o sike434_compressed/PQCtestKAT_kem $(ARM_SETTING)
tests_p503: lib503 lib503comp lib503_for_KATs lib503comp_for_KATs
$(CC) $(CFLAGS) -L./lib503 tests/arith_tests-p503.c tests/test_extras.c -lsidh $(LDFLAGS) -o arith_tests-p503 $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib503 tests/test_SIDHp503.c tests/test_extras.c -lsidh $(LDFLAGS) -o sidh503/test_SIDH $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib503 tests/test_SIKEp503.c tests/test_extras.c -lsidh $(LDFLAGS) -o sike503/test_SIKE $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib503comp tests/test_SIDHp503_compressed.c tests/test_extras.c -lsidh $(LDFLAGS) -o sidh503_compressed/test_SIDH $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib503comp tests/test_SIKEp503_compressed.c tests/test_extras.c -lsidh $(LDFLAGS) -o sike503_compressed/test_SIKE $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib503 tests/PQCtestKAT_kem503.c tests/rng/rng.c -lsidh_for_testing $(LDFLAGS) -o sike503/PQCtestKAT_kem $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib503comp tests/PQCtestKAT_kem503_compressed.c tests/rng/rng.c -lsidh_for_testing $(LDFLAGS) -o sike503_compressed/PQCtestKAT_kem $(ARM_SETTING)
tests_p610: lib610 lib610comp lib610_for_KATs lib610comp_for_KATs
$(CC) $(CFLAGS) -L./lib610 tests/arith_tests-p610.c tests/test_extras.c -lsidh $(LDFLAGS) -o arith_tests-p610 $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib610 tests/test_SIDHp610.c tests/test_extras.c -lsidh $(LDFLAGS) -o sidh610/test_SIDH $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib610 tests/test_SIKEp610.c tests/test_extras.c -lsidh $(LDFLAGS) -o sike610/test_SIKE $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib610comp tests/test_SIDHp610_compressed.c tests/test_extras.c -lsidh $(LDFLAGS) -o sidh610_compressed/test_SIDH $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib610comp tests/test_SIKEp610_compressed.c tests/test_extras.c -lsidh $(LDFLAGS) -o sike610_compressed/test_SIKE $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib610 tests/PQCtestKAT_kem610.c tests/rng/rng.c -lsidh_for_testing $(LDFLAGS) -o sike610/PQCtestKAT_kem $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib610comp tests/PQCtestKAT_kem610_compressed.c tests/rng/rng.c -lsidh_for_testing $(LDFLAGS) -o sike610_compressed/PQCtestKAT_kem $(ARM_SETTING)
tests_p751: lib751 lib751comp lib751_for_KATs lib751comp_for_KATs
$(CC) $(CFLAGS) -L./lib751 tests/arith_tests-p751.c tests/test_extras.c -lsidh $(LDFLAGS) -o arith_tests-p751 $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib751 tests/test_SIDHp751.c tests/test_extras.c -lsidh $(LDFLAGS) -o sidh751/test_SIDH $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib751 tests/test_SIKEp751.c tests/test_extras.c -lsidh $(LDFLAGS) -o sike751/test_SIKE $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib751comp tests/test_SIDHp751_compressed.c tests/test_extras.c -lsidh $(LDFLAGS) -o sidh751_compressed/test_SIDH $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib751comp tests/test_SIKEp751_compressed.c tests/test_extras.c -lsidh $(LDFLAGS) -o sike751_compressed/test_SIKE $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib751 tests/PQCtestKAT_kem751.c tests/rng/rng.c -lsidh_for_testing $(LDFLAGS) -o sike751/PQCtestKAT_kem $(ARM_SETTING)
$(CC) $(CFLAGS) -L./lib751comp tests/PQCtestKAT_kem751_compressed.c tests/rng/rng.c -lsidh_for_testing $(LDFLAGS) -o sike751_compressed/PQCtestKAT_kem $(ARM_SETTING)
check: tests_p434 tests_p503 tests_p610 tests_p751
test434:
ifeq "$(DO_VALGRIND_CHECK)" "TRUE"
valgrind --tool=memcheck --error-exitcode=1 --max-stackframe=20480000 sike434/test_SIKE
else
sike434/test_SIKE
endif
test503:
ifeq "$(DO_VALGRIND_CHECK)" "TRUE"
valgrind --tool=memcheck --error-exitcode=1 --max-stackframe=20480000 sike503/test_SIKE
else
sike503/test_SIKE
endif
test610:
ifeq "$(DO_VALGRIND_CHECK)" "TRUE"
valgrind --tool=memcheck --error-exitcode=1 --max-stackframe=20480000 sike610/test_SIKE
else
sike610/test_SIKE
endif
test751:
ifeq "$(DO_VALGRIND_CHECK)" "TRUE"
valgrind --tool=memcheck --error-exitcode=1 --max-stackframe=20480000 sike751/test_SIKE
else
sike751/test_SIKE
endif
.PHONY: clean
clean:
rm -rf *.req objs434* objs503* objs610* objs751* objs lib434* lib503* lib610* lib751* sidh434* sidh503* sidh610* sidh751* sike434* sike503* sike610* sike751* arith_tests-*