diff --git a/META.sh b/META.sh new file mode 100755 index 000000000..fc1c0f307 --- /dev/null +++ b/META.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Helper script to query META.json +# +# Arguments +# - Scheme to query: ML-KEM-512, ML-KEM-768, ML-KEM-1024 +# - Field to query, e.g. "kat-sha256" +# +# Optional: +# - Value to compare against + +META=META.json + +# Manual extraction of metadata with basic cmd line tools +VAL=$(cat $META | + grep "name\|\"$2\"" | + grep $1 -A 1 | + grep $2 | + cut -d ":" -f 2 | + tr -d '", ') + +# More robust extraction using jq +if (which jq 2>&1 >/dev/null); then + QUERY=".implementations | .[] | select(.name==\"$1\") | .\"$2\"" + VAL_JQ=$(cat $META | jq "$QUERY" -r) + + if [[ $VAL_JQ != $VAL ]]; then + echo "ERROR parsing metadata file $META" + exit 1 + fi +fi + +INPUT=$3 +if [[ "$INPUT" != "" ]]; then + if [[ "$INPUT" != "$VAL" ]]; then + echo "$META $1 $2: FAIL ($VAL != $INPUT)" + exit 1 + else + echo "$META $1 $2: OK" + exit 0 + fi +else + echo $VAL +fi diff --git a/Makefile b/Makefile index a24c40245..2f0da929a 100644 --- a/Makefile +++ b/Makefile @@ -14,12 +14,13 @@ buildall: mlkem nistkat kat acvp $(Q)echo " Everything builds fine!" quickcheck: buildall - # Run basic functionality checks $(MLKEM512_DIR)/bin/test_mlkem512 $(MLKEM768_DIR)/bin/test_mlkem768 $(MLKEM1024_DIR)/bin/test_mlkem1024 - ./scripts/acvp - $(Q)echo " Functionality and ACVP tests passed!" + + $(MLKEM512_DIR)/bin/gen_KAT512 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-512 kat-sha256 + $(MLKEM768_DIR)/bin/gen_KAT768 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-768 kat-sha256 + $(MLKEM1024_DIR)/bin/gen_KAT1024 | sha256sum | cut -d " " -f 1 | xargs ./META.sh ML-KEM-1024 kat-sha256 lib: $(BUILD_DIR)/libmlkem.a