]> git.codecow.com Git - Monocypher.git/commitdiff
Added ed25519 tests
authorLoup Vaillant <loup@loup-vaillant.fr>
Fri, 20 Apr 2018 22:37:41 +0000 (00:37 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Fri, 20 Apr 2018 22:37:41 +0000 (00:37 +0200)
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.

tests/gen/ed_25519.c [new file with mode: 0644]
tests/gen/makefile
tests/test.c
tests/test.sh

diff --git a/tests/gen/ed_25519.c b/tests/gen/ed_25519.c
new file mode 100644 (file)
index 0000000..9eca523
--- /dev/null
@@ -0,0 +1,24 @@
+#include <sodium.h>
+#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;
+}
index 3a102b849877c69b9876104ab224bef7abaa9099..351b84dc4e5562dec38c06d4f85c7fb71c37c956 100644 (file)
@@ -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)
index f5e9f6a49f8cfc71768e541783b302b54061fcf6..b0073eb076341a2e903f32f2517dc85becaf4c66 100644 (file)
@@ -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");
index a43a10d2d05ce29ff8cf208d5c648eaadac3be1e..a312ba2077cca0a6e98982aaf0ce833c6de03d47 100755 (executable)
@@ -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"