From cf9d9d388289b20c4ff9fabd4fe356288c419bef Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 10 May 2017 21:53:25 +0100 Subject: [PATCH] symm/hash.h: Add support for test vectors with hex-encoded messages. --- symm/hash.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/symm/hash.h b/symm/hash.h index dc0bbaa1..dc9ad024 100644 --- a/symm/hash.h +++ b/symm/hash.h @@ -169,7 +169,7 @@ #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 } }, -- 2.11.0