]> git.codecow.com Git - Monocypher.git/commitdiff
Completed test coverage
authorLoup Vaillant <loup@loup-vaillant.fr>
Mon, 9 Dec 2019 13:14:21 +0000 (14:14 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Mon, 9 Dec 2019 13:14:21 +0000 (14:14 +0100)
tests/gen/ed_25519_pk.c [new file with mode: 0644]
tests/gen/makefile
tests/test.c

diff --git a/tests/gen/ed_25519_pk.c b/tests/gen/ed_25519_pk.c
new file mode 100644 (file)
index 0000000..2e2e22a
--- /dev/null
@@ -0,0 +1,26 @@
+#include <sodium.h>
+#include "utils.h"
+
+static void test(u8 seed[32])
+{
+    u8 pk[32];
+    u8 sk[64];
+    crypto_sign_seed_keypair(pk, sk, seed);
+    print_vector(sk, 32);
+    print_vector(pk, 32);
+}
+
+int main(void)
+{
+    SODIUM_INIT;
+    // random secret keys
+    FOR (msg_size, 0, 256) {
+        RANDOM_INPUT(sk,  32);
+        test(sk);
+    }
+    // zero secret key
+    u8 sk[32] = {0};
+    test(sk);
+
+    return 0;
+}
index d1f127de7eb9528076d55c545bc27cc8214e717e..2a200ea349871a54fe60a6e30f2d3f63c3beaa36 100644 (file)
@@ -3,9 +3,9 @@ CFLAGS = -pedantic -Wall -Wextra
 
 .PHONY: all clean
 
-VEC     = chacha20  hchacha20  xchacha20    ietf_chacha20 aead_ietf  \
-          poly1305  blake2b    sha512       hmac_sha512   argon2i    \
-          edDSA     edDSA_pk   ed_25519     ed_25519_check           \
+VEC     = chacha20  hchacha20  xchacha20    ietf_chacha20 aead_ietf      \
+          poly1305  blake2b    sha512       hmac_sha512   argon2i        \
+          edDSA     edDSA_pk   ed_25519     ed_25519_pk   ed_25519_check \
           x25519    x25519_pk  key_exchange
 #          monokex_xk1 monokex_x
 VEC2    = $(patsubst %, %.all.vec, $(VEC))
@@ -65,6 +65,7 @@ argon2i.all.vec       : argon2i.vec     vectors/argon2i
 edDSA.all.vec         : edDSA.vec
 edDSA_pk.all.vec      : edDSA_pk.vec
 ed_25519.all.vec      : ed_25519.vec
+ed_25519_pk.all.vec   : ed_25519_pk.vec
 ed_25519_check.all.vec:                 vectors/ed_25519_check
 key_exchange.all.vec  :                 vectors/key_exchange
 monokex_xk1.all.vec   : monokex_xk1.vec
index fd53b29b991000d0682228acd5538b1a2c068a8b..01acd6533c72d6f3baebecfb4d9d1ddc7fc5b7a3 100644 (file)
@@ -182,6 +182,11 @@ static void ed_25519(const vector in[], vector *out)
     }
 }
 
+static void ed_25519_pk(const vector in[], vector *out)
+{
+    crypto_ed25519_public_key(out->buf, in->buf);
+}
+
 static void ed_25519_check(const vector in[], vector *out)
 {
     const vector *public_k = in;
@@ -268,6 +273,37 @@ static int p_verify16(){ return p_verify(16, crypto_verify16); }
 static int p_verify32(){ return p_verify(32, crypto_verify32); }
 static int p_verify64(){ return p_verify(64, crypto_verify64); }
 
+static int p_chacha20_ctr()
+{
+    int status = 0;
+    RANDOM_INPUT(key  ,  32);
+    RANDOM_INPUT(nonce,  24);
+    RANDOM_INPUT(plain, 128);
+    u8 out_full[128];
+    u8 out1     [64];
+    u8 out2     [64];
+    crypto_chacha20    (out_full, plain     , 128, key, nonce);
+    crypto_chacha20_ctr(out1    , plain +  0,  64, key, nonce, 0);
+    crypto_chacha20_ctr(out2    , plain + 64,  64, key, nonce, 1);
+    status |= memcmp(out_full     , out1, 64);
+    status |= memcmp(out_full + 64, out2, 64);
+
+    crypto_ietf_chacha20    (out_full, plain     , 128, key, nonce);
+    crypto_ietf_chacha20_ctr(out1    , plain +  0,  64, key, nonce, 0);
+    crypto_ietf_chacha20_ctr(out2    , plain + 64,  64, key, nonce, 1);
+    status |= memcmp(out_full     , out1, 64);
+    status |= memcmp(out_full + 64, out2, 64);
+
+    crypto_xchacha20    (out_full, plain     , 128, key, nonce);
+    crypto_xchacha20_ctr(out1    , plain +  0,  64, key, nonce, 0);
+    crypto_xchacha20_ctr(out2    , plain + 64,  64, key, nonce, 1);
+    status |= memcmp(out_full     , out1, 64);
+    status |= memcmp(out_full + 64, out2, 64);
+
+    printf("%s: Chacha20 (ctr)\n", status != 0 ? "FAILED" : "OK");
+    return status;
+}
+
 // Tests that Chacha20(nullptr) == Chacha20(all-zeroes)
 static int p_chacha20_stream()
 {
@@ -741,6 +777,7 @@ int main(int argc, char *argv[])
     status |= TEST(edDSA         , 3);
     status |= TEST(edDSA_pk      , 1);
     status |= TEST(ed_25519      , 3);
+    status |= TEST(ed_25519_pk   , 1);
     status |= TEST(ed_25519_check, 3);
     status |= test_x25519();
 
@@ -749,6 +786,7 @@ int main(int argc, char *argv[])
     status |= p_verify16();
     status |= p_verify32();
     status |= p_verify64();
+    status |= p_chacha20_ctr();
     status |= p_chacha20_stream();
     status |= p_chacha20_same_ptr();
     status |= p_hchacha20();