From: Loup Vaillant Date: Mon, 18 Sep 2017 21:13:36 +0000 (+0200) Subject: Cleaner generation of test vectors. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=b90e5535265b9ee36e28bed7a8ee54555b62d274;p=Monocypher.git Cleaner generation of test vectors. The makefile that generates the test vectors directly puts the vectors.h header in the dist/tests/ directory. No more weird script to do half that work. As a side effect, BSD users can now switch to gmake more easily (they don't depend on a script to do stuff like `make || gmake`. Closes #33, though not satisfactorily (the makefiles still rely on GNU make, because portable makefiles are just crippled). --- diff --git a/.gitignore b/.gitignore index 43a9bae..7ddd1d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # backup files *~ *.o +*.a +*.so *.out *.vec *.gch diff --git a/README.md b/README.md index 3a258e7..fde07bc 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,21 @@ inspired by [libsodium][] and [TweetNaCl][], written in portable C. [libsodium]: http://libsodium.org [TweetNaCl]: http://tweetnacl.cr.yp.to/ -Generating the test suite -------------------------- + +Generating the test vectors +--------------------------- You are currently using the source repository, meant for developers. -You need to generate the test suite before you can run it. This -requires Libsodium 1.0.12 or later. +You need to generate the test vectors before you can run the test +suite. This requires requires Libsodium 1.0.12 or later: - $ ./dist.sh + $ cd tests/gen/ + $ make + $ cd ../.. -Once you have done that, `cd dist` and read the +This will generate `dist/tests/vectors.h`, which contains all the test +vectors. You can now go to the `dist/` directory, then compile and +test Monocypher like end users. There's also a [README.md](dist/README.md) there. @@ -39,7 +44,6 @@ installation instructions there. * [Zig](https://bitbucket.org/mihailp/zig-monocypher/src/default) (http://ziglang.org/). - ### Known alternate distributions * [AUR package](https://aur.archlinux.org/packages/monocypher/) for diff --git a/dist.sh b/dist.sh index 17646a7..4e520b4 100755 --- a/dist.sh +++ b/dist.sh @@ -1,35 +1,6 @@ #! /bin/sh -cp README.md dist/ cp AUTHORS.md dist/ cp LICENCE.md dist/ +cp tests/gen/vectors.h dist/tests/vectors.h -(cd tests/gen/; make) - -mkdir -p dist/tests/vectors -gcc tests/vector_to_header.c -o dist/tests/vectors/vector_to_header.out - -cat tests/gen/chacha20.vec tests/vectors/chacha20 > dist/tests/vectors/chacha20.vec -cat tests/gen/poly1305.vec tests/vectors/poly1305 > dist/tests/vectors/poly1305.vec -cat tests/gen/x25519.vec tests/vectors/x25519 > dist/tests/vectors/x25519.vec -cp tests/gen/xchacha20.vec dist/tests/vectors/xchacha20.vec -cp tests/gen/blake2b.vec dist/tests/vectors/blake2b.vec -cp tests/gen/sha512.vec dist/tests/vectors/sha512.vec -cp tests/gen/argon2i.vec dist/tests/vectors/argon2i.vec -cp tests/gen/edDSA.vec dist/tests/vectors/edDSA.vec -cp tests/vectors/key_exchange dist/tests/vectors/key_exchange.vec - -(cd dist/tests/vectors - ./vector_to_header.out chacha20 < chacha20.vec > chacha20.h - ./vector_to_header.out xchacha20 < xchacha20.vec > xchacha20.h - ./vector_to_header.out poly1305 < poly1305.vec > poly1305.h - ./vector_to_header.out blake2b < blake2b.vec > blake2b.h - ./vector_to_header.out sha512 < sha512.vec > sha512.h - ./vector_to_header.out argon2i < argon2i.vec > argon2i.h - ./vector_to_header.out x25519 < x25519.vec > x25519.h - ./vector_to_header.out edDSA < edDSA.vec > edDSA.h - ./vector_to_header.out key_exchange < key_exchange.vec > key_exchange.h -) - -cat dist/tests/vectors/*.h > dist/tests/vectors.h -rm -rf dist/tests/vectors/ diff --git a/tests/gen/makefile b/tests/gen/makefile index 138a759..1532b50 100644 --- a/tests/gen/makefile +++ b/tests/gen/makefile @@ -1,41 +1,43 @@ CC=gcc -std=c99 -#CC = clang -std=c99 -fsanitize=address -#CC = clang -std=c99 -fsanitize=memory -#CC = clang -std=c99 -fsanitize=undefined -CFLAGS= -pedantic -Wall -Wextra -O3 -march=native -HASH= + +CFLAGS = -pedantic -Wall -Wextra -O3 -march=native +HASH = #HASH=-DED25519_SHA512 .PHONY: all clean -all: chacha20.vec \ - xchacha20.vec \ - poly1305.vec \ - blake2b.vec \ - sha512.vec \ - argon2i.vec \ - edDSA.vec \ - x25519.vec +VEC = chacha20.vec xchacha20.vec poly1305.vec blake2b.vec \ + sha512.vec argon2i.vec edDSA.vec x25519.vec +VEC2 = $(patsubst %.vec, %.all.vec, $(VEC)) key_exchange.all.vec +HEADERS = $(patsubst %.all.vec, %.h.vec, $(VEC2)) +VECTORS = ../../dist/tests/vectors.h + + +all: $(VECTORS) clean: - rm -f *.out - rm -f *.vec - rm -f *.o + rm -f *.out *.vec *.o + rm -f $(VECTORS) %.vec: %.out ./$< > $@ -%.out: %.c donna.o ../../dist/tests/utils.c monocypher.o - $(CC) $(CFLAGS) -o $@ $^ \ - -I ../../dist/tests \ - -I ../ed25519-donna \ - -I ../../dist/src \ - $$(pkg-config --cflags libsodium) \ - $$(pkg-config --libs libsodium) - -# Needed for EdDSA -donna.o: ../ed25519-donna/ed25519.c - $(CC) $(CFLAGS) -o $@ -c $^ \ +%.o: %.c ../../dist/tests/utils.h ../ed25519-donna/ed25519.h + $(CC) $(CFLAGS) -c $< \ + -I ../../dist/tests \ + -I ../ed25519-donna \ + -I ../../dist/src \ + $$(pkg-config --cflags libsodium) + +%.out: %.o monocypher.o utils.o ed25519.o + $(CC) $(CFLAGS) -o $@ $^ \ + $$(pkg-config --libs libsodium) + +utils.o: ../../dist/tests/utils.c ../../dist/tests/utils.h + $(CC) $(CFLAGS) -c $< -I ../../dist/tests -I ../../dist/src + +ed25519.o: ../ed25519-donna/ed25519.c $(wildcard ../ed25519-donna/*.h) + $(CC) $(CFLAGS) -c $< \ -I ../../dist/src \ $(HASH) \ -DED25519_CUSTOMHASH \ @@ -43,12 +45,29 @@ donna.o: ../ed25519-donna/ed25519.c -DED25519_NO_INLINE_ASM \ -DED25519_FORCE_32BIT -# Needed for Blake2b in EdDSA -monocypher.o: ../../dist/src/monocypher.c - $(CC) $(CFLAGS) -o $@ -c $^ \ - -I ../../dist/src +monocypher.o: ../../dist/src/monocypher.c ../../dist/src/monocypher.h +m_sha512.o : ../../dist/src/sha512.c ../../dist/src/sha512.h +monocypher.o m_sha512.o: + $(CC) $(CFLAGS) -c $< -I ../../dist/src + +vector_to_header.out: ../vector_to_header.c + $(CC) $(CFLAGS) $< -o $@ + +chacha20.all.vec : chacha20.vec ../vectors/chacha20 +poly1305.all.vec : poly1305.vec ../vectors/poly1305 +x25519.all.vec : x25519.vec ../vectors/x25519 +xchacha20.all.vec : xchacha20.vec +blake2b.all.vec : blake2b.vec +sha512.all.vec : sha512.vec +argon2i.all.vec : argon2i.vec +edDSA.all.vec : edDSA.vec +key_exchange.all.vec: ../vectors/key_exchange +$(VEC2): + mkdir -p $(@D) + cat $^ > $@ + +%.h.vec: %.all.vec vector_to_header.out + ./vector_to_header.out $(patsubst %.all.vec,%,$<) < $< > $@ -# Needed for Ed25519 -sha512.o: ../../dist/src/sha512.c - $(CC) $(CFLAGS) -o $@ -c $^ \ - -I ../../dist/src + $(VECTORS): $(HEADERS) + cat $^ > $@