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