Skip to content

Commit

Permalink
Trying to add CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
xvzcf committed Oct 25, 2024
1 parent 2b82dc5 commit 036ed8e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 25 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Tests"
on:
pull_request:
push:

jobs:
tests:
name: tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixos-unstable
#- uses: DeterminateSystems/magic-nix-cache-action@v3
- run: nix-shell --run "echo Dependencies OK…"
#- run: nix-shell --run "make test"
#- run: nix-shell --run "make large-kat-test"
- run: nix-shell --run '${JASMINC} -slice ml_dsa_65_keygen -checksafety ml_dsa_65/ref/ml_dsa.jazz'
32 changes: 17 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
TOP = /home/efgh/repos/formosa-mldsa

PARAMETER_SET = 65
IMPLEMENTATION_TYPE = ref
# --------------------------------------------------------------------
JASMINC ?= jasminc
JASMIN_COMMAND ?= $(JASMINC) $(JASMINC_FLAGS) $(INCLUDE)

# --------------------------------------------------------------------
IMPLEMENTATION = $(TOP)/ml_dsa_$(PARAMETER_SET)/$(IMPLEMENTATION_TYPE)
IMPLEMENTATION = ml_dsa_$(PARAMETER_SET)/$(IMPLEMENTATION_TYPE)

IMPLEMENTATION_SOURCES = $(IMPLEMENTATION)/ml_dsa.jazz \
$(wildcard $(IMPLEMENTATION)/*.jinc) \
Expand All @@ -18,30 +15,35 @@ IMPLEMENTATION_SOURCES = $(IMPLEMENTATION)/ml_dsa.jazz \
OUTPUT_FILE_NAME = ml_dsa_$(PARAMETER_SET)_$(IMPLEMENTATION_TYPE)

$(OUTPUT_FILE_NAME).s: $(IMPLEMENTATION_SOURCES)
$(JASMIN_COMMAND) -o $@ $<
$(JASMINC) -o $@ $<

# --------------------------------------------------------------------
.PHONY: test
.PHONY: test large-kat-test
test: $(OUTPUT_FILE_NAME).so
cd test && \
python3 nist_drbg_kat_tests.py && \
python3 nist_acvp_tests.py && \
python3 wycheproof_verify_tests.py && \
python3 wycheproof_sign_tests.py
cd test && python3 nist_drbg_kat_tests.py && \
python3 nist_acvp_tests.py && \
python3 wycheproof_verify_tests.py && \
python3 wycheproof_sign_tests.py

.PHONY: large-kat-test
large-kat-test: $(OUTPUT_FILE_NAME).so
cd test && python3 large_kat_test.py

$(OUTPUT_FILE_NAME).so: $(OUTPUT_FILE_NAME).s
$(CC) $^ -fPIC -shared -o $@

# --------------------------------------------------------------------
ml_dsa_$(PARAMETER_SET)_$(IMPLEMENTATION_TYPE)_bench.o: $(OUTPUT_FILE_NAME).s bench/bench.c
$(CC) -DVERIFICATION_KEY_SIZE=1952 \
$(CC) -DKEYGEN=ml_dsa_$(PARAMETER_SET)_keygen \
-DSIGN=ml_dsa_$(PARAMETER_SET)_sign \
-DVERIFY=ml_dsa_$(PARAMETER_SET)_verify \
-DVERIFICATION_KEY_SIZE=1952 \
-DSIGNING_KEY_SIZE=4032 \
-DSIGNATURE_SIZE=3309 \
$^ -o $@

# --------------------------------------------------------------------
.PHONY: clean
clean:
rm -fr \
$(TOP)/*.s \
$(TOP)/*.so
rm -fr *.s \
*.so
12 changes: 6 additions & 6 deletions bench/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

#define DATA_POINTS 10000

extern void ml_dsa_65_keygen(uint8_t *verification_key, uint8_t *signing_key,
extern void KEYGEN(uint8_t *verification_key, uint8_t *signing_key,
const uint8_t key_generation_randomness[32]);
extern void ml_dsa_65_sign(uint8_t *signature, const uint8_t *signing_key,
extern void SIGN(uint8_t *signature, const uint8_t *signing_key,
const uint8_t *message, const size_t message_size,
const uint8_t randomness[32]);
extern void ml_dsa_65_verify(const uint8_t *verification_key,
extern void VERIFY(const uint8_t *verification_key,
const uint8_t *message, const size_t message_size,
const uint8_t signature[SIGNATURE_SIZE]);

Expand Down Expand Up @@ -43,22 +43,22 @@ int main(void) {
// Test key-generation.
for (i = 0; i < DATA_POINTS; i++) {
observations[i] = cpucycles();
ml_dsa_65_keygen(verification_key, signing_key, key_generation_randomness);
KEYGEN(verification_key, signing_key, key_generation_randomness);
}
print_results("--- Key Generation ---", observations, DATA_POINTS);

// Test signing.
for (i = 0; i < DATA_POINTS; i++) {
observations[i] = cpucycles();
ml_dsa_65_sign(signature, signing_key, message, sizeof(message),
SIGN(signature, signing_key, message, sizeof(message),
signing_randomness);
}
print_results("--- Signing ---", observations, DATA_POINTS);

// Test verification.
for (i = 0; i < DATA_POINTS; i++) {
observations[i] = cpucycles();
ml_dsa_65_verify(verification_key, message, sizeof(message), signature);
VERIFY(verification_key, message, sizeof(message), signature);
}
print_results("--- Verification ---", observations, DATA_POINTS);

Expand Down
11 changes: 11 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/6dbbd5a2622d9abf9263a5cb0a85ca218974b085.tar.gz") {};
in pkgs.mkShell {
packages = [
(pkgs.python3.withPackages (python-pkgs: with python-pkgs; [
pycryptodome
]))
];
JASMINC = "${pkgs.jasmin-compiler.bin}/bin/jasminc";
JASMIN_CT = "${pkgs.jasmin-compiler.bin}/bin/jazzct";
}
3 changes: 1 addition & 2 deletions test/large_kat_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from ml_dsa import ML_DSA
import json
from Crypto.Hash import SHAKE128
from tqdm import tqdm

ml_dsa_65 = ML_DSA("ml_dsa_65_ref")

Expand All @@ -20,7 +19,7 @@ def read(self, length):
rng = RNG()
kat_hasher = SHAKE128.new()

for i in tqdm(range(KAT_ITERATIONS)):
for i in range(KAT_ITERATIONS):
key_generation_seed = bytearray(rng.read(32))
(verification_key, signing_key) = ml_dsa_65.generate_keypair(key_generation_seed)

Expand Down
3 changes: 1 addition & 2 deletions test/nist_drbg_kat_tests.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from ml_dsa import ML_DSA
import json
import hashlib
from tqdm import tqdm

ml_dsa_65 = ML_DSA("ml_dsa_65_ref")

with open("nist_drbg_kats/nist_drbg_kats_65.json", "r") as nistkats_65_raw:
nistkats_65 = json.load(nistkats_65_raw)

for kat in tqdm(nistkats_65):
for kat in nistkats_65:
# Test key generation.
key_generation_seed = bytearray.fromhex(kat["key_generation_seed"])
(verification_key, signing_key) = ml_dsa_65.generate_keypair(
Expand Down

0 comments on commit 036ed8e

Please sign in to comment.