Pollard's rho algorithm for computing discrete logs.
[u/mdw/catacomb] / rmd128.h
1 /* -*-c-*-
2 *
3 * $Id: rmd128.h,v 1.1 2000/07/09 21:30:31 mdw Exp $
4 *
5 * The RIPEMD-128 message digest function
6 *
7 * (c) 1998 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: rmd128.h,v $
33 * Revision 1.1 2000/07/09 21:30:31 mdw
34 * New RIPEMD variants.
35 *
36 */
37
38 /*----- Notes on the RIPEMD-128 hash function -----------------------------*
39 *
40 * RIPEMD-128 was invented by Hans Dobbertin, Antoon Bosselaers and Bart
41 * Preneel, as a drop-in replacement for MD5 (with the same sized output).
42 * It's a cut-down version of RIPEMD-160, which should be used in preference.
43 */
44
45 #ifndef CATACOMB_RMD128_H
46 #define CATACOMB_RMD128_H
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 /*----- Header files ------------------------------------------------------*/
53
54 #include <mLib/bits.h>
55
56 #ifndef CATACOMB_GHASH_H
57 # include "ghash.h"
58 #endif
59
60 /*----- Magic numbers -----------------------------------------------------*/
61
62 #define RMD128_BUFSZ 64
63 #define RMD128_HASHSZ 16
64
65 /*----- Data structures ---------------------------------------------------*/
66
67 typedef struct rmd128_ctx {
68 uint32 a, b, c, d; /* Chaining variables */
69 uint32 nl, nh; /* Byte count so far */
70 unsigned off; /* Offset into buffer */
71 octet buf[RMD128_BUFSZ]; /* Accumulation buffer */
72 } rmd128_ctx;
73
74 /*----- Functions provided ------------------------------------------------*/
75
76 /* --- @rmd128_compress@ --- *
77 *
78 * Arguments: @rmd128_ctx *ctx@ = pointer to context block
79 * @const void *sbuf@ = pointer to buffer of appropriate size
80 *
81 * Returns: ---
82 *
83 * Use: RIPEMD-128 compression function.
84 */
85
86 extern void rmd128_compress(rmd128_ctx */*ctx*/, const void */*sbuf*/);
87
88 /* --- @rmd128_init@ --- *
89 *
90 * Arguments: @rmd128_ctx *ctx@ = pointer to context block to initialize
91 *
92 * Returns: ---
93 *
94 * Use: Initializes a context block ready for hashing.
95 */
96
97 extern void rmd128_init(rmd128_ctx */*ctx*/);
98
99 /* --- @rmd128_set@ --- *
100 *
101 * Arguments: @rmd128_ctx *ctx@ = pointer to context block
102 * @const void *buf@ = pointer to state buffer
103 * @unsigned long count@ = current count of bytes processed
104 *
105 * Returns: ---
106 *
107 * Use: Initializes a context block from a given state. This is
108 * useful in cases where the initial hash state is meant to be
109 * secret, e.g., for NMAC and HMAC support.
110 */
111
112 extern void rmd128_set(rmd128_ctx */*ctx*/,
113 const void */*buf*/, unsigned long /*count*/);
114
115 /* --- @rmd128_hash@ --- *
116 *
117 * Arguments: @rmd128_ctx *ctx@ = pointer to context block
118 * @const void *buf@ = buffer of data to hash
119 * @size_t sz@ = size of buffer to hash
120 *
121 * Returns: ---
122 *
123 * Use: Hashes a buffer of data. The buffer may be of any size and
124 * alignment.
125 */
126
127 extern void rmd128_hash(rmd128_ctx */*ctx*/,
128 const void */*buf*/, size_t /*sz*/);
129
130 /* --- @rmd128_done@ --- *
131 *
132 * Arguments: @rmd128_ctx *ctx@ = pointer to context block
133 * @void *hash@ = pointer to output buffer
134 *
135 * Returns: ---
136 *
137 * Use: Returns the hash of the data read so far.
138 */
139
140 extern void rmd128_done(rmd128_ctx */*ctx*/, void */*hash*/);
141
142 /* --- @rmd128_state@ --- *
143 *
144 * Arguments: @rmd128_ctx *ctx@ = pointer to context
145 * @void *state@ = pointer to buffer for current state
146 *
147 * Returns: Number of bytes written to the hash function so far.
148 *
149 * Use: Returns the current state of the hash function such that
150 * it can be passed to @rmd128_set@.
151 */
152
153 extern unsigned long rmd128_state(rmd128_ctx */*ctx*/, void */*state*/);
154
155 /*----- Generic hash interface --------------------------------------------*/
156
157 extern const gchash rmd128;
158
159 /*----- That's all, folks -------------------------------------------------*/
160
161 #ifdef __cplusplus
162 }
163 #endif
164
165 #endif