3 * The RIPEMD-256 message digest function
5 * (c) 1998 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
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.
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.
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,
28 /*----- Notes on the RIPEMD-256 hash function -----------------------------*
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
38 #ifndef CATACOMB_RMD256_H
39 #define CATACOMB_RMD256_H
45 /*----- Header files ------------------------------------------------------*/
47 #include <mLib/bits.h>
49 #ifndef CATACOMB_GHASH_H
53 /*----- Magic numbers -----------------------------------------------------*/
55 #define RMD256_BUFSZ 64
56 #define RMD256_HASHSZ 32
57 #define RMD256_STATESZ 32
59 /*----- Data structures ---------------------------------------------------*/
61 typedef 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 */
69 /*----- Functions provided ------------------------------------------------*/
71 /* --- @rmd256_compress@ --- *
73 * Arguments: @rmd256_ctx *ctx@ = pointer to context block
74 * @const void *sbuf@ = pointer to buffer of appropriate size
78 * Use: RIPEMD-256 compression function.
81 extern void rmd256_compress(rmd256_ctx */*ctx*/, const void */*sbuf*/);
83 /* --- @rmd256_init@ --- *
85 * Arguments: @rmd256_ctx *ctx@ = pointer to context block to initialize
89 * Use: Initializes a context block ready for hashing.
92 extern void rmd256_init(rmd256_ctx */*ctx*/);
94 /* --- @rmd256_set@ --- *
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
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.
107 extern void rmd256_set(rmd256_ctx */*ctx*/,
108 const void */*buf*/, unsigned long /*count*/);
110 /* --- @rmd256_hash@ --- *
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
118 * Use: Hashes a buffer of data. The buffer may be of any size and
122 extern void rmd256_hash(rmd256_ctx */*ctx*/,
123 const void */*buf*/, size_t /*sz*/);
125 /* --- @rmd256_done@ --- *
127 * Arguments: @rmd256_ctx *ctx@ = pointer to context block
128 * @void *hash@ = pointer to output buffer
132 * Use: Returns the hash of the data read so far.
135 extern void rmd256_done(rmd256_ctx */*ctx*/, void */*hash*/);
137 /* --- @rmd256_state@ --- *
139 * Arguments: @rmd256_ctx *ctx@ = pointer to context
140 * @void *state@ = pointer to buffer for current state
142 * Returns: Number of bytes written to the hash function so far.
144 * Use: Returns the current state of the hash function such that
145 * it can be passed to @rmd256_set@.
148 extern unsigned long rmd256_state(rmd256_ctx */*ctx*/, void */*state*/);
150 /*----- Generic hash interface --------------------------------------------*/
152 extern const gchash rmd256;
154 /*----- That's all, folks -------------------------------------------------*/