* 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@ --- * \
* \
}; \
\
const gccipher pre##_ofb = { \
- #pre "-ofb", pre##_keysz, PRE##_BLKSZ, \
+ name "-ofb", pre##_keysz, PRE##_BLKSZ, \
ginit \
}; \
\
} \
\
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@ --- * \
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 <stdio.h>
* Use: Standard test rig for OFB functions.
*/
-#define OFB_TEST(PRE, pre) \
+#define OFB_TESTX(PRE, pre, name, fname) \
\
/* --- Initial plaintext for the test --- */ \
\
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(':'); \
} \
} \
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); \
} 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); \
} \
}
#else
-# define OFB_TEST(PRE, pre)
+# define OFB_TESTX(PRE, pre, name, fname)
#endif
/*----- That's all, folks -------------------------------------------------*/