diff --git a/test/Makefile b/test/Makefile index e08bb25b..8b938246 100644 --- a/test/Makefile +++ b/test/Makefile @@ -17,7 +17,9 @@ DEST_DIR=../bin # This -Wall was supported by the European Commission through the ERC Starting Grant 805031 (EPOQUE) CFLAGS=-Wall -Wextra -Wpedantic -Werror -Wundef -std=c99 -I$(COMMON_DIR) $(EXTRAFLAGS) -all: $(DEST_DIR)/functest_$(SCHEME)_$(IMPLEMENTATION) $(DEST_DIR)/testvectors_$(SCHEME)_$(IMPLEMENTATION) +all: $(DEST_DIR)/functest_$(SCHEME)_$(IMPLEMENTATION) \ + $(DEST_DIR)/testvectors_$(SCHEME)_$(IMPLEMENTATION) \ + $(DEST_DIR)/printparams_$(SCHEME)_$(IMPLEMENTATION) .PHONY: build-scheme build-scheme: @@ -33,6 +35,9 @@ functest: $(DEST_DIR)/functest_$(SCHEME)_$(IMPLEMENTATION) .PHONY: testvectors testvectors: $(DEST_DIR)/testvectors_$(SCHEME)_$(IMPLEMENTATION) +.PHONY: printparams +printparams: $(DEST_DIR)/printparams_$(SCHEME)_$(IMPLEMENTATION) + $(DEST_DIR)/test_fips202: common/fips202.c $(COMMON_FILES) mkdir -p $(DEST_DIR) $(CC) $(CFLAGS) $< $(COMMON_FILES) -o $@ @@ -49,6 +54,10 @@ $(DEST_DIR)/testvectors_$(SCHEME)_$(IMPLEMENTATION): build-scheme crypto_$(TYPE) mkdir -p $(DEST_DIR) $(CC) $(CFLAGS) -DPQCLEAN_NAMESPACE=PQCLEAN_$(SCHEME_UPPERCASE)_$(IMPLEMENTATION_UPPERCASE) -I$(SCHEME_DIR) crypto_$(TYPE)/testvectors.c $(COMMON_FILES) $(COMMON_DIR)/notrandombytes.c -o $@ -L$(SCHEME_DIR) -l$(SCHEME)_$(IMPLEMENTATION) +$(DEST_DIR)/printparams_$(SCHEME)_$(IMPLEMENTATION): build-scheme crypto_$(TYPE)/printparams.c + mkdir -p $(DEST_DIR) + $(CC) $(CFLAGS) -DPQCLEAN_NAMESPACE=PQCLEAN_$(SCHEME_UPPERCASE)_$(IMPLEMENTATION_UPPERCASE) -I$(SCHEME_DIR) crypto_$(TYPE)/printparams.c -o $@ + .PHONY: clean clean: $(RM) $(DEST_DIR)/functest_$(SCHEME)_$(IMPLEMENTATION) diff --git a/test/Makefile.Microsoft_nmake b/test/Makefile.Microsoft_nmake index 21afb364..9b3661e4 100644 --- a/test/Makefile.Microsoft_nmake +++ b/test/Makefile.Microsoft_nmake @@ -35,6 +35,8 @@ functest: $(DEST_DIR)\functest_$(SCHEME)_$(IMPLEMENTATION).exe testvectors: $(DEST_DIR)\testvectors_$(SCHEME)_$(IMPLEMENTATION).exe +printparams: $(DEST_DIR)\printparams_$(SCHEME)_$(IMPLEMENTATION).exe + $(DEST_DIR)\functest_$(SCHEME)_$(IMPLEMENTATION).exe: build-scheme $(COMMON_OBJECTS) $(COMMON_DIR)\randombytes.obj -MKDIR $(DEST_DIR) -DEL functest.obj @@ -47,7 +49,13 @@ $(DEST_DIR)\testvectors_$(SCHEME)_$(IMPLEMENTATION).exe: build-scheme $(COMMON_O $(CC) /c crypto_$(TYPE)\testvectors.c $(CFLAGS) /I $(SCHEME_DIR) /DPQCLEAN_NAMESPACE=PQCLEAN_$(SCHEME_UPPERCASE)_$(IMPLEMENTATION_UPPERCASE) LINK.EXE /OUT:$@ testvectors.obj $(COMMON_OBJECTS_NOPATH) notrandombytes.obj $(SCHEME_DIR)\lib$(SCHEME)_$(IMPLEMENTATION).lib +$(DEST_DIR)\printparams_$(SCHEME)_$(IMPLEMENTATION).exe: crypto_$(TYPE)\printparams.c $(SCHEME_DIR)\api.h + -MKDIR $(DEST_DIR) + -DEL printparams.obj + $(CC) /c crypto_$(TYPE)\printparams.c $(CFLAGS) /I $(SCHEME_DIR) /DPQCLEAN_NAMESPACE=PQCLEAN_$(SCHEME_UPPERCASE)_$(IMPLEMENTATION_UPPERCASE) + LINK.EXE /OUT:$@ printparams.obj + clean: - -DEL functest.obj testvectors.obj + -DEL functest.obj testvectors.obj printparams.obj -DEL $(COMMON_OBJECTS_NOPATH) randombytes.obj notrandombytes.obj -DEL $(DEST_DIR)\functest_$(SCHEME)_$(IMPLEMENTATION).exe diff --git a/test/crypto_kem/printparams.c b/test/crypto_kem/printparams.c new file mode 100644 index 00000000..925b2119 --- /dev/null +++ b/test/crypto_kem/printparams.c @@ -0,0 +1,14 @@ +#include +#include "api.h" + +#define PASTER(x, y) x##_##y +#define EVALUATOR(x, y) PASTER(x, y) +#define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun) + +int main() { + printf("{\n"); + printf("\t\"CRYPTO_SECRETKEYBYTES\": %u,\n", NAMESPACE(CRYPTO_SECRETKEYBYTES)); + printf("\t\"CRYPTO_PUBLICKEYBYTES\": %u,\n", NAMESPACE(CRYPTO_PUBLICKEYBYTES)); + printf("\t\"CRYPTO_CIPHERTEXTBYTES\": %u,\n", NAMESPACE(CRYPTO_CIPHERTEXTBYTES)); + printf("\t\"CRYPTO_BYTES\": %u\n}\n", NAMESPACE(CRYPTO_BYTES)); +} diff --git a/test/crypto_sign/printparams.c b/test/crypto_sign/printparams.c new file mode 100644 index 00000000..8c38767c --- /dev/null +++ b/test/crypto_sign/printparams.c @@ -0,0 +1,13 @@ +#include +#include "api.h" + +#define PASTER(x, y) x##_##y +#define EVALUATOR(x, y) PASTER(x, y) +#define NAMESPACE(fun) EVALUATOR(PQCLEAN_NAMESPACE, fun) + +int main() { + printf("{\n"); + printf("\t\"CRYPTO_SECRETKEYBYTES\": %u,\n", NAMESPACE(CRYPTO_SECRETKEYBYTES)); + printf("\t\"CRYPTO_PUBLICKEYBYTES\": %u,\n", NAMESPACE(CRYPTO_PUBLICKEYBYTES)); + printf("\t\"CRYPTO_BYTES\": %u\n}\n", NAMESPACE(CRYPTO_BYTES)); +} diff --git a/test/test_metadata_sizes.py b/test/test_metadata_sizes.py new file mode 100644 index 00000000..dc1dfacb --- /dev/null +++ b/test/test_metadata_sizes.py @@ -0,0 +1,50 @@ +import json +import os + +import pqclean +import helpers + + +def test_metadata_sizes(): + for scheme in pqclean.Scheme.all_schemes(): + for implementation in scheme.implementations: + yield check_metadata_sizes, implementation + + +def check_metadata_sizes(implementation): + metadata = implementation.scheme.metadata() + helpers.make('printparams', + TYPE=implementation.scheme.type, + SCHEME=implementation.scheme.name, + IMPLEMENTATION=implementation.name, + working_dir=os.path.join('..', 'test')) + + out = helpers.run_subprocess( + [os.path.join('..', 'bin', 'printparams_{}_{}{}'.format( + implementation.scheme.name, + implementation.name, + '.exe' if os.name == 'nt' else '' + ))], + os.path.join('..', 'bin'), + ).replace('\r', '') + + parsed = json.loads(out) + + assert parsed['CRYPTO_SECRETKEYBYTES'] == metadata['length-secret-key'] + assert parsed['CRYPTO_PUBLICKEYBYTES'] == metadata['length-public-key'] + + if implementation.scheme.type == 'kem': + assert ( + parsed['CRYPTO_CIPHERTEXTBYTES'] == metadata['length-ciphertext']) + assert parsed['CRYPTO_BYTES'] == metadata['length-shared-secret'] + else: + assert parsed['CRYPTO_BYTES'] == metadata['length-signature'] + + +if __name__ == '__main__': + try: + import nose2 + nose2.main() + except ImportError: + import nose + nose.runmodule()