Skip to content

Commit 0aa944c

Browse files
committed
autogen: extending autogen to auto-update the oqs yml file list
This commit port the OQS source list automatically updating feature from mlkem-native to mldsa-native. Signed-off-by: willieyz <willie.zhao@chelpis.com>
1 parent d977284 commit 0aa944c

File tree

1 file changed

+98
-1
lines changed

1 file changed

+98
-1
lines changed

scripts/autogen

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ def gen_header():
8383
yield ""
8484

8585

86+
def gen_yaml_header():
87+
yield "# Copyright (c) The mldsa-native project authors"
88+
yield "# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT"
89+
yield ""
90+
91+
8692
def get_files(pattern):
8793
return [str(p) for p in pathlib.Path().glob(pattern) if p.is_file()]
8894

@@ -997,6 +1003,96 @@ def gen_avx2_zeta_file(dry_run=False):
9971003
)
9981004

9991005

1006+
def get_oqs_shared_sources(backend):
1007+
"""Get shared source files for OQS integration"""
1008+
mldsa_dir = "mldsa"
1009+
1010+
# add files mldsa/*
1011+
sources = [
1012+
f"mldsa/{f}"
1013+
for f in os.listdir(mldsa_dir)
1014+
if os.path.isfile(f"{mldsa_dir}/{f}") and not f.endswith(".o")
1015+
]
1016+
1017+
if backend != "ref":
1018+
# add files mldsa/native/* (API definitions)
1019+
sources += [
1020+
f"mldsa/native/{f}"
1021+
for f in os.listdir(f"{mldsa_dir}/native")
1022+
if os.path.isfile(f"{mldsa_dir}/native/{f}")
1023+
]
1024+
# We use a custom config
1025+
sources.remove("mldsa/config.h")
1026+
# Add FIPS202 glue code
1027+
sources += [
1028+
"integration/liboqs/fips202_glue.h",
1029+
"integration/liboqs/fips202x4_glue.h",
1030+
]
1031+
# Add custom config
1032+
if backend == "ref":
1033+
backend = "c"
1034+
sources.append(f"integration/liboqs/config_{backend.lower()}.h")
1035+
1036+
return sources
1037+
1038+
1039+
def get_oqs_native_sources(backend):
1040+
"""Get native source files for OQS integration"""
1041+
return [f"mldsa/native/{backend}"]
1042+
1043+
1044+
def gen_oqs_meta_file(filename, dry_run=False):
1045+
"""Generate OQS META.yml file with updated source lists"""
1046+
status_update("OQS META", filename)
1047+
1048+
with open(filename, "r") as f:
1049+
content = f.read()
1050+
1051+
# Parse YAML while preserving structure
1052+
yml_data = yaml.safe_load(content)
1053+
1054+
for impl in yml_data["implementations"]:
1055+
name = impl["name"]
1056+
1057+
sources = get_oqs_shared_sources(name)
1058+
1059+
# NOTE: Sorting at the end causes the libOQS importer to fail.
1060+
# Somehow, the native directory cannot be imported too early.
1061+
sources.sort()
1062+
1063+
if name != "ref":
1064+
sources += get_oqs_native_sources(name)
1065+
impl["sources"] = " ".join(sources)
1066+
1067+
# Convert back to YAML string with standard copyright header
1068+
yaml_header = "\n".join(gen_yaml_header())
1069+
1070+
new_content = yaml.dump(
1071+
yml_data,
1072+
default_flow_style=False,
1073+
sort_keys=False,
1074+
allow_unicode=True,
1075+
encoding=None,
1076+
)
1077+
1078+
# Combine copyright header with new YAML content
1079+
new_content = yaml_header + new_content
1080+
1081+
update_file(filename, new_content, dry_run=dry_run)
1082+
1083+
1084+
def gen_oqs_meta_files(dry_run=False):
1085+
"""Generate all OQS META.yml files"""
1086+
meta_files = [
1087+
"integration/liboqs/ML-DSA-44_META.yml",
1088+
"integration/liboqs/ML-DSA-65_META.yml",
1089+
"integration/liboqs/ML-DSA-87_META.yml",
1090+
]
1091+
1092+
for meta_file in meta_files:
1093+
gen_oqs_meta_file(meta_file, dry_run=dry_run)
1094+
1095+
10001096
def adjust_header_guard_for_filename(content, header_file):
10011097

10021098
status_update("header guards", header_file)
@@ -1384,7 +1480,8 @@ def _main():
13841480

13851481
gen_citations(args.dry_run)
13861482
high_level_status("Generated citations")
1387-
1483+
gen_oqs_meta_files(args.dry_run)
1484+
high_level_status("Generated OQS META.yml files")
13881485
gen_c_zeta_file(args.dry_run)
13891486
gen_aarch64_zeta_file(args.dry_run)
13901487
gen_aarch64_rej_uniform_table(args.dry_run)

0 commit comments

Comments
 (0)