* Use: Creates implementations for the HMAC and NMAC functions.
*/
-#define HMAC_DEF(PRE, pre) \
+#define HMAC_DEF(PRE, pre) HMAC_DEFX(PRE, pre, #pre, #pre)
+#define HMAC_DEFX(PRE, pre, name, fname) \
\
/* --- Useful constants --- */ \
\
-const octet pre##_hmackeysz[] = { KSZ_ANY, PRE##_STATESZ }; \
-const octet pre##_sslmackeysz[] = { KSZ_ANY, PRE##_STATESZ }; \
-const octet pre##_nmackeysz[] = { KSZ_SET, 2 * PRE##_STATESZ, 0 }; \
+const octet pre##_hmackeysz[] = \
+ { KSZ_ANY | KSZ_16BIT, PRE##_STATESZ/256, PRE##_STATESZ%256 }; \
+const octet pre##_sslmackeysz[] = \
+ { KSZ_ANY | KSZ_16BIT, PRE##_STATESZ/256, PRE##_STATESZ%256 }; \
+const octet pre##_nmackeysz[] = \
+ { KSZ_SET | KSZ_16BIT, \
+ 2*PRE##_STATESZ/256, 2*PRE##_STATESZ%256, 0, 0 }; \
\
/* --- @pre_nmacinit@ --- * \
* \
} \
\
const gcmac pre##_nmac = \
- { #pre "-nmac", PRE##_HASHSZ, pre##_nmackeysz, gnkey }; \
+ { name "-nmac", PRE##_HASHSZ, pre##_nmackeysz, gnkey }; \
const gcmac pre##_hmac = \
- { #pre "-hmac", PRE##_HASHSZ, pre##_hmackeysz, gkey }; \
+ { name "-hmac", PRE##_HASHSZ, pre##_hmackeysz, gkey }; \
const gcmac pre##_sslmac = \
- { #pre "-sslmac", PRE##_HASHSZ, pre##_sslmackeysz, gsslkey }; \
+ { name "-sslmac", PRE##_HASHSZ, pre##_sslmackeysz, gsslkey }; \
static const gmac_ops gkops = { &pre##_hmac, gkinit, gkdestroy }; \
static const gmac_ops gnkops = { &pre##_nmac, gkinit, gkdestroy }; \
static const gmac_ops gsslkops = { &pre##_sslmac, gkinit, gkdestroy }; \
-static const gchash gch = { #pre "-hmac", PRE##_HASHSZ, ghinit }; \
+static const gchash gch = { name "-hmac", PRE##_HASHSZ, ghinit }; \
static const ghash_ops gops = \
{ &gch, ghhash, ghdone, ghdestroy, ghcopy }; \
-static const gchash gnch = { #pre "-nmac", PRE##_HASHSZ, ghinit }; \
+static const gchash gnch = { name "-nmac", PRE##_HASHSZ, ghinit }; \
static const ghash_ops gnops = \
{ &gch, ghhash, ghdone, ghdestroy, ghcopy }; \
-static const gchash gsslch = { #pre "-sslmac", PRE##_HASHSZ, ghinit }; \
+static const gchash gsslch = { name "-sslmac", PRE##_HASHSZ, ghinit }; \
static const ghash_ops gsslops = \
{ &gch, ghhash, ghdone, ghdestroy, ghcopy }; \
\
-HMAC_TEST(PRE, pre)
+HMAC_TESTX(PRE, pre, name, fname)
+
+#define HMAC_TEST(PRE, pre) HMAC_TESTX(PRE, pre, #pre, #pre)
/* --- @HMAC_TEST@ --- *
*
#include <mLib/quis.h>
#include <mLib/testrig.h>
-#define HMAC_TEST(PRE, pre) \
+#define HMAC_TESTX(PRE, pre, name, fname) \
\
static int macverify(dstr *v) \
{ \
} \
\
static test_chunk macdefs[] = { \
- { #pre "-hmac", macverify, \
+ { name "-hmac", macverify, \
{ &type_string, &type_hex, &type_hex, 0 } }, \
{ 0, 0, { 0 } } \
}; \
int main(int argc, char *argv[]) \
{ \
ego(argv[0]); \
- test_run(argc, argv, macdefs, SRCDIR"/t/" #pre); \
+ test_run(argc, argv, macdefs, SRCDIR"/t/" fname); \
return (0); \
}
#else
-# define HMAC_TEST(PRE, pre)
+# define HMAC_TESTX(PRE, pre, name, fname)
#endif
/*----- That's all, folks -------------------------------------------------*/