a4738812 |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: ghash-def.h,v 1.1 1999/12/10 23:21:37 mdw Exp $ |
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 $ |
33 | * Revision 1.1 1999/12/10 23:21:37 mdw |
34 | * Generic interface. |
35 | * |
36 | */ |
37 | |
38 | #ifndef CATACOMB_GHASH_DEF_H |
39 | #define CATACOMB_GHASH_DEF_H |
40 | |
41 | #ifdef __cplusplus |
42 | extern "C" { |
43 | #endif |
44 | |
45 | /*----- Header files ------------------------------------------------------*/ |
46 | |
47 | #include <mLib/bits.h> |
48 | #include <mLib/sub.h> |
49 | |
50 | #ifndef CATACOMB_GHASH_H |
51 | # include "ghash.h" |
52 | #endif |
53 | |
54 | /*----- Generic hash function interface -----------------------------------*/ |
55 | |
56 | /* --- @GHASH_DEF@ --- * |
57 | * |
58 | * Arguments: @PRE, pre@ = prefixes for hash function |
59 | * |
60 | * Use: Defines the generic hash instance. |
61 | */ |
62 | |
63 | #define GHASH_DEF(PRE, pre) \ |
64 | \ |
65 | static const ghash_ops gops; \ |
66 | \ |
67 | typedef struct gctx { \ |
68 | ghash h; \ |
69 | pre##_ctx c; \ |
70 | } gctx; \ |
71 | \ |
72 | static ghash *ghinit(void) \ |
73 | { \ |
74 | gctx *g = CREATE(gctx); \ |
75 | g->h.ops = &gops; \ |
76 | pre##_init(&g->c); \ |
77 | return (&g->h); \ |
78 | } \ |
79 | \ |
80 | static void ghhash(ghash *h, const void *p, size_t sz) \ |
81 | { \ |
82 | gctx *g = (gctx *)h; \ |
83 | pre##_hash(&g->c, p, sz); \ |
84 | } \ |
85 | \ |
86 | static void ghdone(ghash *h, void *buf) \ |
87 | { \ |
88 | gctx *g = (gctx *)h; \ |
89 | pre##_done(&g->c, buf); \ |
90 | } \ |
91 | \ |
92 | static void ghdestroy(ghash *h) \ |
93 | { \ |
94 | gctx *g = (gctx *)h; \ |
95 | DESTROY(g); \ |
96 | } \ |
97 | \ |
98 | static const ghash_ops gops = { &pre.b, ghhash, ghdone, ghdestroy }; \ |
99 | const gchash pre = { { #pre, PRE##_HASHSZ }, ghinit }; |
100 | |
101 | /*----- That's all, folks -------------------------------------------------*/ |
102 | |
103 | #ifdef __cplusplus |
104 | } |
105 | #endif |
106 | |
107 | #endif |