static void gdestroy(gcipher *c)
{ gctx *g = (gctx *)c; BURN(*g); S_DESTROY(g); }
+static gcipher *ginit(const void *k, size_t sz, const gcipher_ops *ops)
+{
+ gctx *g = S_CREATE(gctx);
+ g->c.ops = ops;
+ chacha_init(&g->ctx, k, sz, 0);
+ return (&g->c);
+}
+
#define DEFGCIPHER(r) \
\
static const gcipher_ops gops_##r; \
\
static gcipher *ginit_##r(const void *k, size_t sz) \
- { \
- gctx *g = S_CREATE(gctx); \
- g->c.ops = &gops_##r; \
- chacha_init(&g->ctx, k, sz, 0); \
- return (&g->c); \
- } \
+ { return (ginit(k, sz, &gops_##r)); } \
\
static void gencrypt_##r(gcipher *c, const void *s, \
void *t, size_t sz) \
static void grdestroy(grand *r)
{ grctx *g = (grctx *)r; BURN(*g); S_DESTROY(g); }
+static grand *grinit(const void *k, size_t ksz, const void *n,
+ const grand_ops *ops, const grops *myops)
+{
+ grctx *g = S_CREATE(grctx);
+ g->r.r.ops = ops;
+ g->r.ops = myops;
+ chacha_init(&g->ctx, k, ksz, 0);
+ myops->setnonce(g, n);
+ return (&g->r.r);
+}
+
#define DEFGRAND(rr) \
\
static void gr_generate_##rr(void *r, void *b, size_t sz) \
}; \
\
grand *chacha##rr##_rand(const void *k, size_t ksz, const void *n) \
- { \
- grctx *g = S_CREATE(grctx); \
- g->r.r.ops = &grops_rand_##rr; \
- g->r.ops = &grops_##rr; \
- chacha_init(&g->ctx, k, ksz, n); \
- return (&g->r.r); \
- }
+ { return (grinit(k, ksz, n, &grops_rand_##rr, &grops_##rr)); }
CHACHA_VARS(DEFGRAND)
#define DEFXGRAND(rr) \
static void gdestroy(gcipher *c)
{ gctx *g = (gctx *)c; BURN(*g); S_DESTROY(g); }
+static gcipher *ginit(const void *k, size_t sz, const gcipher_ops *ops)
+{
+ gctx *g = S_CREATE(gctx);
+ g->c.ops = ops;
+ salsa20_init(&g->ctx, k, sz, 0);
+ return (&g->c);
+}
+
#define DEFGCIPHER(r) \
\
static const gcipher_ops gops_##r; \
\
static gcipher *ginit_##r(const void *k, size_t sz) \
- { \
- gctx *g = S_CREATE(gctx); \
- g->c.ops = &gops_##r; \
- salsa20_init(&g->ctx, k, sz, 0); \
- return (&g->c); \
- } \
+ { return (ginit(k, sz, &gops_##r)); } \
\
static void gencrypt_##r(gcipher *c, const void *s, \
void *t, size_t sz) \
static void grdestroy(grand *r)
{ grctx *g = (grctx *)r; BURN(*g); S_DESTROY(g); }
+static grand *grinit(const void *k, size_t ksz, const void *n,
+ const grand_ops *ops, const grops *myops)
+{
+ grctx *g = S_CREATE(grctx);
+ g->r.r.ops = ops;
+ g->r.ops = myops;
+ salsa20_init(&g->ctx, k, ksz, 0);
+ myops->setnonce(g, n);
+ return (&g->r.r);
+}
+
#define DEFGRAND(rr) \
\
static void gr_generate_##rr(void *r, void *b, size_t sz) \
\
grand *SALSA20_DECOR(salsa20, rr, _rand) \
(const void *k, size_t ksz, const void *n) \
- { \
- grctx *g = S_CREATE(grctx); \
- g->r.r.ops = &grops_rand_##rr; \
- g->r.ops = &grops_##rr; \
- salsa20_init(&g->ctx, k, ksz, n); \
- return (&g->r.r); \
- }
+ { return (grinit(k, ksz, n, &grops_rand_##rr, &grops_##rr)); }
SALSA20_VARS(DEFGRAND)
#define DEFXGRAND(rr) \