1/*
2 * haval.c --
3 *
4 *	Implements and registers message digest generator HAVAL.
5 *
6 *
7 * Copyright (c) 1996 Andreas Kupries (a.kupries@westend.com)
8 * All rights reserved.
9 *
10 * Permission is hereby granted, without written agreement and without
11 * license or royalty fees, to use, copy, modify, and distribute this
12 * software and its documentation for any purpose, provided that the
13 * above copyright notice and the following two paragraphs appear in
14 * all copies of this software.
15 *
16 * IN NO EVENT SHALL I LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
17 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
18 * SOFTWARE AND ITS DOCUMENTATION, EVEN IF I HAVE BEEN ADVISED OF THE
19 * POSSIBILITY OF SUCH DAMAGE.
20 *
21 * I SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
24 * I HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
25 * ENHANCEMENTS, OR MODIFICATIONS.
26 *
27 * CVS: $Id: haval.c,v 1.4 2000/08/09 19:13:17 aku Exp $
28 */
29
30#include "transformInt.h"
31#include "haval.1996/haval.h"
32
33/*
34 * Generator description
35 * ---------------------
36 *
37 * The HAVAL alogrithm is used to compute a cryptographically strong
38 * message digest.
39 */
40
41#define DIGEST_SIZE               (32)
42#define CTX_TYPE                  haval_state
43
44/*
45 * Declarations of internal procedures.
46 */
47
48static void MDHaval_Start     _ANSI_ARGS_ ((VOID* context));
49static void MDHaval_Update    _ANSI_ARGS_ ((VOID* context, unsigned int character));
50static void MDHaval_UpdateBuf _ANSI_ARGS_ ((VOID* context, unsigned char* buffer, int bufLen));
51static void MDHaval_Final     _ANSI_ARGS_ ((VOID* context, VOID* digest));
52
53/*
54 * Generator definition.
55 */
56
57static Trf_MessageDigestDescription mdDescription = { /* THREADING: constant, read-only => safe */
58  "haval",
59  sizeof (CTX_TYPE),
60  DIGEST_SIZE,
61  MDHaval_Start,
62  MDHaval_Update,
63  MDHaval_UpdateBuf,
64  MDHaval_Final,
65  NULL
66};
67
68/*
69 *------------------------------------------------------*
70 *
71 *	TrfInit_HAVAL --
72 *
73 *	------------------------------------------------*
74 *	Register the generator implemented in this file.
75 *	------------------------------------------------*
76 *
77 *	Sideeffects:
78 *		As of 'Trf_Register'.
79 *
80 *	Result:
81 *		A standard Tcl error code.
82 *
83 *------------------------------------------------------*
84 */
85
86int
87TrfInit_HAVAL (interp)
88Tcl_Interp* interp;
89{
90  return Trf_RegisterMessageDigest (interp, &mdDescription);
91}
92
93/*
94 *------------------------------------------------------*
95 *
96 *	MDHaval_Start --
97 *
98 *	------------------------------------------------*
99 *	Initialize the internal state of the message
100 *	digest generator.
101 *	------------------------------------------------*
102 *
103 *	Sideeffects:
104 *		As of the called procedure.
105 *
106 *	Result:
107 *		None.
108 *
109 *------------------------------------------------------*
110 */
111
112static void
113MDHaval_Start (context)
114VOID* context;
115{
116  haval_start ((CTX_TYPE*) context);
117}
118
119/*
120 *------------------------------------------------------*
121 *
122 *	MDHaval_Update --
123 *
124 *	------------------------------------------------*
125 *	Update the internal state of the message digest
126 *	generator for a single character.
127 *	------------------------------------------------*
128 *
129 *	Sideeffects:
130 *		As of the called procedure.
131 *
132 *	Result:
133 *		None.
134 *
135 *------------------------------------------------------*
136 */
137
138static void
139MDHaval_Update (context, character)
140VOID* context;
141unsigned int   character;
142{
143  unsigned char buf = character;
144
145  haval_hash ((CTX_TYPE*) context, &buf, 1);
146}
147
148/*
149 *------------------------------------------------------*
150 *
151 *	MDHaval_UpdateBuf --
152 *
153 *	------------------------------------------------*
154 *	Update the internal state of the message digest
155 *	generator for a character buffer.
156 *	------------------------------------------------*
157 *
158 *	Sideeffects:
159 *		As of the called procedure.
160 *
161 *	Result:
162 *		None.
163 *
164 *------------------------------------------------------*
165 */
166
167static void
168MDHaval_UpdateBuf (context, buffer, bufLen)
169VOID* context;
170unsigned char* buffer;
171int   bufLen;
172{
173  haval_hash ((CTX_TYPE*) context, (unsigned char*) buffer, bufLen);
174}
175
176/*
177 *------------------------------------------------------*
178 *
179 *	MDHaval_Final --
180 *
181 *	------------------------------------------------*
182 *	Generate the digest from the internal state of
183 *	the message digest generator.
184 *	------------------------------------------------*
185 *
186 *	Sideeffects:
187 *		As of the called procedure.
188 *
189 *	Result:
190 *		None.
191 *
192 *------------------------------------------------------*
193 */
194
195static void
196MDHaval_Final (context, digest)
197VOID* context;
198VOID* digest;
199{
200  haval_end ((CTX_TYPE*) context, (unsigned char*) digest);
201}
202
203/*
204 * External code from here on.
205 */
206
207#include "haval.1996/haval.c" /* THREADING: import of one constant var, read-only => safe */
208