f60fdc9b917a540121b28b5e09e95afb2d9c51a6
[u/mdw/catacomb] / has160.h
1 /* -*-c-*-
2 *
3 * $Id: has160.h,v 1.1 2004/04/04 19:42:59 mdw Exp $
4 *
5 * The HAS160 message digest function
6 *
7 * (c) 2004 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
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.
18 *
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.
23 *
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,
27 * MA 02111-1307, USA.
28 */
29
30 /*----- Revision history --------------------------------------------------*
31 *
32 * $Log: has160.h,v $
33 * Revision 1.1 2004/04/04 19:42:59 mdw
34 * Add set -e.
35 *
36 */
37
38 /*----- Notes on the HAS160 hash function ---------------------------------*
39 *
40 * HAS160 was designed by Chae Hoon Lim and the Korean Information Security
41 * Agency (KISA). It's recommended for use with KCDSA (though I think I'm
42 * happer with RIPEMD-160 or SHA1). It's here so I can check KCDSA test
43 * vectors.
44 */
45
46 #ifndef CATACOMB_HAS160_H
47 #define CATACOMB_HAS160_H
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 /*----- Header files ------------------------------------------------------*/
54
55 #include <mLib/bits.h>
56
57 #ifndef CATACOMB_GHASH_H
58 # include "ghash.h"
59 #endif
60
61 /*----- Magic numbers -----------------------------------------------------*/
62
63 #define HAS160_BUFSZ 64
64 #define HAS160_HASHSZ 20
65 #define HAS160_STATESZ 20
66
67 /*----- Data structures ---------------------------------------------------*/
68
69 typedef struct has160_ctx {
70 uint32 a, b, c, d, e; /* Chaining variables */
71 uint32 nl, nh; /* Byte count so far */
72 unsigned off; /* Offset into buffer */
73 octet buf[HAS160_BUFSZ]; /* Accumulation buffer */
74 } has160_ctx;
75
76 /*----- Functions provided ------------------------------------------------*/
77
78 /* --- @has160_compress@ --- *
79 *
80 * Arguments: @has160_ctx *ctx@ = pointer to context block
81 * @const void *sbuf@ = pointer to buffer of appropriate size
82 *
83 * Returns: ---
84 *
85 * Use: HAS160 compression function.
86 */
87
88 extern void has160_compress(has160_ctx */*ctx*/, const void */*sbuf*/);
89
90 /* --- @has160_init@ --- *
91 *
92 * Arguments: @has160_ctx *ctx@ = pointer to context block to initialize
93 *
94 * Returns: ---
95 *
96 * Use: Initializes a context block ready for hashing.
97 */
98
99 extern void has160_init(has160_ctx */*ctx*/);
100
101 /* --- @has160_set@ --- *
102 *
103 * Arguments: @has160_ctx *ctx@ = pointer to context block
104 * @const void *buf@ = pointer to state buffer
105 * @unsigned long count@ = current count of bytes processed
106 *
107 * Returns: ---
108 *
109 * Use: Initializes a context block from a given state. This is
110 * useful in cases where the initial hash state is meant to be
111 * secret, e.g., for NMAC and HMAC support.
112 */
113
114 extern void has160_set(has160_ctx */*ctx*/, const void */*buf*/,
115 unsigned long /*count*/);
116
117 /* --- @has160_hash@ --- *
118 *
119 * Arguments: @has160_ctx *ctx@ = pointer to context block
120 * @const void *buf@ = buffer of data to hash
121 * @size_t sz@ = size of buffer to hash
122 *
123 * Returns: ---
124 *
125 * Use: Hashes a buffer of data. The buffer may be of any size and
126 * alignment.
127 */
128
129 extern void has160_hash(has160_ctx */*ctx*/,
130 const void */*buf*/, size_t /*sz*/);
131
132 /* --- @has160_done@ --- *
133 *
134 * Arguments: @has160_ctx *ctx@ = pointer to context block
135 * @void *hash@ = pointer to output buffer
136 *
137 * Returns: ---
138 *
139 * Use: Returns the hash of the data read so far.
140 */
141
142 extern void has160_done(has160_ctx */*ctx*/, void */*hash*/);
143
144 /* --- @has160_state@ --- *
145 *
146 * Arguments: @has160_ctx *ctx@ = pointer to context
147 * @void *state@ = pointer to buffer for current state
148 *
149 * Returns: Number of bytes written to the hash function so far.
150 *
151 * Use: Returns the current state of the hash function such that
152 * it can be passed to @has160_set@.
153 */
154
155 extern unsigned long has160_state(has160_ctx */*ctx*/, void */*state*/);
156
157 /*----- Generic hash interface --------------------------------------------*/
158
159 extern const gchash has160;
160
161 /*----- That's all, folks -------------------------------------------------*/
162
163 #ifdef __cplusplus
164 }
165 #endif
166
167 #endif