Use the shiny new `mLib' warning-control macros.
[u/mdw/catacomb] / symm / rmd256.h
CommitLineData
1c64c8e2 1/* -*-c-*-
2 *
1c64c8e2 3 * The RIPEMD-256 message digest function
4 *
5 * (c) 1998 Straylight/Edgeware
6 */
7
45c0fd36 8/*----- Licensing notice --------------------------------------------------*
1c64c8e2 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 *
1c64c8e2 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 *
1c64c8e2 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
1c64c8e2 28/*----- Notes on the RIPEMD-256 hash function -----------------------------*
29 *
30 * RIPEMD-256 was invented by Hans Dobbertin, Antoon Bosselaers and Bart
31 * Preneel. It's a double-width version of RIPEMD-128, constructed simply by
32 * not gluing together the two parallel computations which RIPEMD-128 usually
33 * does in its compression function. The authors warn that, while its output
34 * is twice as wide as that of RIPEMD-128, they don't expect it to offer any
35 * more security.
36 */
37
38#ifndef CATACOMB_RMD256_H
39#define CATACOMB_RMD256_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 RMD256_BUFSZ 64
56#define RMD256_HASHSZ 32
c850c0da 57#define RMD256_STATESZ 32
1c64c8e2 58
59/*----- Data structures ---------------------------------------------------*/
60
61typedef struct rmd256_ctx {
62 uint32 a, b, c, d; /* Chaining variables */
63 uint32 A, B, C, D; /* More chaining variables */
64 uint32 nl, nh; /* Byte count so far */
65 unsigned off; /* Offset into buffer */
66 octet buf[RMD256_BUFSZ]; /* Accumulation buffer */
67} rmd256_ctx;
68
69/*----- Functions provided ------------------------------------------------*/
70
71/* --- @rmd256_compress@ --- *
72 *
73 * Arguments: @rmd256_ctx *ctx@ = pointer to context block
74 * @const void *sbuf@ = pointer to buffer of appropriate size
75 *
76 * Returns: ---
77 *
78 * Use: RIPEMD-256 compression function.
79 */
80
81extern void rmd256_compress(rmd256_ctx */*ctx*/, const void */*sbuf*/);
82
83/* --- @rmd256_init@ --- *
84 *
85 * Arguments: @rmd256_ctx *ctx@ = pointer to context block to initialize
86 *
87 * Returns: ---
88 *
89 * Use: Initializes a context block ready for hashing.
90 */
91
92extern void rmd256_init(rmd256_ctx */*ctx*/);
93
94/* --- @rmd256_set@ --- *
95 *
96 * Arguments: @rmd256_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
107extern void rmd256_set(rmd256_ctx */*ctx*/,
108 const void */*buf*/, unsigned long /*count*/);
109
110/* --- @rmd256_hash@ --- *
111 *
112 * Arguments: @rmd256_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
122extern void rmd256_hash(rmd256_ctx */*ctx*/,
123 const void */*buf*/, size_t /*sz*/);
124
125/* --- @rmd256_done@ --- *
126 *
127 * Arguments: @rmd256_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
135extern void rmd256_done(rmd256_ctx */*ctx*/, void */*hash*/);
136
137/* --- @rmd256_state@ --- *
138 *
139 * Arguments: @rmd256_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 @rmd256_set@.
146 */
147
148extern unsigned long rmd256_state(rmd256_ctx */*ctx*/, void */*state*/);
149
150/*----- Generic hash interface --------------------------------------------*/
151
152extern const gchash rmd256;
153
154/*----- That's all, folks -------------------------------------------------*/
155
156#ifdef __cplusplus
157 }
158#endif
159
160#endif