a4738812 |
1 | /* -*-c-*- |
2 | * |
28ef1f45 |
3 | * $Id: ghash-def.h,v 1.2 2000/06/17 11:22:03 mdw Exp $ |
a4738812 |
4 | * |
5 | * Definitions for generic hash interface |
6 | * |
7 | * (c) 1999 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
14 | * Catacomb is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
18 | * |
19 | * Catacomb is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU Library General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with Catacomb; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: ghash-def.h,v $ |
28ef1f45 |
33 | * Revision 1.2 2000/06/17 11:22:03 mdw |
34 | * Use secure arena for memory allocation. Minor changes in the generic |
35 | * hash interface. |
36 | * |
a4738812 |
37 | * Revision 1.1 1999/12/10 23:21:37 mdw |
38 | * Generic interface. |
39 | * |
40 | */ |
41 | |
42 | #ifndef CATACOMB_GHASH_DEF_H |
43 | #define CATACOMB_GHASH_DEF_H |
44 | |
45 | #ifdef __cplusplus |
46 | extern "C" { |
47 | #endif |
48 | |
49 | /*----- Header files ------------------------------------------------------*/ |
50 | |
51 | #include <mLib/bits.h> |
52 | #include <mLib/sub.h> |
53 | |
28ef1f45 |
54 | #ifndef CATACOMB_ARENA_H |
55 | # include "arena.h" |
56 | #endif |
57 | |
a4738812 |
58 | #ifndef CATACOMB_GHASH_H |
59 | # include "ghash.h" |
60 | #endif |
61 | |
62 | /*----- Generic hash function interface -----------------------------------*/ |
63 | |
64 | /* --- @GHASH_DEF@ --- * |
65 | * |
66 | * Arguments: @PRE, pre@ = prefixes for hash function |
67 | * |
68 | * Use: Defines the generic hash instance. |
69 | */ |
70 | |
71 | #define GHASH_DEF(PRE, pre) \ |
72 | \ |
73 | static const ghash_ops gops; \ |
74 | \ |
75 | typedef struct gctx { \ |
76 | ghash h; \ |
77 | pre##_ctx c; \ |
78 | } gctx; \ |
79 | \ |
80 | static ghash *ghinit(void) \ |
81 | { \ |
28ef1f45 |
82 | gctx *g = S_CREATE(gctx); \ |
a4738812 |
83 | g->h.ops = &gops; \ |
84 | pre##_init(&g->c); \ |
85 | return (&g->h); \ |
86 | } \ |
87 | \ |
88 | static void ghhash(ghash *h, const void *p, size_t sz) \ |
89 | { \ |
90 | gctx *g = (gctx *)h; \ |
91 | pre##_hash(&g->c, p, sz); \ |
92 | } \ |
93 | \ |
94 | static void ghdone(ghash *h, void *buf) \ |
95 | { \ |
96 | gctx *g = (gctx *)h; \ |
97 | pre##_done(&g->c, buf); \ |
98 | } \ |
99 | \ |
100 | static void ghdestroy(ghash *h) \ |
101 | { \ |
102 | gctx *g = (gctx *)h; \ |
28ef1f45 |
103 | S_DESTROY(g); \ |
a4738812 |
104 | } \ |
105 | \ |
28ef1f45 |
106 | static const ghash_ops gops = { &pre, ghhash, ghdone, ghdestroy }; \ |
107 | const gchash pre = { #pre, PRE##_HASHSZ, ghinit }; |
a4738812 |
108 | |
109 | /*----- That's all, folks -------------------------------------------------*/ |
110 | |
111 | #ifdef __cplusplus |
112 | } |
113 | #endif |
114 | |
115 | #endif |