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) \
63 static const ghash_ops gops; \
65 typedef struct gctx { \
68 octet buf[PRE##_HASHSZ]; \
71 static ghash *ghinit(void) \
73 gctx *g = S_CREATE(gctx); \
79 static void ghhash(ghash *h, const void *p, size_t sz) \
81 gctx *g = (gctx *)h; \
82 pre##_hash(&g->c, p, sz); \
85 static octet *ghdone(ghash *h, void *buf) \
87 gctx *g = (gctx *)h; \
90 pre##_done(&g->c, buf); \
94 static void ghdestroy(ghash *h) \
96 gctx *g = (gctx *)h; \
101 static ghash *ghcopy(ghash *h) \
103 gctx *g = (gctx *)h; \
104 gctx *gg = S_CREATE(gctx); \
105 memcpy(gg, g, sizeof(gctx)); \
109 static const ghash_ops gops = \
110 { &pre, ghhash, ghdone, ghdestroy, ghcopy }; \
111 const gchash pre = { #pre, PRE##_HASHSZ, ghinit, PRE##_BUFSZ };
113 /*----- That's all, folks -------------------------------------------------*/