3 * The Tiger 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 Tiger hash function ----------------------------------*
30 * Tiger was designed by Eli Biham and Ross Anderson to be an efficient and
31 * secure hash function which worked well on 64-bit processors. This
32 * implementation should work everywhere, but it'll be faster if real 64-bit
33 * arithmetic is available.
35 * I don't know of any really good analysis of Tiger.
38 #ifndef CATACOMB_TIGER_H
39 #define CATACOMB_TIGER_H
45 /*----- Header files ------------------------------------------------------*/
47 #include <mLib/bits.h>
49 #ifndef CATACOMB_GHASH_H
53 /*----- Magic numbers -----------------------------------------------------*/
55 #define TIGER_BUFSZ 64
56 #define TIGER_HASHSZ 24
57 #define TIGER_STATESZ 24
59 /*----- Data structures ---------------------------------------------------*/
61 typedef struct tiger_ctx {
62 kludge64 a, b, c; /* Chaining variables */
63 uint32 nl, nh; /* Byte count so far */
64 unsigned off; /* Offset into buffer */
65 octet buf[TIGER_BUFSZ]; /* Accumulation buffer */
68 /*----- Functions provided ------------------------------------------------*/
70 /* --- @tiger_compress@ --- *
72 * Arguments: @tiger_ctx *ctx@ = pointer to context block
73 * @const void *sbuf@ = pointer to buffer of appropriate size
77 * Use: Tiger compression function.
80 extern void tiger_compress(tiger_ctx */*ctx*/, const void */*sbuf*/);
82 /* --- @tiger_init@ --- *
84 * Arguments: @tiger_ctx *ctx@ = pointer to context block to initialize
88 * Use: Initializes a context block ready for hashing.
91 extern void tiger_init(tiger_ctx */*ctx*/);
93 /* --- @tiger_set@ --- *
95 * Arguments: @tiger_ctx *ctx@ = pointer to context block
96 * @const void *buf@ = pointer to state buffer
97 * @unsigned long count@ = current count of bytes processed
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.
106 extern void tiger_set(tiger_ctx */*ctx*/, const void */*buf*/,
107 unsigned long /*count*/);
109 /* --- @tiger_hash@ --- *
111 * Arguments: @tiger_ctx *ctx@ = pointer to context block
112 * @const void *buf@ = buffer of data to hash
113 * @size_t sz@ = size of buffer to hash
117 * Use: Hashes a buffer of data. The buffer may be of any size and
121 extern void tiger_hash(tiger_ctx */*ctx*/, const void */*buf*/, size_t /*sz*/);
123 /* --- @tiger_done@ --- *
125 * Arguments: @tiger_ctx *ctx@ = pointer to context block
126 * @void *hash@ = pointer to output buffer
130 * Use: Returns the hash of the data read so far.
133 extern void tiger_done(tiger_ctx */*ctx*/, void */*hash*/);
135 /* --- @tiger_state@ --- *
137 * Arguments: @tiger_ctx *ctx@ = pointer to context
138 * @void *state@ = pointer to buffer for current state
140 * Returns: Number of bytes written to the hash function so far.
142 * Use: Returns the current state of the hash function such that
143 * it can be passed to @tiger_set@.
146 extern unsigned long tiger_state(tiger_ctx */*ctx*/, void */*state*/);
148 /*----- Generic hash interface --------------------------------------------*/
150 extern const gchash tiger;
152 /*----- That's all, folks -------------------------------------------------*/