math/mpreduce.h: Missing include files.
[u/mdw/catacomb] / symm / ghash-def.h
1 /* -*-c-*-
2 *
3 * Definitions for generic hash interface
4 *
5 * (c) 1999 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of Catacomb.
11 *
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.
16 *
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.
21 *
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,
25 * MA 02111-1307, USA.
26 */
27
28 #ifndef CATACOMB_GHASH_DEF_H
29 #define CATACOMB_GHASH_DEF_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #include <mLib/bits.h>
38 #include <mLib/sub.h>
39
40 #ifndef CATACOMB_ARENA_H
41 # include "arena.h"
42 #endif
43
44 #ifndef CATACOMB_GHASH_H
45 # include "ghash.h"
46 #endif
47
48 #ifndef CATACOMB_PARANOIA_H
49 # include "paranoia.h"
50 #endif
51
52 /*----- Generic hash function interface -----------------------------------*/
53
54 /* --- @GHASH_DEF@ --- *
55 *
56 * Arguments: @PRE, pre@ = prefixes for hash function
57 *
58 * Use: Defines the generic hash instance.
59 */
60
61 #define GHASH_DEF(PRE, pre) \
62 \
63 static const ghash_ops gops; \
64 \
65 typedef struct gctx { \
66 ghash h; \
67 pre##_ctx c; \
68 octet buf[PRE##_HASHSZ]; \
69 } gctx; \
70 \
71 static ghash *ghinit(void) \
72 { \
73 gctx *g = S_CREATE(gctx); \
74 g->h.ops = &gops; \
75 pre##_init(&g->c); \
76 return (&g->h); \
77 } \
78 \
79 static void ghhash(ghash *h, const void *p, size_t sz) \
80 { \
81 gctx *g = (gctx *)h; \
82 pre##_hash(&g->c, p, sz); \
83 } \
84 \
85 static octet *ghdone(ghash *h, void *buf) \
86 { \
87 gctx *g = (gctx *)h; \
88 if (!buf) \
89 buf = g->buf; \
90 pre##_done(&g->c, buf); \
91 return (buf); \
92 } \
93 \
94 static void ghdestroy(ghash *h) \
95 { \
96 gctx *g = (gctx *)h; \
97 BURN(*g); \
98 S_DESTROY(g); \
99 } \
100 \
101 static ghash *ghcopy(ghash *h) \
102 { \
103 gctx *g = (gctx *)h; \
104 gctx *gg = S_CREATE(gctx); \
105 memcpy(gg, g, sizeof(gctx)); \
106 return (&gg->h); \
107 } \
108 \
109 static const ghash_ops gops = \
110 { &pre, ghhash, ghdone, ghdestroy, ghcopy }; \
111 const gchash pre = { #pre, PRE##_HASHSZ, ghinit, PRE##_BUFSZ };
112
113 /*----- That's all, folks -------------------------------------------------*/
114
115 #ifdef __cplusplus
116 }
117 #endif
118
119 #endif