math/mpreduce.h: Missing include files.
[u/mdw/catacomb] / symm / whirlpool.h
CommitLineData
7fcfe7de 1/* -*-c-*-
2 *
7fcfe7de 3 * Implementation of the Whirlpool hash function
4 *
5 * (c) 2000 Straylight/Edgeware
6 */
7
45c0fd36 8/*----- Licensing notice --------------------------------------------------*
7fcfe7de 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 *
7fcfe7de 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 *
7fcfe7de 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
28/*----- Notes on the Whirlpool hash function ------------------------------*
29 *
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).
33 *
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
38 * Lucks).
39 */
40
41#ifndef CATACOMB_WHIRLPOOL_H
42#define CATACOMB_WHIRLPOOL_H
43#define CATACOMB_WHIRLPOOL256_H
44
45#ifdef __cplusplus
46 extern "C" {
47#endif
48
49/*----- Header files ------------------------------------------------------*/
50
51#include <mLib/bits.h>
52
53#ifndef CATACOMB_GHASH_H
54# include "ghash.h"
55#endif
56
57/*----- Magic numbers -----------------------------------------------------*/
58
59#define WHIRLPOOL_BUFSZ 64
60#define WHIRLPOOL_HASHSZ 64
61#define WHIRLPOOL_STATESZ 64
62
63#define WHIRLPOOL256_BUFSZ 64
64#define WHIRLPOOL256_HASHSZ 32
65#define WHIRLPOOL256_STATESZ 64
66
67/*----- Data structures ---------------------------------------------------*/
68
69typedef 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;
75
76/*----- Functions provided ------------------------------------------------*/
77
78/* --- @whirlpool_compress@, @whirlpool256_compress@ --- *
79 *
80 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block
81 * @const void *sbuf@ = pointer to buffer of appropriate size
82 *
83 * Returns: ---
84 *
85 * Use: SHA-512 compression function.
86 */
87
88extern void whirlpool_compress(whirlpool_ctx */*ctx*/, const void */*sbuf*/);
89#define whirlpool256_compress whirlpool_compress
90
91/* --- @whirlpool_init@, @whirlpool256_init@ --- *
92 *
93 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block to initialize
94 *
95 * Returns: ---
96 *
97 * Use: Initializes a context block ready for hashing.
98 */
99
100extern void whirlpool_init(whirlpool_ctx */*ctx*/);
101#define whirlpool256_init whirlpool_init
102
103/* --- @whirlpool_set@, @whirlpool256_set@ --- *
104 *
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
108 *
109 * Returns: ---
110 *
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.
114 */
115
116extern void whirlpool_set(whirlpool_ctx */*ctx*/, const void */*buf*/,
117 unsigned long /*count*/);
118#define whirlpool256_set whirlpool_set
119
120/* --- @whirlpool_hash@, @whirlpool256_hash@ --- *
121 *
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
125 *
126 * Returns: ---
127 *
128 * Use: Hashes a buffer of data. The buffer may be of any size and
129 * alignment.
130 */
131
132extern void whirlpool_hash(whirlpool_ctx */*ctx*/,
133 const void */*buf*/, size_t /*sz*/);
134#define whirlpool256_hash whirlpool_hash
135
136/* --- @whirlpool_done@, @whirlpool256_done@ --- *
137 *
138 * Arguments: @whirlpool_ctx *ctx@ = pointer to context block
139 * @void *hash@ = pointer to output buffer
140 *
141 * Returns: ---
142 *
143 * Use: Returns the hash of the data read so far.
144 */
145
146extern void whirlpool_done(whirlpool_ctx */*ctx*/, void */*hash*/);
147extern void whirlpool256_done(whirlpool_ctx */*ctx*/, void */*hash*/);
148
149/* --- @whirlpool_state@, @whirlpool256_state@ --- *
150 *
151 * Arguments: @whirlpool_ctx *ctx@ = pointer to context
152 * @void *state@ = pointer to buffer for current state
153 *
154 * Returns: Number of bytes written to the hash function so far.
155 *
156 * Use: Returns the current state of the hash function such that
157 * it can be passed to @whirlpool_set@.
158 */
159
160extern unsigned long whirlpool_state(whirlpool_ctx */*ctx*/,
161 void */*state*/);
162#define whirlpool256_state whirlpool_state
163
164/*----- Generic hash interface --------------------------------------------*/
165
166extern const gchash whirlpool;
167extern const gchash whirlpool256;
168
169/*----- That's all, folks -------------------------------------------------*/
170
171#ifdef __cplusplus
172 }
173#endif
174
175#endif