Skip to content

Commit 67c264e

Browse files
authored
Merge pull request #599 from pq-code-package/makefile_ext
Makefile: Minor cleanup and introduction of level-specific targets
2 parents f57ad64 + f0a03fe commit 67c264e

File tree

5 files changed

+119
-90
lines changed

5 files changed

+119
-90
lines changed

Makefile

Lines changed: 102 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,133 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
.PHONY: mlkem kat nistkat clean quickcheck buildall checkall all check-defined-CYCLES
3+
.PHONY: func kat nistkat acvp \
4+
func_512 kat_512 nistkat_512 acvp_512 \
5+
func_768 kat_768 nistkat_768 acvp_768 \
6+
func_1024 kat_1024 nistkat_1024 acvp_1024 \
7+
run_func run_kat run_nistkat run_acvp \
8+
run_func_512 run_kat_512 run_nistkat_512 run_acvp_512 \
9+
run_func_768 run_kat_768 run_nistkat_768 run_acvp_768 \
10+
run_func_1024 run_kat_1024 run_nistkat_1024 run_acvp_1024 \
11+
bench_512 bench_768 bench_1024 bench \
12+
run_bench_512 run_bench_768 run_bench_1024 run_bench \
13+
bench_components_512 bench_components_768 bench_components_1024 bench_components \
14+
run_bench_components_512 run_bench_components_768 run_bench_components_1024 run_bench_components \
15+
buildall checkall all \
16+
clean quickcheck check-defined-CYCLES
17+
418
.DEFAULT_GOAL := buildall
519
all: quickcheck
620

21+
W := $(EXEC_WRAPPER)
22+
723
include mk/config.mk
8-
include mk/crypto.mk
9-
include mk/schemes.mk
24+
include mk/components.mk
1025
include mk/rules.mk
1126

1227
quickcheck: checkall
1328

14-
buildall: mlkem nistkat kat acvp
29+
buildall: func nistkat kat acvp
1530
$(Q)echo " Everything builds fine!"
1631

17-
checkall: check_kat check_nistkat check_func check_acvp
32+
checkall: run_kat run_nistkat run_func run_acvp
1833
$(Q)echo " Everything checks fine!"
1934

20-
check_kat: kat
21-
$(MLKEM512_DIR)/bin/gen_KAT512 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-512 kat-sha256
22-
$(MLKEM768_DIR)/bin/gen_KAT768 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-768 kat-sha256
23-
$(MLKEM1024_DIR)/bin/gen_KAT1024 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-1024 kat-sha256
35+
run_kat_512: kat_512
36+
$(W) $(MLKEM512_DIR)/bin/gen_KAT512 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-512 kat-sha256
37+
run_kat_768: kat_768
38+
$(W) $(MLKEM768_DIR)/bin/gen_KAT768 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-768 kat-sha256
39+
run_kat_1024: kat_1024
40+
$(W) $(MLKEM1024_DIR)/bin/gen_KAT1024 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-1024 kat-sha256
41+
run_kat: run_kat_512 run_kat_768 run_kat_1024
42+
43+
run_nistkat_512: nistkat_512
44+
$(W) $(MLKEM512_DIR)/bin/gen_NISTKAT512 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-512 nistkat-sha256
45+
run_nistkat_768: nistkat_768
46+
$(W) $(MLKEM768_DIR)/bin/gen_NISTKAT768 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-768 nistkat-sha256
47+
run_nistkat_1024: nistkat_1024
48+
$(W) $(MLKEM1024_DIR)/bin/gen_NISTKAT1024 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-1024 nistkat-sha256
49+
run_nistkat: run_nistkat_512 run_nistkat_768 run_nistkat_1024
50+
51+
run_func_512: func_512
52+
$(W) $(MLKEM512_DIR)/bin/test_mlkem512
53+
run_func_768: func_768
54+
$(W) $(MLKEM768_DIR)/bin/test_mlkem768
55+
run_func_1024: func_1024
56+
$(W) $(MLKEM1024_DIR)/bin/test_mlkem1024
57+
run_func: run_func_512 run_func_768 run_func_1024
58+
59+
run_acvp: acvp
60+
python3 ./test/acvp_client.py
2461

25-
check_nistkat: nistkat
26-
$(MLKEM512_DIR)/bin/gen_NISTKAT512 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-512 nistkat-sha256
27-
$(MLKEM768_DIR)/bin/gen_NISTKAT768 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-768 nistkat-sha256
28-
$(MLKEM1024_DIR)/bin/gen_NISTKAT1024 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-1024 nistkat-sha256
62+
func_512: $(MLKEM512_DIR)/bin/test_mlkem512
63+
func_768: $(MLKEM768_DIR)/bin/test_mlkem768
64+
func_1024: $(MLKEM1024_DIR)/bin/test_mlkem1024
65+
func: func_512 func_768 func_1024
2966

30-
check_func: mlkem
31-
$(MLKEM512_DIR)/bin/test_mlkem512
32-
$(MLKEM768_DIR)/bin/test_mlkem768
33-
$(MLKEM1024_DIR)/bin/test_mlkem1024
67+
nistkat_512: $(MLKEM512_DIR)/bin/gen_NISTKAT512
68+
nistkat_768: $(MLKEM768_DIR)/bin/gen_NISTKAT768
69+
nistkat_1024: $(MLKEM1024_DIR)/bin/gen_NISTKAT1024
70+
nistkat: nistkat_512 nistkat_768 nistkat_1024
3471

35-
check_acvp: acvp
36-
python3 ./test/acvp_client.py
72+
kat_512: $(MLKEM512_DIR)/bin/gen_KAT512
73+
kat_768: $(MLKEM768_DIR)/bin/gen_KAT768
74+
kat_1024: $(MLKEM1024_DIR)/bin/gen_KAT1024
75+
kat: kat_512 kat_768 kat_1024
3776

38-
lib: $(BUILD_DIR)/libmlkem.a
77+
acvp_512: $(MLKEM512_DIR)/bin/acvp_mlkem512
78+
acvp_768: $(MLKEM768_DIR)/bin/acvp_mlkem768
79+
acvp_1024: $(MLKEM1024_DIR)/bin/acvp_mlkem1024
80+
acvp: acvp_512 acvp_768 acvp_1024
3981

40-
mlkem: \
41-
$(MLKEM512_DIR)/bin/test_mlkem512 \
42-
$(MLKEM768_DIR)/bin/test_mlkem768 \
43-
$(MLKEM1024_DIR)/bin/test_mlkem1024
82+
lib: $(BUILD_DIR)/libmlkem.a
4483

4584
# Enforce setting CYCLES make variable when
4685
# building benchmarking binaries
4786
check_defined = $(if $(value $1),, $(error $2))
4887
check-defined-CYCLES:
4988
@:$(call check_defined,CYCLES,CYCLES undefined. Benchmarking requires setting one of NO PMU PERF M1)
5089

51-
bench: check-defined-CYCLES \
52-
$(MLKEM512_DIR)/bin/bench_mlkem512 \
53-
$(MLKEM768_DIR)/bin/bench_mlkem768 \
90+
bench_512: check-defined-CYCLES \
91+
$(MLKEM512_DIR)/bin/bench_mlkem512
92+
bench_768: check-defined-CYCLES \
93+
$(MLKEM768_DIR)/bin/bench_mlkem768
94+
bench_1024: check-defined-CYCLES \
5495
$(MLKEM1024_DIR)/bin/bench_mlkem1024
55-
56-
acvp: \
57-
$(MLKEM512_DIR)/bin/acvp_mlkem512 \
58-
$(MLKEM768_DIR)/bin/acvp_mlkem768 \
59-
$(MLKEM1024_DIR)/bin/acvp_mlkem1024
60-
61-
bench_components: check-defined-CYCLES \
62-
$(MLKEM512_DIR)/bin/bench_components_mlkem512 \
63-
$(MLKEM768_DIR)/bin/bench_components_mlkem768 \
96+
bench: bench_512 bench_768 bench_1024
97+
98+
run_bench_512: bench_512
99+
$(W) $(MLKEM512_DIR)/bin/bench_mlkem512
100+
run_bench_768: bench_768
101+
$(W) $(MLKEM768_DIR)/bin/bench_mlkem768
102+
run_bench_1024: bench_1024
103+
$(W) $(MLKEM1024_DIR)/bin/bench_mlkem1024
104+
105+
# Use .WAIT to prevent parallel execution when -j is passed
106+
run_bench: \
107+
run_bench_512 .WAIT\
108+
run_bench_768 .WAIT\
109+
run_bench_1024
110+
111+
bench_components_512: check-defined-CYCLES \
112+
$(MLKEM512_DIR)/bin/bench_components_mlkem512
113+
bench_components_768: check-defined-CYCLES \
114+
$(MLKEM768_DIR)/bin/bench_components_mlkem768
115+
bench_components_1024: check-defined-CYCLES \
64116
$(MLKEM1024_DIR)/bin/bench_components_mlkem1024
65-
66-
nistkat: \
67-
$(MLKEM512_DIR)/bin/gen_NISTKAT512 \
68-
$(MLKEM768_DIR)/bin/gen_NISTKAT768 \
69-
$(MLKEM1024_DIR)/bin/gen_NISTKAT1024
70-
71-
kat: \
72-
$(MLKEM512_DIR)/bin/gen_KAT512 \
73-
$(MLKEM768_DIR)/bin/gen_KAT768 \
74-
$(MLKEM1024_DIR)/bin/gen_KAT1024
117+
bench_components: bench_components_512 bench_components_768 bench_components_1024
118+
119+
run_bench_components_512: bench_components_512
120+
$(W) $(MLKEM512_DIR)/bin/bench_components_mlkem512
121+
run_bench_components_768: bench_components_768
122+
$(W) $(MLKEM768_DIR)/bin/bench_components_mlkem768
123+
run_bench_components_1024: bench_components_1024
124+
$(W) $(MLKEM1024_DIR)/bin/bench_components_mlkem1024
125+
126+
# Use .WAIT to prevent parallel execution when -j is passed
127+
run_bench_components: \
128+
run_bench_components_512 .WAIT\
129+
run_bench_components_768 .WAIT\
130+
run_bench_components_1024
75131

76132
clean:
77133
-$(RM) -rf *.gcno *.gcda *.lcov *.o *.so

mk/schemes.mk renamed to mk/components.mk

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
# SPDX-License-Identifier: Apache-2.0
2+
3+
CFLAGS += -Imlkem/fips202 -Imlkem/fips202/native
4+
FIPS202_SRCS = $(wildcard mlkem/fips202/*.c)
5+
ifeq ($(OPT),1)
6+
FIPS202_SRCS += $(wildcard mlkem/fips202/native/aarch64/src/*.S) $(wildcard mlkem/fips202/native/aarch64/src/*.c) $(wildcard mlkem/fips202/native/x86_64/src/*.c)
7+
endif
8+
9+
$(BUILD_DIR)/libmlkem.a: $(call OBJS, $(FIPS202_SRCS))
10+
$(BUILD_DIR)/libmlkem512.a: $(call OBJS, $(FIPS202_SRCS))
11+
$(BUILD_DIR)/libmlkem768.a: $(call OBJS, $(FIPS202_SRCS))
12+
$(BUILD_DIR)/libmlkem1024.a: $(call OBJS, $(FIPS202_SRCS))
13+
214
SOURCES += $(wildcard mlkem/*.c) $(wildcard mlkem/debug/*.c)
315
ifeq ($(OPT),1)
416
SOURCES += $(wildcard mlkem/native/aarch64/src/*.[csS]) $(wildcard mlkem/native/x86_64/src/*.[csS])

mk/crypto.mk

Lines changed: 0 additions & 11 deletions
This file was deleted.

scripts/lib/mlkem_test.py

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@ def compile_mode(self):
3434
return "Cross" if self.cross_prefix else "Native"
3535

3636

37-
class Options(object):
38-
def __init__(self):
39-
self.cross_prefix = ""
40-
self.cflags = ""
41-
self.auto = True
42-
self.verbose = False
43-
self.opt = "ALL"
44-
self.compile = True
45-
self.run = True
46-
self.exec_wrapper = ""
47-
self.run_as_root = ""
48-
self.k = "ALL"
49-
50-
5137
class Base:
5238

5339
def __init__(self, test_type: TEST_TYPES, copts: CompileOptions, opt):
@@ -124,7 +110,6 @@ def run_scheme(
124110
scheme,
125111
check_proc=None,
126112
cmd_prefix=None,
127-
extra_args=None,
128113
):
129114
"""Run the binary in all different ways
130115
@@ -134,12 +119,9 @@ def run_scheme(
134119
- check_proc: Callable to process and check the raw byte-output
135120
of the test run with.
136121
- cmd_prefix: Command prefix; array of strings, or None
137-
- extra_args: Extra arguments; array of strings, or None
138122
"""
139123
if cmd_prefix is None:
140124
cmd_prefix = []
141-
if extra_args is None:
142-
extra_args = []
143125

144126
log = logger(self.test_type, scheme, self.cross_prefix, self.opt, self.i)
145127
self.i += 1
@@ -149,7 +131,7 @@ def run_scheme(
149131
log.error(f"{bin} does not exists")
150132
sys.exit(1)
151133

152-
cmd = cmd_prefix + [f"{bin}"] + extra_args
134+
cmd = cmd_prefix + [f"{bin}"]
153135

154136
log.debug(" ".join(cmd))
155137

@@ -206,7 +188,6 @@ def run_scheme(
206188
scheme,
207189
check_proc=None,
208190
cmd_prefix=None,
209-
extra_args=None,
210191
):
211192
"""Arguments:
212193
@@ -215,37 +196,29 @@ def run_scheme(
215196
- check_proc: Callable to process and check the
216197
raw byte-output of the test run with.
217198
- cmd_prefix: Command prefix; array of strings, or None
218-
- extra_args: Extra arguments; array of strings, or None
219199
"""
220200
if cmd_prefix is None:
221201
cmd_prefix = []
222-
if extra_args is None:
223-
extra_args = []
224202

225203
# Returns TypedDict
226204
k = "opt" if opt else "no_opt"
227205

228206
results = {}
229207
results[k] = {}
230-
results[k][scheme] = self.ts[k].run_scheme(
231-
scheme, check_proc, cmd_prefix, extra_args
232-
)
208+
results[k][scheme] = self.ts[k].run_scheme(scheme, check_proc, cmd_prefix)
233209

234210
return results
235211

236-
def run_schemes(self, opt, check_proc=None, cmd_prefix=None, extra_args=None):
212+
def run_schemes(self, opt, check_proc=None, cmd_prefix=None):
237213
"""Arguments:
238214
239215
- opt: Whether native backends should be enabled
240216
- check_proc: Functionto process and check the raw byte-output
241217
of the test run with.
242218
- cmd_prefix: Command prefix; array of strings
243-
- extra_args: Extra arguments; array of strings
244219
"""
245220
if cmd_prefix is None:
246221
cmd_prefix = []
247-
if extra_args is None:
248-
extra_args = []
249222

250223
# Returns
251224
results = {}
@@ -261,7 +234,6 @@ def run_schemes(self, opt, check_proc=None, cmd_prefix=None, extra_args=None):
261234
scheme,
262235
check_proc,
263236
cmd_prefix,
264-
extra_args,
265237
)
266238

267239
results[k][scheme] = result
@@ -467,7 +439,7 @@ def dict2str(dict):
467439
s += f"{k}={v} "
468440
return s
469441

470-
args = ["make", "check_acvp"]
442+
args = ["make", "run_acvp"]
471443
log.info(dict2str(env_update) + " ".join(args))
472444

473445
p = subprocess.run(

scripts/lib/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def bin(self):
102102

103103
def make_target(self):
104104
if self == TEST_TYPES.MLKEM:
105-
return "mlkem"
105+
return "func"
106106
if self == TEST_TYPES.BENCH:
107107
return "bench"
108108
if self == TEST_TYPES.BENCH_COMPONENTS:

0 commit comments

Comments
 (0)