/* --- Useful constants --- */ \
\
const octet pre##_hmackeysz[] = \
- { KSZ_ANY | KSZ_16BIT, PRE##_STATESZ/256, PRE##_STATESZ%256 }; \
+ { KSZ_ANY | KSZ_16BIT, PRE##_HASHSZ/256, PRE##_HASHSZ%256 }; \
const octet pre##_sslmackeysz[] = \
- { KSZ_ANY | KSZ_16BIT, PRE##_STATESZ/256, PRE##_STATESZ%256 }; \
+ { KSZ_ANY | KSZ_16BIT, PRE##_HASHSZ/256, PRE##_HASHSZ%256 }; \
const octet pre##_nmackeysz[] = \
- { KSZ_SET | KSZ_16BIT, \
- 2*PRE##_STATESZ/256, 2*PRE##_STATESZ%256, 0, 0 }; \
+ { KSZ_SET | KSZ_16BIT, 2*PRE##_HASHSZ/256, 2*PRE##_HASHSZ%256, 0, 0 }; \
\
/* --- @pre_nmacinit@ --- * \
* \
int i; \
const octet *kbuf = k; \
pre##_ctx ctx; \
- octet buf[PRE##_HASHSZ]; \
+ octet hbuf[PRE##_HASHSZ], buf[PRE##_BUFSZ]; \
\
if (sz > PRE##_BUFSZ) { \
pre##_init(&ctx); \
pre##_hash(&ctx, k, sz); \
- pre##_done(&ctx, buf); \
- kbuf = buf; \
+ pre##_done(&ctx, hbuf); \
+ kbuf = hbuf; \
sz = PRE##_HASHSZ; \
} \
\
pre##_init(&ctx); \
- memset(ctx.buf, 0x5c, PRE##_BUFSZ); \
- for (i = 0; i < sz; i++) \
- ctx.buf[i] ^= kbuf[i]; \
- pre##_compress(&ctx, ctx.buf); \
- pre##_state(&ctx, key->ochain); \
+ memset(buf, 0x5c, PRE##_BUFSZ); \
+ for (i = 0; i < sz; i++) buf[i] ^= kbuf[i]; \
+ pre##_hash(&ctx, buf, PRE##_BUFSZ); \
+ key->ocount = pre##_state(&ctx, key->ochain); \
\
pre##_init(&ctx); \
- memset(ctx.buf, 0x36, PRE##_BUFSZ); \
- for (i = 0; i < sz; i++) \
- ctx.buf[i] ^= kbuf[i]; \
- pre##_compress(&ctx, ctx.buf); \
- pre##_state(&ctx, key->ichain); \
+ memset(buf, 0x36, PRE##_BUFSZ); \
+ for (i = 0; i < sz; i++) buf[i] ^= kbuf[i]; \
+ pre##_hash(&ctx, buf, PRE##_BUFSZ); \
+ key->icount = pre##_state(&ctx, key->ichain); \
\
- key->ocount = key->icount = PRE##_BUFSZ; \
BURN(ctx); \
} \
\
{ \
const octet *kbuf = k; \
pre##_ctx ctx; \
- octet buf[PRE##_HASHSZ]; \
+ octet hbuf[PRE##_HASHSZ], buf[PRE##_BUFSZ]; \
\
if (sz > PRE##_BUFSZ) { \
pre##_init(&ctx); \
pre##_hash(&ctx, k, sz); \
- pre##_done(&ctx, buf); \
- kbuf = buf; \
+ pre##_done(&ctx, hbuf); \
+ kbuf = hbuf; \
sz = PRE##_HASHSZ; \
} \
\
pre##_init(&ctx); \
- memcpy(ctx.buf, kbuf, sz); \
- memset(ctx.buf + sz, 0x5c, PRE##_BUFSZ - sz); \
- pre##_compress(&ctx, ctx.buf); \
- pre##_state(&ctx, key->ochain); \
+ memcpy(buf, kbuf, sz); \
+ memset(buf + sz, 0x5c, PRE##_BUFSZ - sz); \
+ pre##_hash(&ctx, buf, PRE##_BUFSZ); \
+ key->ocount = pre##_state(&ctx, key->ochain); \
\
pre##_init(&ctx); \
- memcpy(ctx.buf, kbuf, sz); \
- memset(ctx.buf + sz, 0x36, PRE##_BUFSZ - sz); \
- pre##_compress(&ctx, ctx.buf); \
- pre##_state(&ctx, key->ichain); \
+ memcpy(buf, kbuf, sz); \
+ memset(buf + sz, 0x36, PRE##_BUFSZ - sz); \
+ pre##_hash(&ctx, buf, PRE##_BUFSZ); \
+ key->icount = pre##_state(&ctx, key->ichain); \
\
- key->ocount = key->icount = PRE##_BUFSZ; \
BURN(ctx); \
} \
\
*/ \
\
void pre##_machash(pre##_macctx *ctx, const void *buf, size_t sz) \
-{ \
- pre##_hash(&ctx->ctx, buf, sz); \
-} \
+ { pre##_hash(&ctx->ctx, buf, sz); } \
\
/* --- @pre_macdone@ --- * \
* \
\
/* --- Generic MAC interface --- */ \
\
-static const gmac_ops gkops; \
+static const gmac_ops gkops, gnkops, gsslkops; \
static const ghash_ops gops, gnops, gsslops; \
\
typedef struct gkctx { \
gkctx *gk = S_CREATE(gkctx); \
const octet *kk = k; \
assert(keysz(sz, pre##_nmackeysz) == sz); \
- gk->m.ops = &gkops; \
+ gk->m.ops = &gnkops; \
gk->gops = &gnops; \
pre##_nmacinit(&gk->k, kk, kk + PRE##_STATESZ); \
return (&gk->m); \
static gmac *gsslkey(const void *k, size_t sz) \
{ \
gkctx *gk = S_CREATE(gkctx); \
- gk->m.ops = &gkops; \
+ gk->m.ops = &gsslkops; \
gk->gops = &gsslops; \
pre##_sslmacinit(&gk->k, k, sz); \
return (&gk->m); \
{ &gch, ghhash, ghdone, ghdestroy, ghcopy }; \
static const gchash gnch = { name "-nmac", PRE##_HASHSZ, ghinit }; \
static const ghash_ops gnops = \
- { &gch, ghhash, ghdone, ghdestroy, ghcopy }; \
+ { &gnch, ghhash, ghdone, ghdestroy, ghcopy }; \
static const gchash gsslch = { name "-sslmac", PRE##_HASHSZ, ghinit }; \
static const ghash_ops gsslops = \
- { &gch, ghhash, ghdone, ghdestroy, ghcopy }; \
+ { &gsslch, ghhash, ghdone, ghdestroy, ghcopy }; \
\
HMAC_TESTX(PRE, pre, name, fname)
#include <stdio.h>
+#include <mLib/macros.h>
#include <mLib/dstr.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
csz -= i; \
} \
pre##_macdone(&cctx, d.buf); \
- if (memcmp(d.buf, v[2].buf, PRE##_HASHSZ) != 0) { \
+ if (MEMCMP(d.buf, !=, v[2].buf, PRE##_HASHSZ)) { \
printf("\nfail:\n\tstep = %i\n\tinput = `%s'\n\tkey = ", \
*ip, v[0].buf); \
type_hex.dump(&v[1], stdout); \