chiark / gitweb /
symm/blkc.h, symm/hash.h: Factor out pieces of the test machinery.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 10 May 2017 19:26:41 +0000 (20:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 14 May 2017 13:58:41 +0000 (14:58 +0100)
This will allow a source file to include tests for a hash function or
block cipher /and/ other kinds of tests.  Possibly even for another hash
function or block cipher.

This was mostly done already for block ciphers: the remaining piece
involved making a macro to populate the test table.  But hash functions
haven't been as fortunate.

Fix the new definitions to allow non-identifier names for hashes and
block ciphers, to match the mode definitions.

symm/blkc.h
symm/hash.h

index e0374f1abcf0da4aec6193e2680a75645846362d..1cbe729c73573db7034ede47aa7910c92c43e685 100644 (file)
@@ -318,12 +318,17 @@ static int pre##_verify(dstr *v)                                  \
   return (ok);                                                         \
 }
 
+#define BLKC_TESTDEFS(PRE, pre) BLKC_TESTDEFSX(PRE, pre, #pre)
+
+#define BLKC_TESTDEFSX(PRE, pre, name)                                 \
+  { name, pre##_verify, { &type_hex, &type_hex, &type_hex, 0 } },
+
 #define BLKC_TESTX(PRE, pre, name, fname)                              \
                                                                        \
 BLKC_VERIFYX(PRE, pre, name)                                           \
                                                                        \
 static const test_chunk defs[] = {                                     \
-  { name, pre##_verify, { &type_hex, &type_hex, &type_hex, 0 } },      \
+  BLKC_TESTDEFSX(PRE, pre, name)                                       \
   { 0, 0, { 0 } }                                                      \
 };                                                                     \
                                                                        \
index f49251842034866d3ee7004b4e90cf4b6000692c..dc0bbaa12dafcfad774766ee17f577bf3a97c1be 100644 (file)
 
 #define HASH_BUFLEN 100000
 
-#define HASH_TESTX(PRE, pre, name, fname)                              \
+#define HASH_VERIFY(PRE, pre) HASH_VERIFYX(PRE, pre, #pre)
+
+#define HASH_VERIFYX(PRE, pre, name)                                   \
                                                                        \
-static int verify(dstr *v)                                             \
+static int vrf_##pre(dstr *v)                                          \
 {                                                                      \
   pre##_ctx ctx;                                                       \
   int ok = 1;                                                          \
@@ -213,7 +215,7 @@ static int verify(dstr *v)                                          \
   return (ok);                                                         \
 }                                                                      \
                                                                        \
-static int verifyrep(dstr *v)                                          \
+static int vrf_##pre##_rep(dstr *v)                                    \
 {                                                                      \
   pre##_ctx ctx;                                                       \
   size_t len = v[0].len;                                               \
@@ -248,12 +250,21 @@ static int verifyrep(dstr *v)                                             \
   xfree(p);                                                            \
   dstr_destroy(&d);                                                    \
   return (ok);                                                         \
-}                                                                      \
+}
+
+#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 "-rep", vrf_##pre##_rep,                                      \
+    { &type_string, &type_int, &type_hex, 0 } },
+
+#define HASH_TESTX(PRE, pre, name, fname)                              \
+                                                                       \
+HASH_VERIFYX(PRE, pre, name)                                           \
                                                                        \
 static test_chunk defs[] = {                                           \
-  { name, verify, { &type_string, &type_hex, 0 } },                    \
-  { name "-rep", verifyrep,                                            \
-    { &type_string, &type_int, &type_hex, 0 } },                       \
+  HASH_TESTDEFSX(PRE, pre, name)                                       \
   { 0, 0, { 0 } }                                                      \
 };                                                                     \
                                                                        \