]> git.codecow.com Git - Monocypher.git/commitdiff
added XChacha20 comparison with libsodium
authorLoup Vaillant <loup@loup-vaillant.fr>
Sun, 9 Jul 2017 12:12:33 +0000 (14:12 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Sun, 9 Jul 2017 12:12:33 +0000 (14:12 +0200)
tests/sodium.c

index bf807c750fc1aed969467b77ef4422094d8076ec..f8d0e96f9624a57e95001f90fb0d8a52288e62ce 100644 (file)
@@ -41,6 +41,24 @@ static int chacha20(void)
     return status;
 }
 
+static int xchacha20(void)
+{
+    u8  key[32], nonce[24], in[256], mono[256], sodium[256];
+    int status = 0;
+    FOR (size, 0, 256) FOR(i, 0, 10) {
+        p_random(key, 32);
+        p_random(nonce, 24);
+        p_random(in, size);
+        rename_chacha_ctx ctx;
+        rename_chacha20_Xinit(&ctx, key, nonce);
+        rename_chacha20_encrypt(&ctx, mono, in, size);
+        crypto_stream_xchacha20_xor(sodium, in, size, nonce, key);
+        status |= rename_memcmp(mono, sodium, size);
+    }
+    printf("%s: XChacha20\n", status != 0 ? "FAILED" : "OK");
+    return status;
+}
+
 static int poly1305(void)
 {
     u8 key[32], in[256], mono[16], sodium[16];
@@ -146,6 +164,7 @@ int main(void)
     }
     int status = 0;
     status |= chacha20();
+    status |= xchacha20();
     status |= poly1305();
     status |= blake2b();
     status |= argon2i();