X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/0f00dc4c8eb47e67bc0f148c2dd109f73a451e0a..3a1a6c353881dca502bcd32026c5a566474c8354:/symm/ofb-def.h diff --git a/symm/ofb-def.h b/symm/ofb-def.h index 6b1357d0..e9eb5034 100644 --- a/symm/ofb-def.h +++ b/symm/ofb-def.h @@ -65,7 +65,9 @@ * Use: Creates definitions for output feedback mode. */ -#define OFB_DEF(PRE, pre) \ +#define OFB_DEF(PRE, pre) OFB_DEFX(PRE, pre, #pre, #pre) + +#define OFB_DEFX(PRE, pre, name, fname) \ \ /* --- @pre_ofbgetiv@ --- * \ * \ @@ -306,7 +308,7 @@ static const gcipher_ops gops = { \ }; \ \ const gccipher pre##_ofb = { \ - #pre "-ofb", pre##_keysz, PRE##_BLKSZ, \ + name "-ofb", pre##_keysz, PRE##_BLKSZ, \ ginit \ }; \ \ @@ -407,10 +409,10 @@ static void grfill(grand *r, void *p, size_t sz) \ } \ \ static const grand_ops grops = { \ - #pre "-ofb", \ + name "-ofb", \ GRAND_CRYPTO, 0, \ grmisc, grdestroy, \ - grword, grbyte, grword, grand_range, grfill \ + grword, grbyte, grword, grand_defaultrange, grfill \ }; \ \ /* --- @pre_ofbrand@ --- * \ @@ -432,10 +434,12 @@ grand *pre##_ofbrand(const void *k, size_t sz) \ return (&g->r); \ } \ \ -OFB_TEST(PRE, pre) +OFB_TESTX(PRE, pre, name, name) /*----- Test rig ----------------------------------------------------------*/ +#define OFB_TEST(PRE, pre) OFB_TESTX(PRE, pre, #pre, #pre) + #ifdef TEST_RIG #include @@ -449,7 +453,7 @@ OFB_TEST(PRE, pre) * Use: Standard test rig for OFB functions. */ -#define OFB_TEST(PRE, pre) \ +#define OFB_TESTX(PRE, pre, name, fname) \ \ /* --- Initial plaintext for the test --- */ \ \ @@ -465,12 +469,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(':'); \ } \ } \ @@ -486,7 +490,7 @@ int main(void) \ size_t keysz = PRE##_KEYSZ ? \ PRE##_KEYSZ : strlen((const char *)key); \ \ - fputs(#pre "-ofb: ", stdout); \ + fputs(name "-ofb: ", stdout); \ \ pre##_init(&k, key, keysz); \ pre##_ofbsetkey(&ctx, &k); \ @@ -511,14 +515,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); \ } \ @@ -533,7 +537,7 @@ int main(void) \ } #else -# define OFB_TEST(PRE, pre) +# define OFB_TESTX(PRE, pre, name, fname) #endif /*----- That's all, folks -------------------------------------------------*/