]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Additional salsa20 test, with simpler input structure.
authorNiels Möller <nisse@lysator.liu.se>
Mon, 6 Jul 2020 21:12:54 +0000 (23:12 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Mon, 6 Jul 2020 21:12:54 +0000 (23:12 +0200)
ChangeLog
testsuite/salsa20-test.c

index 4687f4e4b9866373a25361d1808f4e20a1287a70..f7b2e93933ec44891526acf990095609e74fc659 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2020-07-06  Niels Möller  <nisse@lysator.liu.se>
 
+       * testsuite/salsa20-test.c (test_salsa20_core): New function, test
+       salsa20 with simple input structure.
+
        * configure.ac: Obey --enable-arm-neon=yes, even if not explicitly
        targetting ARM v6 or later.
 
index 3a1b8eab49871a34c7ef196ce9edd6283e77aba0..d633c3a5e0945b1e612370ee5d7436a40a1ac916 100644 (file)
@@ -118,6 +118,74 @@ test_salsa20_stream(const struct tstring *key,
     }
 }
 
+/* Test with simple structure of the salsa20 input, to aid
+   debugging. */
+static void
+test_salsa20_core(void)
+{
+  const uint32_t input[16] =
+    {
+     0, 1, 2, 3,
+     4, 5, 6, 7,
+     /* Second block will have carry from first counter word propagate
+       to next word. */
+     0xffffffff, 9, 10, 11,
+     12, 13, 14, 15
+    };
+
+  const struct tstring *expected_12
+    = SHEX("c456dd00835121fa 2f3f818adea91c66"
+          "c024ec78191dbef8 4e828fde71420f4f"
+          "2edb91cc7ae72fe6 1c6d96d1169241f5"
+          "8d34bec538389247 1b2f71089992fd2b"
+          "a1194b4875788ee5 731f27c32481450b"
+          "4cc7b2a3f8ac7f43 6f42bd16a71cb721"
+          "299f6d9481e4bc87 23b5c0a2f142e507"
+          "34b7fe35fe292f2f 1bf9ae5296afdbeb");
+
+  const struct tstring *expected_20
+    = SHEX(
+          "02e02587e69cd380 3e5f3c53f0c29173"
+          "d3becef2da8da494 e8d1d4294270fc5e"
+          "a2c2001a6a45dc71 a3699e6594af795f"
+          "299814ae4f73650b e1d13040031dbfef"
+          "46b5b8ce5dc5b255 78b2695eb61fa816"
+          "7e22958311e2d585 826f4ebf1c7b3c98"
+          "a2857c3e4edc6f9e ed4312d698ddad55"
+          "57d13942292f8713 63eb7a5ab07a707e");
+
+  struct salsa20_ctx ctx;
+  uint8_t output[128];
+
+  ASSERT (expected_12->length == 128);
+  ASSERT (expected_20->length == 128);
+
+  /* Two blocks, to exercises _salsa20_2core, if available. */
+  memcpy (&ctx, input, sizeof(ctx));
+  salsa20r12_crypt (&ctx, 128, output, expected_12->data);
+
+  if (!memzero_p (output, 128))
+    {
+      fprintf(stderr, "salsa20r12_crypt failed:\n");
+      fprintf(stderr, "\nOutput: ");
+      print_hex(128, output);
+      fprintf(stderr, "\n");
+      FAIL();
+    }
+
+  memcpy (&ctx, input, sizeof(ctx));
+  salsa20_crypt (&ctx, 128, output, expected_20->data);
+
+  if (!memzero_p (output, 128))
+    {
+      fprintf(stderr, "salsa20_crypt failed:\n");
+      fprintf(stderr, "\nOutput: ");
+      print_hex(128, output);
+      fprintf(stderr, "\n");
+      FAIL();
+    }
+}
+
 typedef void salsa20_func(struct salsa20_ctx *ctx,
                          size_t length, uint8_t *dst,
                          const uint8_t *src);
@@ -191,6 +259,8 @@ _test_salsa20(salsa20_func *crypt,
 void
 test_main(void)
 {
+  test_salsa20_core();
+
   /* http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/salsa20/reduced/12-rounds/verified.test-vectors?logsort=rev&rev=210&view=markup */
   test_salsa20r12(SHEX("80000000 00000000 00000000 00000000"),
                  SHEX("00000000 00000000"),