5 * Implementation of the Whirlpool hash function
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
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.
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.
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,
30 /*----- Notes on the Whirlpool hash function ------------------------------*
32 * Whirlpool was designed by Paulo Barreto and Vincent Rijmen. Its
33 * compression function is based on similar ideas to Rijndael (also
34 * codesigned by Rijmen).
36 * Whirlpool256 is simply Whirlpool with its final output truncated to 256
37 * bits. This is, I hope, about as good as a 256-bit hash function can get.
38 * It isn't vulnerable to the Kelsey-Schneier generic second-preimage attack
39 * against MD hash functions because of its larger internal state (see also
43 #ifndef CATACOMB_WHIRLPOOL_H
44 #define CATACOMB_WHIRLPOOL_H
45 #define CATACOMB_WHIRLPOOL256_H
51 /*----- Header files ------------------------------------------------------*/
53 #include <mLib/bits.h>
55 #ifndef CATACOMB_GHASH_H
59 /*----- Magic numbers -----------------------------------------------------*/
61 #define WHIRLPOOL_BUFSZ 64
62 #define WHIRLPOOL_HASHSZ 64
63 #define WHIRLPOOL_STATESZ 64
65 #define WHIRLPOOL256_BUFSZ 64
66 #define WHIRLPOOL256_HASHSZ 32
67 #define WHIRLPOOL256_STATESZ 64
69 /*----- Data structures ---------------------------------------------------*/
71 typedef struct whirlpool_ctx {
72 kludge64 s[8]; /* Chaining variables */
73 uint32 nh, nl; /* Byte count so far */
74 unsigned off; /* Offset into buffer */
75 octet buf[WHIRLPOOL_BUFSZ]; /* Accumulation buffer */
76 } whirlpool_ctx, whirlpool256_ctx;
78 /*----- Functions provided ------------------------------------------------*/
80 /* --- @whirlpool_compress@, @whirlpool256_compress@ --- *
82 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block
83 * @const void *sbuf@ = pointer to buffer of appropriate size
87 * Use: SHA-512 compression function.
90 extern void whirlpool_compress(whirlpool_ctx */*ctx*/, const void */*sbuf*/);
91 #define whirlpool256_compress whirlpool_compress
93 /* --- @whirlpool_init@, @whirlpool256_init@ --- *
95 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block to initialize
99 * Use: Initializes a context block ready for hashing.
102 extern void whirlpool_init(whirlpool_ctx */*ctx*/);
103 #define whirlpool256_init whirlpool_init
105 /* --- @whirlpool_set@, @whirlpool256_set@ --- *
107 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block
108 * @const void *buf@ = pointer to state buffer
109 * @unsigned long count@ = current count of bytes processed
113 * Use: Initializes a context block from a given state. This is
114 * useful in cases where the initial hash state is meant to be
115 * secret, e.g., for NMAC and HMAC support.
118 extern void whirlpool_set(whirlpool_ctx */*ctx*/, const void */*buf*/,
119 unsigned long /*count*/);
120 #define whirlpool256_set whirlpool_set
122 /* --- @whirlpool_hash@, @whirlpool256_hash@ --- *
124 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block
125 * @const void *buf@ = buffer of data to hash
126 * @size_t sz@ = size of buffer to hash
130 * Use: Hashes a buffer of data. The buffer may be of any size and
134 extern void whirlpool_hash(whirlpool_ctx */*ctx*/,
135 const void */*buf*/, size_t /*sz*/);
136 #define whirlpool256_hash whirlpool_hash
138 /* --- @whirlpool_done@, @whirlpool256_done@ --- *
140 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block
141 * @void *hash@ = pointer to output buffer
145 * Use: Returns the hash of the data read so far.
148 extern void whirlpool_done(whirlpool_ctx */*ctx*/, void */*hash*/);
149 extern void whirlpool256_done(whirlpool_ctx */*ctx*/, void */*hash*/);
151 /* --- @whirlpool_state@, @whirlpool256_state@ --- *
153 * Arguments: @whirlpool_ctx *ctx@ = pointer to context
154 * @void *state@ = pointer to buffer for current state
156 * Returns: Number of bytes written to the hash function so far.
158 * Use: Returns the current state of the hash function such that
159 * it can be passed to @whirlpool_set@.
162 extern unsigned long whirlpool_state(whirlpool_ctx */*ctx*/,
164 #define whirlpool256_state whirlpool_state
166 /*----- Generic hash interface --------------------------------------------*/
168 extern const gchash whirlpool;
169 extern const gchash whirlpool256;
171 /*----- That's all, folks -------------------------------------------------*/