1/*
2 * xxx.c --
3 *
4 *	Implements and registers message digest generator XXX.
5 *
6 *
7 * Copyright (c) 1995 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: md_template.c,v 1.1.1.1 1997/02/05 20:51:08 aku Exp $
28 */
29
30#include "transformInt.h"
31#include "xxx/xxx.h"
32
33/*
34 * Generator description
35 * ---------------------
36 *
37 * The XXX alogrithm is used to compute a cryptographically strong
38 * message digest.
39 */
40
41#define DIGEST_SIZE               (0)
42#define CTX_TYPE                  XXX
43
44/*
45 * Declarations of internal procedures.
46 */
47
48static void MD_Start     _ANSI_ARGS_ ((VOID* context));
49static void MD_Update    _ANSI_ARGS_ ((VOID* context, int character));
50static void MD_UpdateBuf _ANSI_ARGS_ ((VOID* context, char* buffer, int bufLen));
51static void MD_Final     _ANSI_ARGS_ ((VOID* context, VOID* digest));
52static int  MD_Check     _ANSI_ARGS_ ((Tcl_Interp* interp));
53
54/*
55 * Generator definition.
56 */
57
58static Trf_MessageDigestDescription mdDescription = {
59  "xxx",
60  sizeof (CTX_TYPE),
61  DIGEST_SIZE,
62  MD_Start,
63  MD_Update,
64  MD_UpdateBuf,
65  MD_Final,
66  MD_Check
67};
68
69/*
70 *------------------------------------------------------*
71 *
72 *	TrfInit_XXX --
73 *
74 *	------------------------------------------------*
75 *	Register the generator implemented in this file.
76 *	------------------------------------------------*
77 *
78 *	Sideeffects:
79 *		As of 'Trf_Register'.
80 *
81 *	Result:
82 *		A standard Tcl error code.
83 *
84 *------------------------------------------------------*
85 */
86
87int
88TrfInit_XXX (interp)
89Tcl_Interp* interp;
90{
91  return Trf_RegisterMessageDigest (interp, &mdDescription);
92}
93
94/*
95 *------------------------------------------------------*
96 *
97 *	MD_Start --
98 *
99 *	------------------------------------------------*
100 *	Initialize the internal state of the message
101 *	digest generator.
102 *	------------------------------------------------*
103 *
104 *	Sideeffects:
105 *		As of the called procedure.
106 *
107 *	Result:
108 *		None.
109 *
110 *------------------------------------------------------*
111 */
112
113static void
114MD_Start (context)
115VOID* context;
116{
117  /* call md specific initialization here */
118}
119
120/*
121 *------------------------------------------------------*
122 *
123 *	MD_Update --
124 *
125 *	------------------------------------------------*
126 *	Update the internal state of the message digest
127 *	generator for a single character.
128 *	------------------------------------------------*
129 *
130 *	Sideeffects:
131 *		As of the called procedure.
132 *
133 *	Result:
134 *		None.
135 *
136 *------------------------------------------------------*
137 */
138
139static void
140MD_Update (context, character)
141VOID* context;
142int   character;
143{
144  char buf = character;
145
146  /* call md specific update here */
147}
148
149/*
150 *------------------------------------------------------*
151 *
152 *	MD_UpdateBuf --
153 *
154 *	------------------------------------------------*
155 *	Update the internal state of the message digest
156 *	generator for a character buffer.
157 *	------------------------------------------------*
158 *
159 *	Sideeffects:
160 *		As of the called procedure.
161 *
162 *	Result:
163 *		None.
164 *
165 *------------------------------------------------------*
166 */
167
168static void
169MD_Updatebuf (context, buffer, bufLen)
170VOID* context;
171char* buffer;
172int   bufLen;
173{
174  sha_trf_info* s = context;
175
176  if ((s->count + bufLen) < CHUNK_SIZE) {
177    /*
178     * Not enough for full chunk. Remember incoming
179     * data and wait for another call containing more data.
180     */
181
182    memcpy ((VOID*) (s->buf + s->count), (VOID*) buffer, bufLen);
183    s->count += bufLen;
184  } else {
185    /*
186     * Complete chunk with incoming data, update digest,
187     * then use all chunks contained in the buffer. Remember
188     * an incomplete chunk and wait for further calls.
189     */
190
191    int k = CHUNK_SIZE - s->count;
192
193    if (k < CHUNK_SIZE) {
194      memcpy ((VOID*) (s->buf + s->count), (VOID*) buffer, k);
195
196      sha_update (&s->s, s->buf, CHUNK_SIZE);
197
198      buffer += k;
199      bufLen -= k;
200    } /* k == CHUNK_SIZE => internal buffer was empty, so skip it entirely */
201
202    while (bufLen > CHUNK_SIZE) {
203      sha_update (&s->s, buffer, CHUNK_SIZE);
204
205      buffer += CHUNK_SIZE;
206      bufLen -= CHUNK_SIZE;
207    }
208
209    s->count = bufLen;
210    if (bufLen > 0)
211      memcpy ((VOID*) s->buf, (VOID*) buffer, bufLen);
212  }
213}
214
215/*
216 *------------------------------------------------------*
217 *
218 *	MD_Final --
219 *
220 *	------------------------------------------------*
221 *	Generate the digest from the internal state of
222 *	the message digest generator.
223 *	------------------------------------------------*
224 *
225 *	Sideeffects:
226 *		As of the called procedure.
227 *
228 *	Result:
229 *		None.
230 *
231 *------------------------------------------------------*
232 */
233
234static void
235MD_Final (context, digest)
236VOID* context;
237VOID* digest;
238{
239  /* call md specific finalization here */
240}
241
242/*
243 *------------------------------------------------------*
244 *
245 *	MD_Check --
246 *
247 *	------------------------------------------------*
248 *	Check environment (required shared libs, ...).
249 *	------------------------------------------------*
250 *
251 *	Sideeffects:
252 *		As of the called procedure.
253 *
254 *	Result:
255 *		None.
256 *
257 *------------------------------------------------------*
258 */
259
260static int
261MD_Check (interp)
262Tcl_Interp* interp;
263{
264  return TCL_OK;
265}
266
267/*
268 * External code from here on.
269 */
270
271#include "xxx/xxx.c"
272