d03ab969 |
1 | /* -*-c-*- |
d03ab969 |
2 | * |
3 | * The RIPEMD-160 message digest function |
4 | * |
5 | * (c) 1998 Straylight/Edgeware |
6 | */ |
7 | |
45c0fd36 |
8 | /*----- Licensing notice --------------------------------------------------* |
d03ab969 |
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 | * |
d03ab969 |
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 | * |
d03ab969 |
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 | |
d03ab969 |
28 | /*----- Notes on the RIPEMD-160 hash function -----------------------------* |
29 | * |
30 | * RIPEMD-160 was invented by Hans Dobbertin, Antoon Bosselaers and Bart |
31 | * Preneel. It's a strengthened version of the original RIPEMD hash |
32 | * function, fixing a vulnerability discovered by Hans Dobbertin. The |
33 | * RIPEMD-160 design team appears well respected in the cryptographic |
34 | * community. The author finds them more plausible than SHA-1, which is the |
35 | * best alternative hash function. |
36 | */ |
37 | |
dc2f0497 |
38 | #ifndef CATACOMB_RMD160_H |
39 | #define CATACOMB_RMD160_H |
d03ab969 |
40 | |
41 | #ifdef __cplusplus |
42 | extern "C" { |
43 | #endif |
44 | |
45 | /*----- Header files ------------------------------------------------------*/ |
46 | |
47 | #include <mLib/bits.h> |
48 | |
dc2f0497 |
49 | #ifndef CATACOMB_GHASH_H |
50 | # include "ghash.h" |
51 | #endif |
52 | |
d03ab969 |
53 | /*----- Magic numbers -----------------------------------------------------*/ |
54 | |
55 | #define RMD160_BUFSZ 64 |
56 | #define RMD160_HASHSZ 20 |
c850c0da |
57 | #define RMD160_STATESZ 20 |
d03ab969 |
58 | |
59 | /*----- Data structures ---------------------------------------------------*/ |
60 | |
61 | typedef struct rmd160_ctx { |
62 | uint32 a, b, c, d, e; /* Chaining variables */ |
dc2f0497 |
63 | uint32 nl, nh; /* Byte count so far */ |
1a44eacd |
64 | unsigned off; /* Offset into buffer */ |
d03ab969 |
65 | octet buf[RMD160_BUFSZ]; /* Accumulation buffer */ |
66 | } rmd160_ctx; |
67 | |
68 | /*----- Functions provided ------------------------------------------------*/ |
69 | |
70 | /* --- @rmd160_compress@ --- * |
71 | * |
72 | * Arguments: @rmd160_ctx *ctx@ = pointer to context block |
73 | * @const void *sbuf@ = pointer to buffer of appropriate size |
74 | * |
75 | * Returns: --- |
76 | * |
77 | * Use: RIPEMD-160 compression function. |
78 | */ |
79 | |
80 | extern void rmd160_compress(rmd160_ctx */*ctx*/, const void */*sbuf*/); |
81 | |
82 | /* --- @rmd160_init@ --- * |
83 | * |
84 | * Arguments: @rmd160_ctx *ctx@ = pointer to context block to initialize |
85 | * |
86 | * Returns: --- |
87 | * |
88 | * Use: Initializes a context block ready for hashing. |
89 | */ |
90 | |
91 | extern void rmd160_init(rmd160_ctx */*ctx*/); |
92 | |
93 | /* --- @rmd160_set@ --- * |
94 | * |
95 | * Arguments: @rmd160_ctx *ctx@ = pointer to context block |
96 | * @const void *buf@ = pointer to state buffer |
97 | * @unsigned long count@ = current count of bytes processed |
98 | * |
99 | * Returns: --- |
100 | * |
101 | * Use: Initializes a context block from a given state. This is |
102 | * useful in cases where the initial hash state is meant to be |
103 | * secret, e.g., for NMAC and HMAC support. |
104 | */ |
105 | |
106 | extern void rmd160_set(rmd160_ctx */*ctx*/, |
107 | const void */*buf*/, unsigned long /*count*/); |
108 | |
109 | /* --- @rmd160_hash@ --- * |
110 | * |
111 | * Arguments: @rmd160_ctx *ctx@ = pointer to context block |
112 | * @const void *buf@ = buffer of data to hash |
113 | * @size_t sz@ = size of buffer to hash |
114 | * |
115 | * Returns: --- |
116 | * |
117 | * Use: Hashes a buffer of data. The buffer may be of any size and |
118 | * alignment. |
119 | */ |
120 | |
121 | extern void rmd160_hash(rmd160_ctx */*ctx*/, |
122 | const void */*buf*/, size_t /*sz*/); |
123 | |
124 | /* --- @rmd160_done@ --- * |
125 | * |
126 | * Arguments: @rmd160_ctx *ctx@ = pointer to context block |
127 | * @void *hash@ = pointer to output buffer |
128 | * |
129 | * Returns: --- |
130 | * |
131 | * Use: Returns the hash of the data read so far. |
132 | */ |
133 | |
134 | extern void rmd160_done(rmd160_ctx */*ctx*/, void */*hash*/); |
135 | |
136 | /* --- @rmd160_state@ --- * |
137 | * |
138 | * Arguments: @rmd160_ctx *ctx@ = pointer to context |
139 | * @void *state@ = pointer to buffer for current state |
140 | * |
141 | * Returns: Number of bytes written to the hash function so far. |
142 | * |
143 | * Use: Returns the current state of the hash function such that |
144 | * it can be passed to @rmd160_set@. |
145 | */ |
146 | |
147 | extern unsigned long rmd160_state(rmd160_ctx */*ctx*/, void */*state*/); |
148 | |
dc2f0497 |
149 | /*----- Generic hash interface --------------------------------------------*/ |
150 | |
151 | extern const gchash rmd160; |
152 | |
d03ab969 |
153 | /*----- That's all, folks -------------------------------------------------*/ |
154 | |
155 | #ifdef __cplusplus |
156 | } |
157 | #endif |
158 | |
159 | #endif |