progs/perftest.c: Use from Glibc syscall numbers.
[catacomb] / symm / ghash-def.h
CommitLineData
a4738812 1/* -*-c-*-
2 *
a4738812 3 * Definitions for generic hash interface
4 *
5 * (c) 1999 Straylight/Edgeware
6 */
7
45c0fd36 8/*----- Licensing notice --------------------------------------------------*
a4738812 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.
45c0fd36 16 *
a4738812 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.
45c0fd36 21 *
a4738812 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
a4738812 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
28ef1f45 40#ifndef CATACOMB_ARENA_H
41# include "arena.h"
42#endif
43
a4738812 44#ifndef CATACOMB_GHASH_H
45# include "ghash.h"
46#endif
47
f80463ac 48#ifndef CATACOMB_PARANOIA_H
49# include "paranoia.h"
50#endif
51
a4738812 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
aaae9cab
MW
61#define GHASH_DEF(PRE, pre) GHASH_DEFX(PRE, pre, #pre)
62#define GHASH_DEFX(PRE, pre, name) \
a4738812 63 \
aaae9cab 64static const ghash_ops gops_##pre; \
a4738812 65 \
aaae9cab 66typedef struct gctx_##pre { \
a4738812 67 ghash h; \
68 pre##_ctx c; \
a351d052 69 octet buf[PRE##_HASHSZ]; \
aaae9cab 70} gctx_##pre; \
a4738812 71 \
aaae9cab 72static ghash *ghinit_##pre(void) \
a4738812 73{ \
aaae9cab
MW
74 gctx_##pre *g = S_CREATE(gctx_##pre); \
75 g->h.ops = &gops_##pre; \
a4738812 76 pre##_init(&g->c); \
77 return (&g->h); \
78} \
79 \
aaae9cab 80static void ghhash_##pre(ghash *h, const void *p, size_t sz) \
a4738812 81{ \
aaae9cab 82 gctx_##pre *g = (gctx_##pre *)h; \
a4738812 83 pre##_hash(&g->c, p, sz); \
84} \
85 \
aaae9cab 86static octet *ghdone_##pre(ghash *h, void *buf) \
a4738812 87{ \
aaae9cab 88 gctx_##pre *g = (gctx_##pre *)h; \
a351d052 89 if (!buf) \
90 buf = g->buf; \
a4738812 91 pre##_done(&g->c, buf); \
a351d052 92 return (buf); \
a4738812 93} \
94 \
aaae9cab 95static void ghdestroy_##pre(ghash *h) \
a4738812 96{ \
aaae9cab 97 gctx_##pre *g = (gctx_##pre *)h; \
f80463ac 98 BURN(*g); \
28ef1f45 99 S_DESTROY(g); \
a4738812 100} \
101 \
aaae9cab 102static ghash *ghcopy_##pre(ghash *h) \
d2fdbc2c 103{ \
aaae9cab
MW
104 gctx_##pre *g = (gctx_##pre *)h; \
105 gctx_##pre *gg = S_CREATE(gctx_##pre); \
106 memcpy(gg, g, sizeof(gctx_##pre)); \
d2fdbc2c 107 return (&gg->h); \
108} \
109 \
aaae9cab
MW
110static const ghash_ops gops_##pre = \
111 { &pre, ghhash_##pre, ghdone_##pre, ghdestroy_##pre, ghcopy_##pre }; \
112const gchash pre = { name, PRE##_HASHSZ, ghinit_##pre, PRE##_BUFSZ };
a4738812 113
114/*----- That's all, folks -------------------------------------------------*/
115
116#ifdef __cplusplus
117 }
118#endif
119
120#endif