X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/0f00dc4c8eb47e67bc0f148c2dd109f73a451e0a..c90ce6bb395bac18afa5b189e4664151d4d8ea2c:/symm/cfb-def.h diff --git a/symm/cfb-def.h b/symm/cfb-def.h index 767f4c42..78aa6d98 100644 --- a/symm/cfb-def.h +++ b/symm/cfb-def.h @@ -68,7 +68,9 @@ * Use: Creates an implementation for CFB mode. */ -#define CFB_DEF(PRE, pre) \ +#define CFB_DEF(PRE, pre) CFB_DEFX(PRE, pre, #pre, #pre) + +#define CFB_DEFX(PRE, pre, name, fname) \ \ /* --- @pre_cfbgetiv@ --- * \ * \ @@ -389,14 +391,16 @@ static const gcipher_ops gops = { \ }; \ \ const gccipher pre##_cfb = { \ - #pre "-cfb", pre##_keysz, PRE##_BLKSZ, \ + name "-cfb", pre##_keysz, PRE##_BLKSZ, \ ginit \ }; \ \ -CFB_TEST(PRE, pre) +CFB_TESTX(PRE, pre, name, fname) /*----- Test rig ----------------------------------------------------------*/ +#define CFB_TEST(PRE, pre) CFB_TESTX(PRE, pre, #pre, #pre) + #ifdef TEST_RIG #include @@ -410,7 +414,7 @@ CFB_TEST(PRE, pre) * Use: Standard test rig for CFB functions. */ -#define CFB_TEST(PRE, pre) \ +#define CFB_TESTX(PRE, pre, name, fname) \ \ /* --- Initial plaintext for the test --- */ \ \ @@ -426,12 +430,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(':'); \ } \ } \ @@ -447,7 +451,7 @@ int main(void) \ size_t keysz = PRE##_KEYSZ ? \ PRE##_KEYSZ : strlen((const char *)key); \ \ - fputs(#pre "-cfb: ", stdout); \ + fputs(name "-cfb: ", stdout); \ \ pre##_init(&k, key, keysz); \ pre##_cfbsetkey(&ctx, &k); \ @@ -472,14 +476,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); \ } \ @@ -494,7 +498,7 @@ int main(void) \ } #else -# define CFB_TEST(PRE, pre) +# define CFB_TESTX(PRE, pre, name, fname) #endif /*----- That's all, folks -------------------------------------------------*/