]> git.codecow.com Git - Monocypher.git/commitdiff
Added tests for HChacha20
authorLoup Vaillant <loup@loup-vaillant.fr>
Thu, 16 Aug 2018 19:29:13 +0000 (21:29 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Thu, 16 Aug 2018 19:29:13 +0000 (21:29 +0200)
Not that it needed any (XChacha20 were enough), but it's easier to
communicate to outsiders that HChacha20 is correct when we have explicit
test vectors.

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

diff --git a/tests/gen/hchacha20.c b/tests/gen/hchacha20.c
new file mode 100644 (file)
index 0000000..a7e5b1b
--- /dev/null
@@ -0,0 +1,22 @@
+#include <sodium.h>
+#include "utils.h"
+
+int main(void)
+{
+    SODIUM_INIT;
+
+    FOR (size, 0, 50) {
+        RANDOM_INPUT(key  , 32);
+        RANDOM_INPUT(in   , 16);
+        u8 out[32];
+
+        crypto_core_hchacha20(out, in, key, 0);
+
+        print_vector(key   , 32);
+        print_vector(in    , 16);
+        print_vector(out   , 32);
+        printf("\n");
+    }
+
+    return 0;
+}
index 57fa8ee81101e33e25ec16f9b7223cdede95ea44..eb5369df884224342d9b564df2c8979af2379d52 100644 (file)
@@ -3,9 +3,9 @@ CFLAGS = -pedantic -Wall -Wextra
 
 .PHONY: all clean
 
-VEC     = chacha20.vec xchacha20.vec aead_ietf.vec poly1305.vec       \
-          blake2b.vec  sha512.vec    argon2i.vec                      \
-          edDSA.vec    edDSA_pk.vec  ed_25519.vec  ed_25519_check.vec \
+VEC     = chacha20.vec hchacha20.vec xchacha20.vec aead_ietf.vec poly1305.vec \
+          blake2b.vec  sha512.vec    argon2i.vec                              \
+          edDSA.vec    edDSA_pk.vec  ed_25519.vec  ed_25519_check.vec         \
           x25519.vec   x25519_pk.vec
 VEC2    = $(patsubst %.vec, %.all.vec, $(VEC)) key_exchange.all.vec
 HEADERS = $(patsubst %.all.vec, %.h.vec, $(VEC2))
@@ -48,6 +48,7 @@ chacha20.all.vec      : chacha20.vec  ../vectors/chacha20
 poly1305.all.vec      : poly1305.vec  ../vectors/poly1305
 x25519.all.vec        : x25519.vec    ../vectors/x25519
 x25519_pk.all.vec     : x25519_pk.vec
+hchacha20.all.vec     : hchacha20.vec
 xchacha20.all.vec     : xchacha20.vec
 aead_ietf.all.vec     : aead_ietf.vec
 blake2b.all.vec       : blake2b.vec
index 758bc0c50c27bccdc69a10567980c4ea49f4a581..88a7d680dfdc41aab0203e99796e0c185388b90a 100644 (file)
@@ -103,6 +103,13 @@ static void chacha20(const vector in[], vector *out)
     crypto_chacha20_encrypt(&ctx, out->buf, plain->buf, plain->size);
 }
 
+static void hchacha20(const vector in[], vector *out)
+{
+    const vector *key   = in;
+    const vector *nonce = in + 1;
+    crypto_chacha20_H(out->buf, key->buf, nonce->buf);
+}
+
 static void xchacha20(const vector in[], vector *out)
 {
     const vector *key   = in;
@@ -821,6 +828,7 @@ int main(void)
     printf("\nTest against vectors");
     printf("\n--------------------\n");
     status |= TEST(chacha20      , 4);
+    status |= TEST(hchacha20     , 2);
     status |= TEST(xchacha20     , 4);
     status |= TEST(poly1305      , 2);
     status |= TEST(aead_ietf     , 4);