X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/0f00dc4c8eb47e67bc0f148c2dd109f73a451e0a..734a933080d78496fb41100a17815c4f21a41057:/symm/ecb-def.h diff --git a/symm/ecb-def.h b/symm/ecb-def.h index ea153a27..568ffa1e 100644 --- a/symm/ecb-def.h +++ b/symm/ecb-def.h @@ -65,7 +65,9 @@ * Use: Creates an implementation for ECB stealing mode. */ -#define ECB_DEF(PRE, pre) \ +#define ECB_DEF(PRE, pre) ECB_DEFX(PRE, pre, #pre, #pre) + +#define ECB_DEFX(PRE, pre, name, fname) \ \ /* --- @pre_ecbsetkey@ --- * \ * \ @@ -354,14 +356,16 @@ static const gcipher_ops gops = { \ }; \ \ const gccipher pre##_ecb = { \ - #pre "-ecb", pre##_keysz, PRE##_BLKSZ, \ + name "-ecb", pre##_keysz, PRE##_BLKSZ, \ ginit \ }; \ \ -ECB_TEST(PRE, pre) +ECB_TESTX(PRE, pre, name, fname) /*----- Test rig ----------------------------------------------------------*/ +#define ECB_TEST(PRE, pre) ECB_TESTX(PRE, pre, #pre, #pre) + #ifdef TEST_RIG #include @@ -375,7 +379,7 @@ ECB_TEST(PRE, pre) * Use: Standard test rig for ECB functions. */ -#define ECB_TEST(PRE, pre) \ +#define ECB_TESTX(PRE, pre, name, fname) \ \ /* --- Initial plaintext for the test --- */ \ \ @@ -391,12 +395,12 @@ static const octet iv[] = IV; \ static octet ct[sizeof(text)]; \ static octet pt[sizeof(text)]; \ \ -static void hexdump(const octet *p, size_t sz) \ +static void hexdump(const octet *p, size_t sz, size_t off) \ { \ const octet *q = p + sz; \ for (sz = 0; p < q; p++, sz++) { \ printf("%02x", *p); \ - if ((sz + 1) % PRE##_BLKSZ == 0) \ + if ((off + sz + 1) % PRE##_BLKSZ == 0) \ putchar(':'); \ } \ } \ @@ -411,7 +415,7 @@ int main(void) \ size_t keysz = PRE##_KEYSZ ? \ PRE##_KEYSZ : strlen((const char *)key); \ \ - fputs(#pre "-ecb: ", stdout); \ + fputs(name "-ecb: ", stdout); \ \ pre##_ecbinit(&ctx, key, keysz, iv); \ \ @@ -436,14 +440,14 @@ int main(void) \ } else { \ printf("\nError (sz = %lu)\n", (unsigned long)sz); \ status = 1; \ - printf("\tplaintext = "); hexdump(text, sz); \ - printf(", "); hexdump(text + sz, rest); \ + printf("\tplaintext = "); hexdump(text, sz, 0); \ + printf(", "); hexdump(text + sz, rest, sz); \ fputc('\n', stdout); \ - printf("\tciphertext = "); hexdump(ct, sz); \ - printf(", "); hexdump(ct + sz, rest); \ + printf("\tciphertext = "); hexdump(ct, sz, 0); \ + printf(", "); hexdump(ct + sz, rest, sz); \ fputc('\n', stdout); \ - printf("\trecovered text = "); hexdump(pt, sz); \ - printf(", "); hexdump(pt + sz, rest); \ + printf("\trecovered text = "); hexdump(pt, sz, 0); \ + printf(", "); hexdump(pt + sz, rest, sz); \ fputc('\n', stdout); \ fputc('\n', stdout); \ } \ @@ -459,7 +463,7 @@ int main(void) \ } #else -# define ECB_TEST(PRE, pre) +# define ECB_TESTX(PRE, pre, name, fname) #endif /*----- That's all, folks -------------------------------------------------*/