From 4328f7469ba7f9539368a21107005009aa9d3a43 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 10 May 2017 20:26:41 +0100 Subject: [PATCH] symm/blkc.h, symm/hash.h: Factor out pieces of the test machinery. 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 | 7 ++++++- symm/hash.h | 25 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/symm/blkc.h b/symm/blkc.h index e0374f1a..1cbe729c 100644 --- a/symm/blkc.h +++ b/symm/blkc.h @@ -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 } } \ }; \ \ diff --git a/symm/hash.h b/symm/hash.h index f4925184..dc0bbaa1 100644 --- a/symm/hash.h +++ b/symm/hash.h @@ -165,9 +165,11 @@ #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 } } \ }; \ \ -- 2.11.0