Pollard's rho algorithm for computing discrete logs.
[u/mdw/catacomb] / ghash-def.h
CommitLineData
a4738812 1/* -*-c-*-
2 *
a351d052 3 * $Id: ghash-def.h,v 1.3 2000/07/02 18:27:42 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 $
a351d052 33 * Revision 1.3 2000/07/02 18:27:42 mdw
34 * (ghash->ops->done): Interface change. Passing in a null buffer pointer
35 * uses a buffer internal to the ghash object. The operation returns the
36 * address of the buffer it used. Clients of generic hashes no longer need
37 * to use dynamically allocated memory for hash results.
38 *
28ef1f45 39 * Revision 1.2 2000/06/17 11:22:03 mdw
40 * Use secure arena for memory allocation. Minor changes in the generic
41 * hash interface.
42 *
a4738812 43 * Revision 1.1 1999/12/10 23:21:37 mdw
44 * Generic interface.
45 *
46 */
47
48#ifndef CATACOMB_GHASH_DEF_H
49#define CATACOMB_GHASH_DEF_H
50
51#ifdef __cplusplus
52 extern "C" {
53#endif
54
55/*----- Header files ------------------------------------------------------*/
56
57#include <mLib/bits.h>
58#include <mLib/sub.h>
59
28ef1f45 60#ifndef CATACOMB_ARENA_H
61# include "arena.h"
62#endif
63
a4738812 64#ifndef CATACOMB_GHASH_H
65# include "ghash.h"
66#endif
67
68/*----- Generic hash function interface -----------------------------------*/
69
70/* --- @GHASH_DEF@ --- *
71 *
72 * Arguments: @PRE, pre@ = prefixes for hash function
73 *
74 * Use: Defines the generic hash instance.
75 */
76
77#define GHASH_DEF(PRE, pre) \
78 \
79static const ghash_ops gops; \
80 \
81typedef struct gctx { \
82 ghash h; \
83 pre##_ctx c; \
a351d052 84 octet buf[PRE##_HASHSZ]; \
a4738812 85} gctx; \
86 \
87static ghash *ghinit(void) \
88{ \
28ef1f45 89 gctx *g = S_CREATE(gctx); \
a4738812 90 g->h.ops = &gops; \
91 pre##_init(&g->c); \
92 return (&g->h); \
93} \
94 \
95static void ghhash(ghash *h, const void *p, size_t sz) \
96{ \
97 gctx *g = (gctx *)h; \
98 pre##_hash(&g->c, p, sz); \
99} \
100 \
a351d052 101static octet *ghdone(ghash *h, void *buf) \
a4738812 102{ \
103 gctx *g = (gctx *)h; \
a351d052 104 if (!buf) \
105 buf = g->buf; \
a4738812 106 pre##_done(&g->c, buf); \
a351d052 107 return (buf); \
a4738812 108} \
109 \
110static void ghdestroy(ghash *h) \
111{ \
112 gctx *g = (gctx *)h; \
28ef1f45 113 S_DESTROY(g); \
a4738812 114} \
115 \
28ef1f45 116static const ghash_ops gops = { &pre, ghhash, ghdone, ghdestroy }; \
117const gchash pre = { #pre, PRE##_HASHSZ, ghinit };
a4738812 118
119/*----- That's all, folks -------------------------------------------------*/
120
121#ifdef __cplusplus
122 }
123#endif
124
125#endif