]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
(decode_hex_reverse): New function.
authorNiels Möller <nisse@lysator.liu.se>
Fri, 15 Apr 2011 18:59:37 +0000 (20:59 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Fri, 15 Apr 2011 18:59:37 +0000 (20:59 +0200)
(RH, RHL): New macros.
(test_main): Byte reverse inputs and outputs for the testvectors
taken from the serpent submission package. Enable test vectors
from http://www.cs.technion.ac.il/~biham/Reports/Serpent/.

Rev: nettle/testsuite/serpent-test.c:1.3

testsuite/serpent-test.c

index 8c39632b394459c8500a03f88dee9dc0d284b85e..c00b0c3a8cd7ab6bd680175f60180b6df552d8f8 100644 (file)
@@ -1,58 +1,81 @@
 #include "testutils.h"
 #include "serpent.h"
 
+static uint8_t *
+decode_hex_reverse (const char *hex)
+{
+  unsigned length = decode_hex_length (hex);
+  uint8_t *p = xalloc(length);
+  unsigned i;
+
+  decode_hex(p, hex);
+
+  for (i = 0; i < (length+1)/2; i++)
+    {
+      uint8_t t = p[i];
+      p[i] = p[length - 1 - i];
+      p[length - 1 - i] = t;
+    }
+  return p;
+}
+
+#define RH(x) decode_hex_reverse(x)
+#define RHL(x) decode_hex_length(x), decode_hex_reverse(x)
+
 int
 test_main(void)
 {
   /* The first test for each key size from the ecb_vk.txt and ecb_vt.txt
    * files in the serpent package. */
 
+  /* NOTE: These vectors uses strange byte-reversed order of inputs
+     and outputs. */
   /* 128 bit key */
 
   /* vk, 1 */
   test_cipher(&nettle_serpent128,
-             HL("8000000000000000 0000000000000000"),
-             HL("0000000000000000 0000000000000000"),
-             H("49AFBFAD9D5A3405 2CD8FFA5986BD2DD"));
+             RHL("8000000000000000 0000000000000000"),
+             RHL("0000000000000000 0000000000000000"),
+             RH("49AFBFAD9D5A3405 2CD8FFA5986BD2DD"));
 
   /* vt, 1 */
   test_cipher(&nettle_serpent128,
-             HL("0000000000000000 0000000000000000"),
-             HL("8000000000000000 0000000000000000"),
-             H("10B5FFB720B8CB90 02A1142B0BA2E94A"));
+             RHL("0000000000000000 0000000000000000"),
+             RHL("8000000000000000 0000000000000000"),
+             RH("10B5FFB720B8CB90 02A1142B0BA2E94A"));
 
   /* 192 bit key */
 
   /* vk, 1 */
   test_cipher(&nettle_serpent192,
-             HL("8000000000000000 0000000000000000"
+             RHL("8000000000000000 0000000000000000"
                 "0000000000000000"),
-             HL("0000000000000000 0000000000000000"),
-             H("E78E5402C7195568 AC3678F7A3F60C66"));
+             RHL("0000000000000000 0000000000000000"),
+             RH("E78E5402C7195568 AC3678F7A3F60C66"));
 
   /* vt, 1 */
   test_cipher(&nettle_serpent192,
-             HL("0000000000000000 0000000000000000"
+             RHL("0000000000000000 0000000000000000"
                 "0000000000000000"),
-             HL("8000000000000000 0000000000000000"),
-             H("B10B271BA25257E1 294F2B51F076D0D9"));
+             RHL("8000000000000000 0000000000000000"),
+             RH("B10B271BA25257E1 294F2B51F076D0D9"));
 
   /* 256 bit key */
 
   /* vk, 1 */
   test_cipher(&nettle_serpent256,
-             HL("8000000000000000 0000000000000000"
+             RHL("8000000000000000 0000000000000000"
                 "0000000000000000 0000000000000000"),
-             HL("0000000000000000 0000000000000000"),
-             H("ABED96E766BF28CB C0EBD21A82EF0819"));
+             RHL("0000000000000000 0000000000000000"),
+             RH("ABED96E766BF28CB C0EBD21A82EF0819"));
 
   /* vt, 1 */
   test_cipher(&nettle_serpent256,
-             HL("0000000000000000 0000000000000000"
+             RHL("0000000000000000 0000000000000000"
                 "0000000000000000 0000000000000000"),
-             HL("8000000000000000 0000000000000000"),
-             H("DA5A7992B1B4AE6F 8C004BC8A7DE5520"));
-#if 0
+             RHL("8000000000000000 0000000000000000"),
+             RH("DA5A7992B1B4AE6F 8C004BC8A7DE5520"));
+
   /* Test vectors from
      http://www.cs.technion.ac.il/~biham/Reports/Serpent/ */
 
@@ -91,12 +114,11 @@ test_main(void)
              H("2868B7A2D28ECD5E4FDEFAC3C4330074"));
 
   /* Set 4, vector#  1 */
-    test_cipher(&nettle_serpent256,
-               HL("2BD6459F82C5B300952C49104881FF48"
-                  "2BD6459F82C5B300952C49104881FF48"),
-               HL("EA024714AD5C4D84EA024714AD5C4D84"),
-               H("3E507730776B93FDEA661235E1DD99F0"));
-#endif
+  test_cipher(&nettle_serpent256,
+             HL("2BD6459F82C5B300952C49104881FF48"
+                "2BD6459F82C5B300952C49104881FF48"),
+             HL("EA024714AD5C4D84EA024714AD5C4D84"),
+             H("3E507730776B93FDEA661235E1DD99F0"));
 
   SUCCESS();
 }