3 * Definitions for generic hash interface
5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 #ifndef CATACOMB_GHASH_DEF_H
29 #define CATACOMB_GHASH_DEF_H
35 /*----- Header files ------------------------------------------------------*/
37 #include <mLib/bits.h>
40 #ifndef CATACOMB_ARENA_H
44 #ifndef CATACOMB_GHASH_H
48 #ifndef CATACOMB_PARANOIA_H
49 # include "paranoia.h"
52 /*----- Generic hash function interface -----------------------------------*/
54 /* --- @GHASH_DEF@ --- *
56 * Arguments: @PRE, pre@ = prefixes for hash function
58 * Use: Defines the generic hash instance.
61 #define GHASH_DEF(PRE, pre) GHASH_DEFX(PRE, pre, #pre)
62 #define GHASH_DEFX(PRE, pre, name) \
64 static const ghash_ops gops_##pre; \
66 typedef struct gctx_##pre { \
69 octet buf[PRE##_HASHSZ]; \
72 static ghash *ghinit_##pre(void) \
74 gctx_##pre *g = S_CREATE(gctx_##pre); \
75 g->h.ops = &gops_##pre; \
80 static void ghhash_##pre(ghash *h, const void *p, size_t sz) \
82 gctx_##pre *g = (gctx_##pre *)h; \
83 pre##_hash(&g->c, p, sz); \
86 static octet *ghdone_##pre(ghash *h, void *buf) \
88 gctx_##pre *g = (gctx_##pre *)h; \
91 pre##_done(&g->c, buf); \
95 static void ghdestroy_##pre(ghash *h) \
97 gctx_##pre *g = (gctx_##pre *)h; \
102 static ghash *ghcopy_##pre(ghash *h) \
104 gctx_##pre *g = (gctx_##pre *)h; \
105 gctx_##pre *gg = S_CREATE(gctx_##pre); \
106 memcpy(gg, g, sizeof(gctx_##pre)); \
110 static const ghash_ops gops_##pre = \
111 { &pre, ghhash_##pre, ghdone_##pre, ghdestroy_##pre, ghcopy_##pre }; \
112 const gchash pre = { name, PRE##_HASHSZ, ghinit_##pre, PRE##_BUFSZ };
114 /*----- That's all, folks -------------------------------------------------*/