3 * Implementation of the Whirlpool hash function
5 * (c) 2000 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 Whirlpool hash function ------------------------------*
30 * Whirlpool was designed by Paulo Barreto and Vincent Rijmen. Its
31 * compression function is based on similar ideas to Rijndael (also
32 * codesigned by Rijmen).
34 * Whirlpool256 is simply Whirlpool with its final output truncated to 256
35 * bits. This is, I hope, about as good as a 256-bit hash function can get.
36 * It isn't vulnerable to the Kelsey-Schneier generic second-preimage attack
37 * against MD hash functions because of its larger internal state (see also
41 #ifndef CATACOMB_WHIRLPOOL_H
42 #define CATACOMB_WHIRLPOOL_H
43 #define CATACOMB_WHIRLPOOL256_H
49 /*----- Header files ------------------------------------------------------*/
51 #include <mLib/bits.h>
53 #ifndef CATACOMB_GHASH_H
57 /*----- Magic numbers -----------------------------------------------------*/
59 #define WHIRLPOOL_BUFSZ 64
60 #define WHIRLPOOL_HASHSZ 64
61 #define WHIRLPOOL_STATESZ 64
63 #define WHIRLPOOL256_BUFSZ 64
64 #define WHIRLPOOL256_HASHSZ 32
65 #define WHIRLPOOL256_STATESZ 64
67 /*----- Data structures ---------------------------------------------------*/
69 typedef struct whirlpool_ctx {
70 kludge64 s[8]; /* Chaining variables */
71 uint32 nh, nl; /* Byte count so far */
72 unsigned off; /* Offset into buffer */
73 octet buf[WHIRLPOOL_BUFSZ]; /* Accumulation buffer */
74 } whirlpool_ctx, whirlpool256_ctx;
76 /*----- Functions provided ------------------------------------------------*/
78 /* --- @whirlpool_compress@, @whirlpool256_compress@ --- *
80 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block
81 * @const void *sbuf@ = pointer to buffer of appropriate size
85 * Use: SHA-512 compression function.
88 extern void whirlpool_compress(whirlpool_ctx */*ctx*/, const void */*sbuf*/);
89 #define whirlpool256_compress whirlpool_compress
91 /* --- @whirlpool_init@, @whirlpool256_init@ --- *
93 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block to initialize
97 * Use: Initializes a context block ready for hashing.
100 extern void whirlpool_init(whirlpool_ctx */*ctx*/);
101 #define whirlpool256_init whirlpool_init
103 /* --- @whirlpool_set@, @whirlpool256_set@ --- *
105 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block
106 * @const void *buf@ = pointer to state buffer
107 * @unsigned long count@ = current count of bytes processed
111 * Use: Initializes a context block from a given state. This is
112 * useful in cases where the initial hash state is meant to be
113 * secret, e.g., for NMAC and HMAC support.
116 extern void whirlpool_set(whirlpool_ctx */*ctx*/, const void */*buf*/,
117 unsigned long /*count*/);
118 #define whirlpool256_set whirlpool_set
120 /* --- @whirlpool_hash@, @whirlpool256_hash@ --- *
122 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block
123 * @const void *buf@ = buffer of data to hash
124 * @size_t sz@ = size of buffer to hash
128 * Use: Hashes a buffer of data. The buffer may be of any size and
132 extern void whirlpool_hash(whirlpool_ctx */*ctx*/,
133 const void */*buf*/, size_t /*sz*/);
134 #define whirlpool256_hash whirlpool_hash
136 /* --- @whirlpool_done@, @whirlpool256_done@ --- *
138 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block
139 * @void *hash@ = pointer to output buffer
143 * Use: Returns the hash of the data read so far.
146 extern void whirlpool_done(whirlpool_ctx */*ctx*/, void */*hash*/);
147 extern void whirlpool256_done(whirlpool_ctx */*ctx*/, void */*hash*/);
149 /* --- @whirlpool_state@, @whirlpool256_state@ --- *
151 * Arguments: @whirlpool_ctx *ctx@ = pointer to context
152 * @void *state@ = pointer to buffer for current state
154 * Returns: Number of bytes written to the hash function so far.
156 * Use: Returns the current state of the hash function such that
157 * it can be passed to @whirlpool_set@.
160 extern unsigned long whirlpool_state(whirlpool_ctx */*ctx*/,
162 #define whirlpool256_state whirlpool_state
164 /*----- Generic hash interface --------------------------------------------*/
166 extern const gchash whirlpool;
167 extern const gchash whirlpool256;
169 /*----- That's all, folks -------------------------------------------------*/