diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..eb3ff3bc0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libcrux-ml-kem/pqcp/repo"] + path = libcrux-ml-kem/pqcp/repo + url = git@github.com:pq-code-package/mlkem-rust-libcrux.git diff --git a/libcrux-ml-kem/pqcp/.gitignore b/libcrux-ml-kem/pqcp/.gitignore new file mode 100644 index 000000000..72f092ff8 --- /dev/null +++ b/libcrux-ml-kem/pqcp/.gitignore @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 +# (TODO customize .gitignore for project) + +.vscode +.idea +/target +Cargo.lock diff --git a/libcrux-ml-kem/pqcp/README.md b/libcrux-ml-kem/pqcp/README.md new file mode 100644 index 000000000..5cf9fd5db --- /dev/null +++ b/libcrux-ml-kem/pqcp/README.md @@ -0,0 +1,6 @@ +# PQCP + +## Submodule + +## Updating + diff --git a/libcrux-ml-kem/pqcp/allowlist.txt b/libcrux-ml-kem/pqcp/allowlist.txt new file mode 100644 index 000000000..1e9c88915 --- /dev/null +++ b/libcrux-ml-kem/pqcp/allowlist.txt @@ -0,0 +1,6 @@ +build.rs +examples +src +tests +benches +pqcp/.gitignore diff --git a/libcrux-ml-kem/pqcp/cargo.py b/libcrux-ml-kem/pqcp/cargo.py new file mode 100644 index 000000000..58942f134 --- /dev/null +++ b/libcrux-ml-kem/pqcp/cargo.py @@ -0,0 +1,44 @@ +import tomlkit +import os +import sys + +libcrux_root = sys.argv[1] +workspace_toml_path = os.path.join(libcrux_root, 'Cargo.toml') +crate_toml_path = os.path.join(libcrux_root, 'libcrux-ml-kem/Cargo.toml') +package_toml_path = os.path.join(libcrux_root, 'libcrux-ml-kem/pqcp/repo/Cargo.toml') + +with open(workspace_toml_path, 'r') as workspace_toml_f: + with open(crate_toml_path, 'r') as crate_toml_f: + workspace_toml = tomlkit.parse(workspace_toml_f.read()) + crate_toml = tomlkit.parse(crate_toml_f.read()) + + package_toml = tomlkit.document() + + package = tomlkit.table() + package["name"] = crate_toml["package"]["name"] + package["description"] = crate_toml["package"]["description"] + package["readme"] = crate_toml["package"]["readme"] + package["version"] = workspace_toml["workspace"]["package"]["version"] + package["authors"] = workspace_toml["workspace"]["package"]["authors"] + package["license"] = workspace_toml["workspace"]["package"]["license"] + package["edition"] = workspace_toml["workspace"]["package"]["edition"] + package["repository"] = workspace_toml["workspace"]["package"]["repository"] + package_toml["package"] = package + + + package_toml["workspace"] = tomlkit.table() + package_toml["workspace"]["members"] = ["."] + + + deps = tomlkit.table() + for dep in crate_toml["dependencies"]: + deps[dep] = {"version": crate_toml["dependencies"][dep]["version"]} + package_toml["dependencies"] = deps + package_toml["features"] = crate_toml["features"] + package_toml["dev-dependencies"] = crate_toml["dev-dependencies"] + + package_toml["profile"] = tomlkit.table() + package_toml["profile"]["release"] = workspace_toml["profile"]["release"] + + with open(package_toml_path, 'w') as package_toml_f: + package_toml_f.write(tomlkit.dumps(package_toml)) diff --git a/libcrux-ml-kem/pqcp/repo b/libcrux-ml-kem/pqcp/repo new file mode 160000 index 000000000..f83fd4908 --- /dev/null +++ b/libcrux-ml-kem/pqcp/repo @@ -0,0 +1 @@ +Subproject commit f83fd490821c80da2f806dba77fd230f1698b145 diff --git a/libcrux-ml-kem/pqcp/update-pqcp.sh b/libcrux-ml-kem/pqcp/update-pqcp.sh new file mode 100755 index 000000000..42f98aac1 --- /dev/null +++ b/libcrux-ml-kem/pqcp/update-pqcp.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# +# This script copies files to be included in the `mlkem-rust-libcrux` +# crate for the PQ code package. Files and directories to be copied +# are listed, one per line, in a file at `ALLOWLIST` and copied to the +# PQCP submodule. The copied files include a custom .gitignore file +# for mlkem-rust-libcrux. On successful completion of `cargo test`, a +# signed-off commit is created in the target repository. + +set -e +set -o pipefail + +if [ -z "$(which pip)" ] +then + echo "Error: Python (>= 3.7) required to run this script." +fi + +if [ -z "$(pip list | grep tomlkit)" ] +then + echo "Error: Pythong package tomlkit required to run this script." + echo "To install it using pip, run" + echo "" + echo " pip install tomlkit" + echo "" + exit 1 +fi + +libcrux_root="$(git rev-parse --show-toplevel)" +libcrux_ml_kem_crate="$libcrux_root/libcrux-ml-kem" +allowlist="$libcrux_ml_kem_crate/pqcp/allowlist.txt" +pqcp_repo="$libcrux_ml_kem_crate/pqcp/repo" + +cd "$libcrux_ml_kem_crate" +while read -r item; do + cp -r "$item" "$pqcp_repo" +done < "$allowlist" + +python "$libcrux_ml_kem_crate/pqcp/cargo.py" "$libcrux_root" + +cd "$pqcp_repo" +cargo test +cargo clean + +message="$(printf "mlkem-rust-libcrux PQ code packages update\n\n$(date): libcrux revision $(git -C $libcrux_root rev-parse HEAD)")" +git switch -c "libcrux-ml-kem-$(git -C $libcrux_root rev-parse HEAD)" +git add . +git commit -sm "$message"