From: Loup Vaillant Date: Fri, 20 Apr 2018 22:37:41 +0000 (+0200) Subject: Added ed25519 tests X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=be33cc35d9288adc7cbaf7909ef4f30318d09cb0;p=Monocypher.git Added ed25519 tests Monocypher failed to compile with -DED25519_SHA512 since we added the incremental interface. The error has been corrected by the #95 Pull Request by @vbmithr. To make sure this doesn't happen again, the test suite has been expanded to include the official Ed25519 construction. You can test it thus: $ make clean $ make test CFLAGS="-DED25519_SHA512 -O3" Or just run `tests/test.sh` to have the whole shebang. --- diff --git a/tests/gen/ed_25519.c b/tests/gen/ed_25519.c new file mode 100644 index 0000000..9eca523 --- /dev/null +++ b/tests/gen/ed_25519.c @@ -0,0 +1,24 @@ +#include +#include "utils.h" + +void test(size_t msg_size) +{ + RANDOM_INPUT(seed, 32); + RANDOM_INPUT(msg , 256); + u8 pk[32], sk[64], sig[64]; + + crypto_sign_seed_keypair(pk, sk, seed); + crypto_sign_detached(sig, 0, msg, msg_size, sk); + + print_vector(sk , 32 ); + print_vector(pk , 32 ); + print_vector(msg, msg_size); + print_vector(sig, 64 ); +} + +int main(void) +{ + SODIUM_INIT; + FOR (msg_size, 0, 256) { test(msg_size); } + return 0; +} diff --git a/tests/gen/makefile b/tests/gen/makefile index 3a102b8..351b84d 100644 --- a/tests/gen/makefile +++ b/tests/gen/makefile @@ -7,7 +7,7 @@ HASH = .PHONY: all clean VEC = chacha20.vec xchacha20.vec aead_ietf.vec poly1305.vec blake2b.vec \ - sha512.vec argon2i.vec edDSA.vec x25519.vec + sha512.vec argon2i.vec edDSA.vec ed_25519.vec x25519.vec VEC2 = $(patsubst %.vec, %.all.vec, $(VEC)) key_exchange.all.vec HEADERS = $(patsubst %.all.vec, %.h.vec, $(VEC2)) VECTORS = ../vectors.h @@ -60,6 +60,7 @@ blake2b.all.vec : blake2b.vec sha512.all.vec : sha512.vec argon2i.all.vec : argon2i.vec ../vectors/argon2i edDSA.all.vec : edDSA.vec +ed_25519.all.vec : ed_25519.vec key_exchange.all.vec: ../vectors/key_exchange $(VEC2): mkdir -p $(@D) diff --git a/tests/test.c b/tests/test.c index f5e9f6a..b0073eb 100644 --- a/tests/test.c +++ b/tests/test.c @@ -194,6 +194,10 @@ static void edDSA(const vector in[], vector *out) } } +#ifdef ED25519_SHA512 +static void (*ed_25519)(const vector[], vector*) = edDSA; +#endif + static void iterate_x25519(u8 k[32], u8 u[32]) { u8 tmp[32]; @@ -795,7 +799,11 @@ int main(void) status |= TEST(argon2i , 6); status |= TEST(x25519 , 2); status |= TEST(key_exchange, 2); +#ifdef ED25519_SHA512 + status |= TEST(ed_25519 , 3); +#else status |= TEST(edDSA , 3); +#endif status |= test_x25519(); printf("\nProperty based tests"); diff --git a/tests/test.sh b/tests/test.sh index a43a10d..a312ba2 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -3,6 +3,7 @@ set -e make clean; make test +make clean; make test CFLAGS="-DED25519_SHA512 -O3" make clean; make test CC="clang -std=c99" CFLAGS="-g -fsanitize=address" make clean; make test CC="clang -std=c99" CFLAGS="-g -fsanitize=memory" make clean; make test CC="clang -std=c99" CFLAGS="-g -fsanitize=undefined"