-
Notifications
You must be signed in to change notification settings - Fork 147
/
Makefile.examples
402 lines (309 loc) · 21.6 KB
/
Makefile.examples
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# IMPORTANT: This file MUST NOT introduce dependencies of the
# generated .c/.rs/etc files on the source for the standalone
# binaries, as we should be able to generate the files by invoking
# this makefile directly as long as the compiled binaries are lying
# around
.SUFFIXES:
include Makefile.config
CFLAGS?=
.PHONY: \
c-files bedrock2-files rust-files go-files json-files java-files zig-files generated-files \
lite-c-files lite-bedrock2-files lite-rust-files lite-go-files lite-json-files lite-java-files lite-zig-files lite-generated-files \
update-go-pkg-cache \
test-c-files test-bedrock2-files test-rust-files test-go-files test-json-files test-java-files test-zig-files test-amd64-files test-amd64-files-lite \
only-test-c-files only-test-bedrock2-files only-test-rust-files only-test-go-files only-test-json-files only-test-java-files only-test-zig-files only-test-amd64-files only-test-amd64-files-lite \
test-go-module only-test-go-module \
javadoc only-javadoc \
#
CARGO_BUILD := cargo build
ZIG_BUILD := zig build
COPY_TO_FIAT_RUST_AND_FIAT_GO := \
AUTHORS \
CONTRIBUTORS \
COPYRIGHT \
LICENSE-MIT \
LICENSE-APACHE \
LICENSE-BSD-1
COPY_TO_FIAT_RUST := \
$(COPY_TO_FIAT_RUST_AND_FIAT_GO)
COPY_TO_FIAT_GO := \
$(COPY_TO_FIAT_RUST_AND_FIAT_GO)
C_DIR := fiat-c/src/
BEDROCK2_DIR := fiat-bedrock2/src/
RUST_DIR := fiat-rust/src/
GO_DIR := fiat-go/
JSON_DIR := fiat-json/src/
JAVA_DIR := fiat-java/src/
JAVADOC_DIR := fiat-java/doc/
ZIG_DIR := fiat-zig/src/
# Java only really supports 32-bit builds, because we have neither 64x64->64x64 multiplication, nor uint128
# Java also requires that class names match file names
# import string; print(''.join(f'$(patsubst {i}%,{i.upper()}%,' for i in string.ascii_lowercase) + '$(1)' + ')' * len(string.ascii_lowercase))
capitalize_first_letter = $(patsubst a%,A%,$(patsubst b%,B%,$(patsubst c%,C%,$(patsubst d%,D%,$(patsubst e%,E%,$(patsubst f%,F%,$(patsubst g%,G%,$(patsubst h%,H%,$(patsubst i%,I%,$(patsubst j%,J%,$(patsubst k%,K%,$(patsubst l%,L%,$(patsubst m%,M%,$(patsubst n%,N%,$(patsubst o%,O%,$(patsubst p%,P%,$(patsubst q%,Q%,$(patsubst r%,R%,$(patsubst s%,S%,$(patsubst t%,T%,$(patsubst u%,U%,$(patsubst v%,V%,$(patsubst w%,W%,$(patsubst x%,X%,$(patsubst y%,Y%,$(patsubst z%,Z%,$(1)))))))))))))))))))))))))))
split_after_non_alpha = $(shell echo '$(1)' | sed 's/\([^a-zA-Z ]\)/\1 /g')
to_title_case = $(foreach i,$(1),$(subst $(space),,$(call capitalize_first_letter,$(call split_after_non_alpha,$(i)))))
empty=
space=$(empty) $(empty)
JAVA_RENAME = $(foreach i,$(patsubst %_32,%,$(filter %_32,$(1))),Fiat$(subst $(space),,$(call to_title_case,$(subst _, ,$(i)))))
# Go places each file in a separate directory, and separates these directories by machine bitwidth
GO_RENAME_TO_KEY = $(strip $(foreach bw,32 64,$(foreach i,$(subst _,,$(patsubst %_$(bw),%,$(filter %_$(bw),$(1)))),$(bw)__SLASH__$(i)__SLASH__$(i))))
GO_KEY_TO_FILE = $(subst __SLASH__,/,$(1))
GO_FILE_TO_KEY = $(subst /,__SLASH__,$(1))
GO_RENAME_TO_FILE = $(call GO_KEY_TO_FILE,$(call GO_RENAME_TO_KEY,$(1)))
# Keys for looking up curve parameters
define add_curve_keys
# add_curve_keys curve_base BINARY_NAME description bitwidth non_bitwidth_args FUNCTIONS
$(2)_BASE_FILES += $(1)
ALL_BASE_FILES += $(1)
$(1)_BINARY_NAME:=$(2)
$(1)_DESCRIPTION:=$(3)
$(1)_BITWIDTH:=$(4)
$(1)_ARGS:=$(4) $(5)
$(1)_FUNCTIONS:=$(6)
GO_$(call GO_RENAME_TO_KEY,$(1))_BINARY_NAME:=$(2)
GO_$(call GO_RENAME_TO_KEY,$(1))_PACKAGE:=$(subst _,,$(patsubst %_32,%,$(patsubst %_64,%,$(1))))
GO_$(call GO_RENAME_TO_KEY,$(1))_BITWIDTH:=$(4)
GO_$(call GO_RENAME_TO_KEY,$(1))_ARGS:=$(4) $(5)
GO_$(call GO_RENAME_TO_KEY,$(1))_FUNCTIONS:=$(6) $(GO_EXTRA_$(7)_FUNCTIONS)
JAVA_$(call JAVA_RENAME,$(1))_BINARY_NAME:=$(2)
JAVA_$(call JAVA_RENAME,$(1))_DESCRIPTION:=$(patsubst Fiat%,%,$(call JAVA_RENAME,$(1)))
JAVA_$(call JAVA_RENAME,$(1))_BITWIDTH:=$(4)
JAVA_$(call JAVA_RENAME,$(1))_ARGS:=$(4) $(5)
JAVA_$(call JAVA_RENAME,$(1))_FUNCTIONS:=$(6)
endef
UNSATURATED_SOLINAS_FUNCTIONS := carry_mul carry_square carry add sub opp selectznz to_bytes from_bytes relax
FUNCTIONS_FOR_25519 := $(UNSATURATED_SOLINAS_FUNCTIONS) carry_scmul121666
WORD_BY_WORD_MONTGOMERY_FUNCTIONS := mul square add sub opp from_montgomery to_montgomery nonzero selectznz to_bytes from_bytes one msat divstep divstep_precomp
SOLINAS_REDUCTION_FUNCTIONS := mul square
DETTMAN_MULTIPLICATION_FUNCTIONS := mul square
UNSATURATED_SOLINAS := src/ExtractionOCaml/unsaturated_solinas
WORD_BY_WORD_MONTGOMERY := src/ExtractionOCaml/word_by_word_montgomery
DETTMAN_MULTIPLICATION := src/ExtractionOCaml/dettman_multiplication
SOLINAS_REDUCTION := src/ExtractionOCaml/solinas_reduction
UNSATURATED_SOLINAS_BASE_FILES := # p224_solinas_64
WORD_BY_WORD_MONTGOMERY_BASE_FILES := # p434_32
ALL_BASE_FILES := $(UNSATURATED_SOLINAS_BASE_FILES) $(WORD_BY_WORD_MONTGOMERY_BASE_FILES)
BASE_FILES_NEEDING_INT128 := p448_solinas_32
BASE_FILES_WITH_CODESIZE_GT_65535 := p434_32
INVALID_JAVA_BASE_FILES := $(BASE_FILES_WITH_CODESIZE_GT_65535) $(BASE_FILES_NEEDING_INT128)
INVALID_BEDROCK2_BASE_FILES := $(BASE_FILES_NEEDING_INT128)
INVALID_GO_BASE_FILES := $(BASE_FILES_NEEDING_INT128)
GO_EXTRA_UNSATURATED_SOLINAS_FUNCTIONS := carry_add carry_sub carry_opp
GO_EXTRA_WORD_BY_WORD_MONTGOMERY_FUNCTIONS :=
$(foreach bw,64 32,$(eval $(call add_curve_keys,curve25519_$(bw),UNSATURATED_SOLINAS,'25519',$(bw),'(auto)' '2^255 - 19',$(FUNCTIONS_FOR_25519),UNSATURATED_SOLINAS)))
$(eval $(call add_curve_keys,poly1305_64,UNSATURATED_SOLINAS,'poly1305',64,'3' '2^130 - 5',$(UNSATURATED_SOLINAS_FUNCTIONS),UNSATURATED_SOLINAS))
$(eval $(call add_curve_keys,poly1305_32,UNSATURATED_SOLINAS,'poly1305',32,'(auto)' '2^130 - 5',$(UNSATURATED_SOLINAS_FUNCTIONS),UNSATURATED_SOLINAS))
$(foreach bw,64 32,$(eval $(call add_curve_keys,p521_$(bw),UNSATURATED_SOLINAS,'p521',$(bw),'(auto)' '2^521 - 1',$(UNSATURATED_SOLINAS_FUNCTIONS),UNSATURATED_SOLINAS)))
## 2^224 - 2^96 + 1 ## does not bounds check
#$(eval $(call add_curve_keys,p224_solinas_64,UNSATURATED_SOLINAS,'p224',64,'4' '2^224 - 2^96 + 1',$(UNSATURATED_SOLINAS_FUNCTIONS),UNSATURATED_SOLINAS))
$(eval $(call add_curve_keys,p448_solinas_64,UNSATURATED_SOLINAS,'p448',64,'8' '2^448 - 2^224 - 1',$(UNSATURATED_SOLINAS_FUNCTIONS),UNSATURATED_SOLINAS))
$(eval $(call add_curve_keys,p448_solinas_32,UNSATURATED_SOLINAS,'p448',32,'16' '2^448 - 2^224 - 1',$(UNSATURATED_SOLINAS_FUNCTIONS),UNSATURATED_SOLINAS))
$(foreach bw,64 32,$(eval $(call add_curve_keys,p256_$(bw),WORD_BY_WORD_MONTGOMERY,'p256',$(bw),'2^256 - 2^224 + 2^192 + 2^96 - 1',$(WORD_BY_WORD_MONTGOMERY_FUNCTIONS),WORD_BY_WORD_MONTGOMERY)))
$(foreach bw,64 32,$(eval $(call add_curve_keys,secp256k1_montgomery_$(bw),WORD_BY_WORD_MONTGOMERY,'secp256k1_montgomery',$(bw),'2^256 - 2^32 - 977',$(WORD_BY_WORD_MONTGOMERY_FUNCTIONS),WORD_BY_WORD_MONTGOMERY)))
$(foreach bw,64 32,$(eval $(call add_curve_keys,p384_$(bw),WORD_BY_WORD_MONTGOMERY,'p384',$(bw),'2^384 - 2^128 - 2^96 + 2^32 - 1',$(WORD_BY_WORD_MONTGOMERY_FUNCTIONS),WORD_BY_WORD_MONTGOMERY)))
$(foreach bw,64 32,$(eval $(call add_curve_keys,p224_$(bw),WORD_BY_WORD_MONTGOMERY,'p224',$(bw),'2^224 - 2^96 + 1',$(WORD_BY_WORD_MONTGOMERY_FUNCTIONS),WORD_BY_WORD_MONTGOMERY)))
$(foreach bw,64,$(eval $(call add_curve_keys,p434_$(bw),WORD_BY_WORD_MONTGOMERY,'p434',$(bw),'2^216 * 3^137 - 1',$(WORD_BY_WORD_MONTGOMERY_FUNCTIONS),WORD_BY_WORD_MONTGOMERY))) # 32 is a bit too heavy
$(foreach bw,64 32,$(eval $(call add_curve_keys,sm2_$(bw),WORD_BY_WORD_MONTGOMERY,'sm2',$(bw),'2^256 - 2^224 - 2^96 + 2^64 - 1',$(WORD_BY_WORD_MONTGOMERY_FUNCTIONS),WORD_BY_WORD_MONTGOMERY)))
$(foreach bw,64 32,$(eval $(call add_curve_keys,curve25519_scalar_$(bw),WORD_BY_WORD_MONTGOMERY,'25519_scalar',$(bw),'2^252 + 27742317777372353535851937790883648493',$(WORD_BY_WORD_MONTGOMERY_FUNCTIONS),WORD_BY_WORD_MONTGOMERY)))
$(foreach bw,64 32,$(eval $(call add_curve_keys,p256_scalar_$(bw),WORD_BY_WORD_MONTGOMERY,'p256_scalar',$(bw),'2^256 - 2^224 + 2^192 - 89188191075325690597107910205041859247',$(WORD_BY_WORD_MONTGOMERY_FUNCTIONS),WORD_BY_WORD_MONTGOMERY)))
$(foreach bw,64 32,$(eval $(call add_curve_keys,p384_scalar_$(bw),WORD_BY_WORD_MONTGOMERY,'p384_scalar',$(bw),'2^384 - 1388124618062372383947042015309946732620727252194336364173',$(WORD_BY_WORD_MONTGOMERY_FUNCTIONS),WORD_BY_WORD_MONTGOMERY)))
$(foreach bw,64 32,$(eval $(call add_curve_keys,secp256k1_montgomery_scalar_$(bw),WORD_BY_WORD_MONTGOMERY,'secp256k1_montgomery_scalar',$(bw),'2^256 - 432420386565659656852420866394968145599',$(WORD_BY_WORD_MONTGOMERY_FUNCTIONS),WORD_BY_WORD_MONTGOMERY)))
$(foreach bw,64 32,$(eval $(call add_curve_keys,sm2_scalar_$(bw),WORD_BY_WORD_MONTGOMERY,'sm2_scalar',$(bw),'2^256 - 2^224 - 188730267045675049073202170516080344797',$(WORD_BY_WORD_MONTGOMERY_FUNCTIONS),WORD_BY_WORD_MONTGOMERY)))
$(foreach bw,64,$(eval $(call add_curve_keys,secp256k1_dettman_$(bw),DETTMAN_MULTIPLICATION,'secp256k1_dettman',$(bw),5 48 2 '2^256 - 4294968273',$(DETTMAN_MULTIPLICATION_FUNCTIONS),DETTMAN_MULTIPLICATION)))
$(foreach bw,32,$(eval $(call add_curve_keys,secp256k1_dettman_$(bw),DETTMAN_MULTIPLICATION,'secp256k1_dettman',$(bw),10 22 6 '2^256 - 4294968273',$(DETTMAN_MULTIPLICATION_FUNCTIONS),DETTMAN_MULTIPLICATION)))
$(foreach bw,64,$(eval $(call add_curve_keys,curve25519_solinas_$(bw),SOLINAS_REDUCTION,'curve25519_solinas',$(bw),'2^255 - 19',$(SOLINAS_REDUCTION_FUNCTIONS),SOLINAS_REDUCTION)))
# Files taking 30s or less
LITE_BASE_FILES := curve25519_64 poly1305_64 poly1305_32 p256_64 secp256k1_dettman_64 secp256k1_dettman_32 secp256k1_montgomery_64 p384_64 p224_32 p434_64 p448_solinas_64 secp256k1_montgomery_32 p256_32 p448_solinas_32 \
curve25519_scalar_64 p256_scalar_64 secp256k1_montgomery_scalar_64 p384_scalar_64 secp256k1_montgomery_scalar_32 p256_scalar_32
EXTRA_C_FILES := inversion/c/*_test.c
ALL_C_FILES := $(patsubst %,$(C_DIR)%.c,$(ALL_BASE_FILES))
ALL_BEDROCK2_FILES := $(patsubst %,$(BEDROCK2_DIR)%.c,$(filter-out $(INVALID_BEDROCK2_BASE_FILES),$(ALL_BASE_FILES)))
ALL_RUST_FILES := $(patsubst %,$(RUST_DIR)%.rs,$(ALL_BASE_FILES))
ALL_RUST_MODS := $(ALL_BASE_FILES)
ALL_GO_FILES := $(patsubst %,$(GO_DIR)%.go,$(call GO_RENAME_TO_FILE,$(filter-out $(INVALID_GO_BASE_FILES),$(ALL_BASE_FILES))))
ALL_JSON_FILES := $(patsubst %,$(JSON_DIR)%.json,$(ALL_BASE_FILES))
ALL_JAVA_FILES := $(patsubst %,$(JAVA_DIR)%.java,$(call JAVA_RENAME,$(filter-out $(INVALID_JAVA_BASE_FILES),$(ALL_BASE_FILES))))
ALL_ZIG_FILES := $(patsubst %,$(ZIG_DIR)%.zig,$(ALL_BASE_FILES))
LITE_C_FILES := $(patsubst %,$(C_DIR)%.c,$(LITE_BASE_FILES))
LITE_BEDROCK2_FILES := $(patsubst %,$(BEDROCK2_DIR)%.c,$(filter-out $(INVALID_BEDROCK2_BASE_FILES),$(LITE_BASE_FILES)))
LITE_RUST_FILES := $(patsubst %,$(RUST_DIR)%.rs,$(LITE_BASE_FILES))
LITE_GO_FILES := $(patsubst %,$(GO_DIR)%.go,$(call GO_RENAME_TO_FILE,$(filter-out $(INVALID_GO_BASE_FILES),$(LITE_BASE_FILES))))
LITE_JSON_FILES := $(patsubst %,$(JSON_DIR)%.json,$(LITE_BASE_FILES))
LITE_JAVA_FILES := $(patsubst %,$(JAVA_DIR)%.java,$(call JAVA_RENAME,$(filter-out $(INVALID_JAVA_BASE_FILES),$(LITE_BASE_FILES))))
LITE_ZIG_FILES := $(patsubst %,$(ZIG_DIR)%.zig,$(LITE_BASE_FILES))
BEDROCK2_UNSATURATED_SOLINAS := src/ExtractionOCaml/bedrock2_unsaturated_solinas
BEDROCK2_WORD_BY_WORD_MONTGOMERY := src/ExtractionOCaml/bedrock2_word_by_word_montgomery
BEDROCK2_DETTMAN_MULTIPLICATION := src/ExtractionOCaml/bedrock2_dettman_multiplication
BEDROCK2_SOLINAS_REDUCTION := src/ExtractionOCaml/bedrock2_solinas_reduction
C_EXTRA_ARGS := --inline --static --use-value-barrier
JSON_EXTRA_ARGS := --emit-all-casts
BEDROCK2_ARGS := --no-wide-int --widen-carry --widen-bytes --split-multiret --no-select --no-field-element-typedefs
BEDROCK2_EXTRA_CFLAGS := -Wno-error=unused-but-set-variable
RUST_EXTRA_ARGS := --inline
GO_EXTRA_ARGS_ALL := --relax-primitive-carry-to-bitwidth 32,64 --cmovznz-by-mul --internal-static --package-case flatcase --public-function-case UpperCamelCase --private-function-case camelCase --public-type-case UpperCamelCase --private-type-case camelCase --no-prefix-fiat --doc-newline-in-typedef-bounds --doc-prepend-header 'Code generated by Fiat Cryptography. DO NOT EDIT.' --doc-text-before-function-name '' --doc-text-before-type-name ''
GO_EXTRA_ARGS_64 := --no-wide-int $(GO_EXTRA_ARGS_ALL)
GO_EXTRA_ARGS_32 := $(GO_EXTRA_ARGS_ALL)
JAVA_EXTRA_ARGS_ALL := --cmovznz-by-mul --widen-carry --widen-bytes --internal-static --package-name fiat_crypto --class-case UpperCamelCase --no-field-element-typedefs
JAVA_EXTRA_ARGS_64 := --no-wide-int $(JAVA_EXTRA_ARGS_ALL)
JAVA_EXTRA_ARGS_32 := $(JAVA_EXTRA_ARGS_ALL)
ZIG_EXTRA_ARGS := --internal-static --public-function-case camelCase --private-function-case camelCase --public-type-case UpperCamelCase --private-type-case UpperCamelCase --no-prefix-fiat
.PHONY: bedrock2-extra-cflags
bedrock2-extra-cflags:
@echo "$(BEDROCK2_EXTRA_CFLAGS)"
generated-files: c-files rust-files go-files json-files java-files zig-files
lite-generated-files: lite-c-files lite-rust-files lite-go-files lite-json-files lite-java-files lite-zig-files
ifneq ($(SKIP_BEDROCK2),1)
generated-files: bedrock2-files
lite-generated-files: lite-bedrock2-files
endif
c-files: $(ALL_C_FILES)
bedrock2-files: $(ALL_BEDROCK2_FILES)
rust-files: $(ALL_RUST_FILES)
go-files: $(ALL_GO_FILES)
json-files: $(ALL_JSON_FILES)
java-files: $(ALL_JAVA_FILES)
zig-files: $(ALL_ZIG_FILES)
lite-c-files: $(LITE_C_FILES)
lite-bedrock2-files: $(LITE_BEDROCK2_FILES)
lite-rust-files: $(LITE_RUST_FILES)
lite-go-files: $(LITE_GO_FILES)
lite-json-files: $(LITE_JSON_FILES)
lite-java-files: $(LITE_JAVA_FILES)
lite-zig-files: $(LITE_ZIG_FILES)
.SECONDEXPANSION:
$(ALL_C_FILES) : $(C_DIR)%.c : $$($$($$*_BINARY_NAME))
$(SHOW)'SYNTHESIZE > $@'
$(HIDE)rm -f [email protected]
$(HIDE)($(TIMER) $($($*_BINARY_NAME)) $(C_EXTRA_ARGS) $($*_DESCRIPTION) $($*_ARGS) $($*_FUNCTIONS) && touch [email protected] || true) > [email protected]
$(HIDE)(rm [email protected] && mv [email protected] $@) || ( RV=$$?; cat [email protected]; exit $$RV )
test-c-files: $(ALL_C_FILES) $(EXTRA_C_FILES)
test-c-files only-test-c-files:
$(CC) -Wall -Wno-unused-function -Wpedantic -Werror $(CFLAGS) -c $(ALL_C_FILES) $(EXTRA_C_FILES)
$(ALL_BEDROCK2_FILES) : $(BEDROCK2_DIR)%.c : $$(BEDROCK2_$$($$*_BINARY_NAME))
$(SHOW)'SYNTHESIZE > $@'
$(HIDE)($(TIMER) $(BEDROCK2_$($*_BINARY_NAME)) --lang bedrock2 --static $(BEDROCK2_ARGS) $($*_DESCRIPTION) $($*_ARGS) $($*_FUNCTIONS) && touch [email protected] || true) > [email protected]
$(HIDE)(rm [email protected] && mv [email protected] $@) || ( RV=$$?; cat [email protected]; exit $$RV )
test-bedrock2-files: $(ALL_BEDROCK2_FILES)
test-bedrock2-files only-test-bedrock2-files:
$(CC) -Wall -Wno-unused-function -Werror $(BEDROCK2_EXTRA_CFLAGS) $(CFLAGS) -c $(ALL_BEDROCK2_FILES)
$(ALL_RUST_FILES) : $(RUST_DIR)%.rs : $$($$($$*_BINARY_NAME))
$(SHOW)'SYNTHESIZE > $@'
$(HIDE)rm -f [email protected]
$(HIDE)($(TIMER) $($($*_BINARY_NAME)) --lang Rust $(RUST_EXTRA_ARGS) $($*_DESCRIPTION) $($*_ARGS) $($*_FUNCTIONS) && touch [email protected] || true) > [email protected]
$(HIDE)(rm [email protected] && mv [email protected] $@) || ( RV=$$?; cat [email protected]; exit $$RV )
test-rust-files: $(ALL_RUST_FILES)
test-rust-files only-test-rust-files:
cd fiat-rust; $(CARGO_BUILD)
rust-files lite-rust-files: fiat-rust/src/lib.rs
fiat-rust/src/lib.rs: Makefile.examples
$(SHOW)'PRINTF > $@'
$(HIDE)(echo '// AUTOGENERATED FILE: DO NOT EDIT'; echo '#![cfg_attr(not(feature = "std"), no_std)]'; printf 'pub mod %s;\n' $(sort $(ALL_RUST_MODS))) > $@
$(ALL_ZIG_FILES) : $(ZIG_DIR)%.zig : $$($$($$*_BINARY_NAME))
$(SHOW)'SYNTHESIZE > $@'
$(HIDE)rm -f [email protected]
$(HIDE)($(TIMER) $($($*_BINARY_NAME)) --lang Zig $(ZIG_EXTRA_ARGS) --package-name $($*_DESCRIPTION) "" $($*_ARGS) $($*_FUNCTIONS) && touch [email protected] || true) > [email protected]
$(HIDE)(rm [email protected] && mv [email protected] $@) || ( RV=$$?; cat [email protected]; exit $$RV )
test-zig-files: $(ALL_ZIG_FILES)
test-zig-files only-test-zig-files:
cd fiat-zig; $(ZIG_BUILD)
.PHONY: copy-to-fiat-rust
copy-to-fiat-rust: $(addprefix fiat-rust/,$(COPY_TO_FIAT_RUST))
.PHONY: copy-to-fiat-go
copy-to-fiat-go: $(addprefix fiat-go/,$(COPY_TO_FIAT_GO))
# make these .PHONY, so that we copy by contents, not by modification date
# this ensures that these files are always in sync as long as we run make
.PHONY: $(addprefix fiat-rust/,$(COPY_TO_FIAT_RUST))
$(addprefix fiat-rust/,$(COPY_TO_FIAT_RUST)) : fiat-rust/% : %
cp -f $< $@
.PHONY: $(addprefix fiat-go/,$(COPY_TO_FIAT_GO))
$(addprefix fiat-go/,$(COPY_TO_FIAT_GO)) : fiat-go/% : %
cp -f $< $@
$(ALL_GO_FILES) : $(GO_DIR)%.go : $$($$(GO_$$(call GO_FILE_TO_KEY,$$*)_BINARY_NAME))
$(SHOW)'SYNTHESIZE > $@'
$(HIDE)mkdir -p $(dir $@)
$(HIDE)rm -f [email protected]
$(HIDE)($(TIMER) $(PERF_RECORDER) $($(GO_$(call GO_FILE_TO_KEY,$*)_BINARY_NAME)) --lang Go $(GO_EXTRA_ARGS_$(GO_$(call GO_FILE_TO_KEY,$*)_BITWIDTH)) --package-name $(GO_$(call GO_FILE_TO_KEY,$*)_PACKAGE) "" $(GO_$(call GO_FILE_TO_KEY,$*)_ARGS) $(GO_$(call GO_FILE_TO_KEY,$*)_FUNCTIONS) && touch [email protected] || true) > [email protected]
$(HIDE)(rm [email protected] && mv [email protected] $@) || ( RV=$$?; cat [email protected]; exit $$RV )
.PHONY: $(addprefix test-,$(ALL_GO_FILES))
.PHONY: $(addprefix only-test-,$(ALL_GO_FILES))
$(addprefix test-,$(ALL_GO_FILES)) : test-% : %
go build $*
$(addprefix only-test-,$(ALL_GO_FILES)) : only-test-% :
go build $*
test-go-module only-test-go-module:
( cd fiat-go && go build -a -v ./... )
test-go-module: $(ALL_GO_FILES)
test-go-files: $(addprefix test-,$(ALL_GO_FILES))
only-test-go-files: $(addprefix only-test-,$(ALL_GO_FILES))
$(ALL_JSON_FILES) : $(JSON_DIR)%.json : $$($$($$*_BINARY_NAME))
$(SHOW)'SYNTHESIZE > $@'
$(HIDE)rm -f [email protected] [email protected]
$(HIDE)(($(TIMER) $(PERF_RECORDER) $($($*_BINARY_NAME)) --lang JSON $(JSON_EXTRA_ARGS) $($*_DESCRIPTION) $($*_ARGS) $($*_FUNCTIONS) && touch [email protected] || true) | jq -s . && touch [email protected] || true) > [email protected]
$(HIDE)(rm [email protected] [email protected] && mv [email protected] $@) || ( RV=$$?; cat [email protected]; exit $$RV )
.PHONY: $(addprefix test-,$(ALL_JSON_FILES))
.PHONY: $(addprefix only-test-,$(ALL_JSON_FILES))
$(addprefix test-,$(ALL_JSON_FILES)) : test-% : %
jq . >/dev/null <$*
$(addprefix only-test-,$(ALL_JSON_FILES)) : only-test-% :
jq . >/dev/null <$*
test-json-files: $(addprefix test-,$(ALL_JSON_FILES))
only-test-json-files: $(addprefix only-test-,$(ALL_JSON_FILES))
$(ALL_JAVA_FILES) : $(JAVA_DIR)%.java : $$($$(JAVA_$$*_BINARY_NAME))
$(SHOW)'SYNTHESIZE > $@'
$(HIDE)rm -f [email protected]
$(HIDE)($(TIMER) $(PERF_RECORDER) $($(JAVA_$*_BINARY_NAME)) --lang Java $(JAVA_EXTRA_ARGS_$(JAVA_$*_BITWIDTH)) $(JAVA_$*_DESCRIPTION) $(JAVA_$*_ARGS) $(JAVA_$*_FUNCTIONS) && touch [email protected]) > [email protected]
$(HIDE)(rm [email protected] && mv [email protected] $@) || ( RV=$$?; cat [email protected]; exit $$RV )
.PHONY: $(addprefix test-,$(ALL_JAVA_FILES))
.PHONY: $(addprefix only-test-,$(ALL_JAVA_FILES))
$(addprefix test-,$(ALL_JAVA_FILES)) : test-% : %
javac $*
$(addprefix only-test-,$(ALL_JAVA_FILES)) : only-test-% :
javac $*
test-java-files: $(addprefix test-,$(ALL_JAVA_FILES))
only-test-java-files: $(addprefix only-test-,$(ALL_JAVA_FILES))
javadoc: $(ALL_JAVA_FILES)
javadoc only-javadoc:
mkdir -p $(JAVADOC_DIR)
(cd $(JAVADOC_DIR); javadoc $(addprefix $(realpath .)/,$(ALL_JAVA_FILES)))
AMD64_ASM_FILES := $(sort $(wildcard fiat-amd64/**/*.asm))
Makefile.test-amd64-files.mk: fiat-amd64/gentest.py $(AMD64_ASM_FILES)
$(SHOW)'GENTEST --makefile fiat-amd64/fiat_* > $@'
$(HIDE)fiat-amd64/gentest.py --makefile fiat-amd64/fiat_* > $@
include Makefile.test-amd64-files.mk
.PHONY: test-amd64-files-print-report test-amd64-files-lite-print-report only-test-amd64-files-print-report only-test-amd64-files-lite-print-report
test-amd64-files-print-report:: STATUS_FILES=$(AMD64_ASM_STATUS_FILES)
only-test-amd64-files-print-report:: STATUS_FILES=$(AMD64_ASM_ONLY_STATUS_FILES)
test-amd64-files-lite-print-report:: STATUS_FILES=$(AMD64_ASM_SMALL_STATUS_FILES)
only-test-amd64-files-lite-print-report:: STATUS_FILES=$(AMD64_ASM_SMALL_ONLY_STATUS_FILES)
test-amd64-files-status: STATUS_FILES=$(AMD64_ASM_STATUS_FILES)
only-test-amd64-files-status: STATUS_FILES=$(AMD64_ASM_ONLY_STATUS_FILES)
test-amd64-files-lite-status: STATUS_FILES=$(AMD64_ASM_SMALL_STATUS_FILES)
only-test-amd64-files-lite-status: STATUS_FILES=$(AMD64_ASM_SMALL_ONLY_STATUS_FILES)
test-amd64-files-print-report only-test-amd64-files-print-report test-amd64-files-lite-print-report only-test-amd64-files-lite-print-report::
@ export passed=$$(cat $(STATUS_FILES) 2>/dev/null | grep -c '^0$$'); \
export total=$(words $(STATUS_FILES)); \
export failed=$$(expr $${total} - $${passed}); \
if [ $${passed} -eq $${total} ]; then \
echo "$(GREEN)$(BOLD)ALL $${total} AMD64 ASM TESTS PASSED$(NC)"; \
else \
echo "$(GREEN)$(BOLD)PASSED:$(NORMAL) $(GREEN)$${passed}$(NC) / $${total}"; \
echo "$(RED)$(BOLD)FAILED:$(NORMAL) $(RED)$${failed}$(NC) / $${total}"; \
fi
test-amd64-files-status only-test-amd64-files-status test-amd64-files-lite-status only-test-amd64-files-lite-status: $$(STATUS_FILES)
$(HIDE)! grep -q -v '^0$$' $(STATUS_FILES)
.PHONY: test-amd64-files-status only-test-amd64-files-status test-amd64-files-lite-status only-test-amd64-files-lite-status
test-amd64-files test-amd64-files-lite: $(UNSATURATED_SOLINAS) $(WORD_BY_WORD_MONTGOMERY) $(SOLINAS_REDUCTION) $(DETTMAN_MULTIPLICATION)
test-amd64-files: test-amd64-files-print-report test-amd64-files-status
only-test-amd64-files: only-test-amd64-files-print-report only-test-amd64-files-status
test-amd64-files-lite: test-amd64-files-lite-print-report test-amd64-files-lite-status
only-test-amd64-files-lite: only-test-amd64-files-lite-print-report only-test-amd64-files-lite-status
etc/tscfreq: etc/tscfreq.c
$(CC) etc/tscfreq.c -s -Os -o etc/tscfreq
GOPROXY?=https://proxy.golang.org
GO111MODULE?=on
export GOPROXY
export GO111MODULE
update-go-pkg-cache:
go get "github.com/mit-plv/fiat-crypto/fiat-go@master"
go get "github.com/mit-plv/fiat-crypto/[email protected]$(shell TZ=UTC git show --quiet --date='format-local:%Y%m%d%H%M%S' --format="%cd" HEAD)-$(shell git rev-parse HEAD | cut -c 1-12)"
curl "https://pkg.go.dev/github.com/mit-plv/fiat-crypto/[email protected]$(shell TZ=UTC git show --quiet --date='format-local:%Y%m%d%H%M%S' --format="%cd" HEAD)-$(shell git rev-parse HEAD | cut -c 1-12)" >/dev/null