chiark / gitweb /
symm/hash.h: Add support for test vectors with hex-encoded messages.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 10 May 2017 20:53:25 +0000 (21:53 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 14 May 2017 13:58:42 +0000 (14:58 +0100)
symm/hash.h

index dc0bbaa12dafcfad774766ee17f577bf3a97c1be..dc9ad024d14f70a500e30e5e25742c547278969f 100644 (file)
 
 #define HASH_VERIFYX(PRE, pre, name)                                   \
                                                                        \
-static int vrf_##pre(dstr *v)                                          \
+static int vrf_##pre(dstr *v, const test_type *msgty)                  \
 {                                                                      \
   pre##_ctx ctx;                                                       \
   int ok = 1;                                                          \
@@ -201,8 +201,9 @@ static int vrf_##pre(dstr *v)                                               \
     }                                                                  \
     pre##_done(&ctx, d.buf);                                           \
     if (memcmp(d.buf, v[1].buf, PRE##_HASHSZ) != 0) {                  \
-      printf("\nfail:\n\tstep = %i\n\tinput = `%s'\n\texpected = ",    \
-            *ip, v[0].buf);                                            \
+      printf("\nfail:\n\tstep = %i\n\tinput = ", *ip);                 \
+      msgty->dump(&v[0], stdout);                                      \
+      printf("\n\texpected = ");                                       \
       type_hex.dump(&v[1], stdout);                                    \
       fputs("\n\tcomputed = ", stdout);                                        \
       type_hex.dump(&d, stdout);                                       \
@@ -215,6 +216,11 @@ static int vrf_##pre(dstr *v)                                              \
   return (ok);                                                         \
 }                                                                      \
                                                                        \
+static int vrf_##pre##_hex(dstr *v)                                    \
+  { return vrf_##pre(v, &type_hex); }                                  \
+static int vrf_##pre##_lit(dstr *v)                                    \
+  { return vrf_##pre(v, &type_string); }                               \
+                                                                       \
 static int vrf_##pre##_rep(dstr *v)                                    \
 {                                                                      \
   pre##_ctx ctx;                                                       \
@@ -255,7 +261,8 @@ static int vrf_##pre##_rep(dstr *v)                                 \
 #define HASH_TESTDEFS(PRE, pre) HASH_TESTDEFSX(PRE, pre, #pre)
 
 #define HASH_TESTDEFSX(PRE, pre, name)                                 \
-  { name, vrf_##pre, { &type_string, &type_hex, 0 } },                 \
+  { name, vrf_##pre##_lit, { &type_string, &type_hex, 0 } },           \
+  { name "-hex", vrf_##pre##_hex, { &type_hex, &type_hex, 0 } },       \
   { name "-rep", vrf_##pre##_rep,                                      \
     { &type_string, &type_int, &type_hex, 0 } },