Rearrange the file tree.
[u/mdw/catacomb] / symm / rmd320.h
1 /* -*-c-*-
2 *
3 * The RIPEMD-320 message digest function
4 *
5 * (c) 1998 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
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.
16 *
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.
21 *
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
28 /*----- Notes on the RIPEMD-320 hash function -----------------------------*
29 *
30 * RIPEMD-320 was invented by Hans Dobbertin, Antoon Bosselaers and Bart
31 * Preneel. It's a double-width version of RIPEMD-160, constructed simply by
32 * not gluing together the two parallel computations which RIPEMD-160 usually
33 * does in its compression function. The authors warn that, while its output
34 * is twice as wide as that of RIPEMD-160, they don't expect it to offer any
35 * more security.
36 */
37
38 #ifndef CATACOMB_RMD320_H
39 #define CATACOMB_RMD320_H
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /*----- Header files ------------------------------------------------------*/
46
47 #include <mLib/bits.h>
48
49 #ifndef CATACOMB_GHASH_H
50 # include "ghash.h"
51 #endif
52
53 /*----- Magic numbers -----------------------------------------------------*/
54
55 #define RMD320_BUFSZ 64
56 #define RMD320_HASHSZ 40
57 #define RMD320_STATESZ 40
58
59 /*----- Data structures ---------------------------------------------------*/
60
61 typedef struct rmd320_ctx {
62 uint32 a, b, c, d, e; /* Chaining variables */
63 uint32 A, B, C, D, E; /* More chaining variables */
64 uint32 nl, nh; /* Byte count so far */
65 unsigned off; /* Offset into buffer */
66 octet buf[RMD320_BUFSZ]; /* Accumulation buffer */
67 } rmd320_ctx;
68
69 /*----- Functions provided ------------------------------------------------*/
70
71 /* --- @rmd320_compress@ --- *
72 *
73 * Arguments: @rmd320_ctx *ctx@ = pointer to context block
74 * @const void *sbuf@ = pointer to buffer of appropriate size
75 *
76 * Returns: ---
77 *
78 * Use: RIPEMD-320 compression function.
79 */
80
81 extern void rmd320_compress(rmd320_ctx */*ctx*/, const void */*sbuf*/);
82
83 /* --- @rmd320_init@ --- *
84 *
85 * Arguments: @rmd320_ctx *ctx@ = pointer to context block to initialize
86 *
87 * Returns: ---
88 *
89 * Use: Initializes a context block ready for hashing.
90 */
91
92 extern void rmd320_init(rmd320_ctx */*ctx*/);
93
94 /* --- @rmd320_set@ --- *
95 *
96 * Arguments: @rmd320_ctx *ctx@ = pointer to context block
97 * @const void *buf@ = pointer to state buffer
98 * @unsigned long count@ = current count of bytes processed
99 *
100 * Returns: ---
101 *
102 * Use: Initializes a context block from a given state. This is
103 * useful in cases where the initial hash state is meant to be
104 * secret, e.g., for NMAC and HMAC support.
105 */
106
107 extern void rmd320_set(rmd320_ctx */*ctx*/,
108 const void */*buf*/, unsigned long /*count*/);
109
110 /* --- @rmd320_hash@ --- *
111 *
112 * Arguments: @rmd320_ctx *ctx@ = pointer to context block
113 * @const void *buf@ = buffer of data to hash
114 * @size_t sz@ = size of buffer to hash
115 *
116 * Returns: ---
117 *
118 * Use: Hashes a buffer of data. The buffer may be of any size and
119 * alignment.
120 */
121
122 extern void rmd320_hash(rmd320_ctx */*ctx*/,
123 const void */*buf*/, size_t /*sz*/);
124
125 /* --- @rmd320_done@ --- *
126 *
127 * Arguments: @rmd320_ctx *ctx@ = pointer to context block
128 * @void *hash@ = pointer to output buffer
129 *
130 * Returns: ---
131 *
132 * Use: Returns the hash of the data read so far.
133 */
134
135 extern void rmd320_done(rmd320_ctx */*ctx*/, void */*hash*/);
136
137 /* --- @rmd320_state@ --- *
138 *
139 * Arguments: @rmd320_ctx *ctx@ = pointer to context
140 * @void *state@ = pointer to buffer for current state
141 *
142 * Returns: Number of bytes written to the hash function so far.
143 *
144 * Use: Returns the current state of the hash function such that
145 * it can be passed to @rmd320_set@.
146 */
147
148 extern unsigned long rmd320_state(rmd320_ctx */*ctx*/, void */*state*/);
149
150 /*----- Generic hash interface --------------------------------------------*/
151
152 extern const gchash rmd320;
153
154 /*----- That's all, folks -------------------------------------------------*/
155
156 #ifdef __cplusplus
157 }
158 #endif
159
160 #endif