8d9059f95a16bff6286032697b75e8742480bc7a
[openssl.git] / crypto / md32_common.h
1 /* crypto/md32_common.h */
2 /* ====================================================================
3  * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer. 
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in
14  *    the documentation and/or other materials provided with the
15  *    distribution.
16  *
17  * 3. All advertising materials mentioning features or use of this
18  *    software must display the following acknowledgment:
19  *    "This product includes software developed by the OpenSSL Project
20  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21  *
22  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23  *    endorse or promote products derived from this software without
24  *    prior written permission. For written permission, please contact
25  *    licensing@OpenSSL.org.
26  *
27  * 5. Products derived from this software may not be called "OpenSSL"
28  *    nor may "OpenSSL" appear in their names without prior written
29  *    permission of the OpenSSL Project.
30  *
31  * 6. Redistributions of any form whatsoever must retain the following
32  *    acknowledgment:
33  *    "This product includes software developed by the OpenSSL Project
34  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35  *
36  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47  * OF THE POSSIBILITY OF SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This product includes cryptographic software written by Eric Young
51  * (eay@cryptsoft.com).  This product includes software written by Tim
52  * Hudson (tjh@cryptsoft.com).
53  *
54  */
55
56 /*
57  * This is a generic 32 bit "collector" for message digest algorithms.
58  * Whenever needed it collects input character stream into chunks of
59  * 32 bit values and invokes a block function that performs actual hash
60  * calculations.
61  *
62  * Porting guide.
63  *
64  * Obligatory macros:
65  *
66  * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN
67  *      this macro defines byte order of input stream.
68  * HASH_CBLOCK
69  *      size of a unit chunk HASH_BLOCK operates on.
70  * HASH_LONG
71  *      has to be at lest 32 bit wide, if it's wider, then
72  *      HASH_LONG_LOG2 *has to* be defined along
73  * HASH_CTX
74  *      context structure that at least contains following
75  *      members:
76  *              typedef struct {
77  *                      ...
78  *                      HASH_LONG       Nl,Nh;
79  *                      HASH_LONG       data[HASH_LBLOCK];
80  *                      int             num;
81  *                      ...
82  *                      } HASH_CTX;
83  * HASH_UPDATE
84  *      name of "Update" function, implemented here.
85  * HASH_TRANSFORM
86  *      name of "Transform" function, implemented here.
87  * HASH_FINAL
88  *      name of "Final" function, implemented here.
89  * HASH_BLOCK_HOST_ORDER
90  *      name of "block" function treating *aligned* input message
91  *      in host byte order, implemented externally.
92  * HASH_BLOCK_DATA_ORDER
93  *      name of "block" function treating *unaligned* input message
94  *      in original (data) byte order, implemented externally (it
95  *      actually is optional if data and host are of the same
96  *      "endianess").
97  * HASH_MAKE_STRING
98  *      macro convering context variables to an ASCII hash string.
99  *
100  * Optional macros:
101  *
102  * B_ENDIAN or L_ENDIAN
103  *      defines host byte-order.
104  * HASH_LONG_LOG2
105  *      defaults to 2 if not states otherwise.
106  * HASH_LBLOCK
107  *      assumed to be HASH_CBLOCK/4 if not stated otherwise.
108  * HASH_BLOCK_DATA_ORDER_ALIGNED
109  *      alternative "block" function capable of treating
110  *      aligned input message in original (data) order,
111  *      implemented externally.
112  *
113  * MD5 example:
114  *
115  *      #define DATA_ORDER_IS_LITTLE_ENDIAN
116  *
117  *      #define HASH_LONG               MD5_LONG
118  *      #define HASH_LONG_LOG2          MD5_LONG_LOG2
119  *      #define HASH_CTX                MD5_CTX
120  *      #define HASH_CBLOCK             MD5_CBLOCK
121  *      #define HASH_LBLOCK             MD5_LBLOCK
122  *      #define HASH_UPDATE             MD5_Update
123  *      #define HASH_TRANSFORM          MD5_Transform
124  *      #define HASH_FINAL              MD5_Final
125  *      #define HASH_BLOCK_HOST_ORDER   md5_block_host_order
126  *      #define HASH_BLOCK_DATA_ORDER   md5_block_data_order
127  *
128  *                                      <appro@fy.chalmers.se>
129  */
130
131 #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
132 #error "DATA_ORDER must be defined!"
133 #endif
134
135 #ifndef HASH_CBLOCK
136 #error "HASH_CBLOCK must be defined!"
137 #endif
138 #ifndef HASH_LONG
139 #error "HASH_LONG must be defined!"
140 #endif
141 #ifndef HASH_CTX
142 #error "HASH_CTX must be defined!"
143 #endif
144
145 #ifndef HASH_UPDATE
146 #error "HASH_UPDATE must be defined!"
147 #endif
148 #ifndef HASH_TRANSFORM
149 #error "HASH_TRANSFORM must be defined!"
150 #endif
151 #ifndef HASH_FINAL
152 #error "HASH_FINAL must be defined!"
153 #endif
154
155 #ifndef HASH_BLOCK_HOST_ORDER
156 #error "HASH_BLOCK_HOST_ORDER must be defined!"
157 #endif
158
159 #if 0
160 /*
161  * Moved below as it's required only if HASH_BLOCK_DATA_ORDER_ALIGNED
162  * isn't defined.
163  */
164 #ifndef HASH_BLOCK_DATA_ORDER
165 #error "HASH_BLOCK_DATA_ORDER must be defined!"
166 #endif
167 #endif
168
169 #ifndef HASH_LBLOCK
170 #define HASH_LBLOCK     (HASH_CBLOCK/4)
171 #endif
172
173 #ifndef HASH_LONG_LOG2
174 #define HASH_LONG_LOG2  2
175 #endif
176
177 /*
178  * Engage compiler specific rotate intrinsic function if available.
179  */
180 #undef ROTATE
181 #ifndef PEDANTIC
182 # if defined(_MSC_VER)
183 #  define ROTATE(a,n)   _lrotl(a,n)
184 # elif defined(__MWERKS__)
185 #  ifdef __POWERPC__
186 #   defined ROTATE(a,n) __rlwinm(a,n,0,31)
187 #  else
188 #   define ROTATE(a,n)  __rol(a,n)
189 #  endif
190  B
191 # elif defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM)
192   /*
193    * Some GNU C inline assembler templates. Note that these are
194    * rotates by *constant* number of bits! But that's exactly
195    * what we need here...
196    *
197    *                                    <appro@fy.chalmers.se>
198    */
199 #  if defined(__i386)
200 #   define ROTATE(a,n)  ({ register unsigned int ret;   \
201                                 asm volatile (          \
202                                 "roll %1,%0"            \
203                                 : "=r"(ret)             \
204                                 : "I"(n), "0"(a)        \
205                                 : "cc");                \
206                            ret;                         \
207                         })
208 #  elif defined(__powerpc)
209 #   define ROTATE(a,n)  ({ register unsigned int ret;   \
210                                 asm volatile (          \
211                                 "rlwinm %0,%1,%2,0,31"  \
212                                 : "=r"(ret)             \
213                                 : "r"(a), "I"(n));      \
214                            ret;                         \
215                         })
216 #  endif
217 # endif
218
219 /*
220  * Engage compiler specific "fetch in reverse byte order"
221  * intrinsic function if available.
222  */
223 # if defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM)
224   /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */
225 #  if defined(__i386) && !defined(I386_ONLY)
226 #   define BE_FETCH32(a)        ({ register unsigned int l=(a);\
227                                 asm volatile (          \
228                                 "bswapl %0"             \
229                                 : "=r"(l) : "0"(l));    \
230                           l;                            \
231                         })
232 #  elif defined(__powerpc)
233 #   define LE_FETCH32(a)        ({ register unsigned int l;     \
234                                 asm volatile (          \
235                                 "lwbrx %0,0,%1"         \
236                                 : "=r"(l)               \
237                                 : "r"(a));              \
238                            l;                           \
239                         })
240
241 #  elif defined(__sparc) && defined(ULTRASPARC)
242 #  define LE_FETCH32(a) ({ register unsigned int l;             \
243                                 asm volatile (                  \
244                                 "lda [%1]#ASI_PRIMARY_LITTLE,%0"\
245                                 : "=r"(l)                       \
246                                 : "r"(a));                      \
247                            l;                                   \
248                         })
249 #  endif
250 # endif
251 #endif /* PEDANTIC */
252
253 #if HASH_LONG_LOG2==2   /* Engage only if sizeof(HASH_LONG)== 4 */
254 /* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
255 #ifdef ROTATE
256 /* 5 instructions with rotate instruction, else 9 */
257 #define REVERSE_FETCH32(a,l)    (                                       \
258                 l=*(const HASH_LONG *)(a),                              \
259                 ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24)))  \
260                                 )
261 #else
262 /* 6 instructions with rotate instruction, else 8 */
263 #define REVERSE_FETCH32(a,l)    (                               \
264                 l=*(const HASH_LONG *)(a),                      \
265                 l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)),    \
266                 ROTATE(l,16)                                    \
267                                 )
268 /*
269  * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|...
270  * It's rewritten as above for two reasons:
271  *      - RISCs aren't good at long constants and have to explicitely
272  *        compose 'em with several (well, usually 2) instructions in a
273  *        register before performing the actual operation and (as you
274  *        already realized:-) having same constant should inspire the
275  *        compiler to permanently allocate the only register for it;
276  *      - most modern CPUs have two ALUs, but usually only one has
277  *        circuitry for shifts:-( this minor tweak inspires compiler
278  *        to schedule shift instructions in a better way...
279  *
280  *                              <appro@fy.chalmers.se>
281  */
282 #endif
283 #endif
284
285 #ifndef ROTATE
286 #define ROTATE(a,n)     (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
287 #endif
288
289 /*
290  * Make some obvious choices. E.g., HASH_BLOCK_DATA_ORDER_ALIGNED
291  * and HASH_BLOCK_HOST_ORDER ought to be the same if input data
292  * and host are of the same "endianess". It's possible to mask
293  * this with blank #define HASH_BLOCK_DATA_ORDER though...
294  *
295  *                              <appro@fy.chalmers.se>
296  */
297 #if defined(B_ENDIAN)
298 #  if defined(DATA_ORDER_IS_BIG_ENDIAN)
299 #    if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
300 #      define HASH_BLOCK_DATA_ORDER_ALIGNED     HASH_BLOCK_HOST_ORDER
301 #    endif
302 #  elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
303 #    ifndef HOST_FETCH32
304 #      ifdef LE_FETCH32
305 #        define HOST_FETCH32(p,l)       LE_FETCH32(p)
306 #      elif defined(REVERSE_FETCH32)
307 #        define HOST_FETCH32(p,l)       REVERSE_FETCH32(p,l)
308 #      endif
309 #    endif
310 #  endif
311 #elif defined(L_ENDIAN)
312 #  if defined(DATA_ORDER_IS_LITTLE_ENDIAN)
313 #    if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
314 #      define HASH_BLOCK_DATA_ORDER_ALIGNED     HASH_BLOCK_HOST_ORDER
315 #    endif
316 #  elif defined(DATA_ORDER_IS_BIG_ENDIAN)
317 #    ifndef HOST_FETCH32
318 #      ifdef BE_FETCH32
319 #        define HOST_FETCH32(p,l)       BE_FETCH32(p)
320 #      elif defined(REVERSE_FETCH32)
321 #        define HOST_FETCH32(p,l)       REVERSE_FETCH32(p,l)
322 #      endif
323 #    endif
324 #  endif
325 #endif
326
327 #if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
328 #ifndef HASH_BLOCK_DATA_ORDER
329 #error "HASH_BLOCK_DATA_ORDER must be defined!"
330 #endif
331 #endif
332
333 #if defined(DATA_ORDER_IS_BIG_ENDIAN)
334
335 #define HOST_c2l(c,l)   (l =(((unsigned long)(*((c)++)))<<24),          \
336                          l|=(((unsigned long)(*((c)++)))<<16),          \
337                          l|=(((unsigned long)(*((c)++)))<< 8),          \
338                          l|=(((unsigned long)(*((c)++)))    ),          \
339                          l)
340 #define HOST_p_c2l(c,l,n)       {                                       \
341                         switch (n) {                                    \
342                         case 0: l =((unsigned long)(*((c)++)))<<24;     \
343                         case 1: l|=((unsigned long)(*((c)++)))<<16;     \
344                         case 2: l|=((unsigned long)(*((c)++)))<< 8;     \
345                         case 3: l|=((unsigned long)(*((c)++)));         \
346                                 } }
347 #define HOST_p_c2l_p(c,l,sc,len) {                                      \
348                         switch (sc) {                                   \
349                         case 0: l =((unsigned long)(*((c)++)))<<24;     \
350                                 if (--len == 0) break;                  \
351                         case 1: l|=((unsigned long)(*((c)++)))<<16;     \
352                                 if (--len == 0) break;                  \
353                         case 2: l|=((unsigned long)(*((c)++)))<< 8;     \
354                                 } }
355 /* NOTE the pointer is not incremented at the end of this */
356 #define HOST_c2l_p(c,l,n)       {                                       \
357                         l=0; (c)+=n;                                    \
358                         switch (n) {                                    \
359                         case 3: l =((unsigned long)(*(--(c))))<< 8;     \
360                         case 2: l|=((unsigned long)(*(--(c))))<<16;     \
361                         case 1: l|=((unsigned long)(*(--(c))))<<24;     \
362                                 } }
363 #define HOST_l2c(l,c)   (*((c)++)=(unsigned char)(((l)>>24)&0xff),      \
364                          *((c)++)=(unsigned char)(((l)>>16)&0xff),      \
365                          *((c)++)=(unsigned char)(((l)>> 8)&0xff),      \
366                          *((c)++)=(unsigned char)(((l)    )&0xff),      \
367                          l)
368
369 #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
370
371 #define HOST_c2l(c,l)   (l =(((unsigned long)(*((c)++)))    ),          \
372                          l|=(((unsigned long)(*((c)++)))<< 8),          \
373                          l|=(((unsigned long)(*((c)++)))<<16),          \
374                          l|=(((unsigned long)(*((c)++)))<<24),          \
375                          l)
376 #define HOST_p_c2l(c,l,n)       {                                       \
377                         switch (n) {                                    \
378                         case 0: l =((unsigned long)(*((c)++)));         \
379                         case 1: l|=((unsigned long)(*((c)++)))<< 8;     \
380                         case 2: l|=((unsigned long)(*((c)++)))<<16;     \
381                         case 3: l|=((unsigned long)(*((c)++)))<<24;     \
382                                 } }
383 #define HOST_p_c2l_p(c,l,sc,len) {                                      \
384                         switch (sc) {                                   \
385                         case 0: l =((unsigned long)(*((c)++)));         \
386                                 if (--len == 0) break;                  \
387                         case 1: l|=((unsigned long)(*((c)++)))<< 8;     \
388                                 if (--len == 0) break;                  \
389                         case 2: l|=((unsigned long)(*((c)++)))<<16;     \
390                                 } }
391 /* NOTE the pointer is not incremented at the end of this */
392 #define HOST_c2l_p(c,l,n)       {                                       \
393                         l=0; (c)+=n;                                    \
394                         switch (n) {                                    \
395                         case 3: l =((unsigned long)(*(--(c))))<<16;     \
396                         case 2: l|=((unsigned long)(*(--(c))))<< 8;     \
397                         case 1: l|=((unsigned long)(*(--(c))));         \
398                                 } }
399 #define HOST_l2c(l,c)   (*((c)++)=(unsigned char)(((l)    )&0xff),      \
400                          *((c)++)=(unsigned char)(((l)>> 8)&0xff),      \
401                          *((c)++)=(unsigned char)(((l)>>16)&0xff),      \
402                          *((c)++)=(unsigned char)(((l)>>24)&0xff),      \
403                          l)
404
405 #endif
406
407 /*
408  * Time for some action:-)
409  */
410
411 void HASH_UPDATE (HASH_CTX *c, const unsigned char *data, unsigned long len)
412         {
413         register HASH_LONG * p;
414         register unsigned long l;
415         int sw,sc,ew,ec;
416
417         if (len==0) return;
418
419         l=(c->Nl+(len<<3))&0xffffffffL;
420         /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
421          * Wei Dai <weidai@eskimo.com> for pointing it out. */
422         if (l < c->Nl) /* overflow */
423                 c->Nh++;
424         c->Nh+=(len>>29);
425         c->Nl=l;
426
427         if (c->num != 0)
428                 {
429                 p=c->data;
430                 sw=c->num>>2;
431                 sc=c->num&0x03;
432
433                 if ((c->num+len) >= HASH_CBLOCK)
434                         {
435                         l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
436                         for (; sw<HASH_LBLOCK; sw++)
437                                 {
438                                 HOST_c2l(data,l); p[sw]=l;
439                                 }
440                         HASH_BLOCK_HOST_ORDER (c,p,1);
441                         len-=(HASH_CBLOCK-c->num);
442                         c->num=0;
443                         /* drop through and do the rest */
444                         }
445                 else
446                         {
447                         c->num+=len;
448                         if ((sc+len) < 4) /* ugly, add char's to a word */
449                                 {
450                                 l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l;
451                                 }
452                         else
453                                 {
454                                 ew=(c->num>>2);
455                                 ec=(c->num&0x03);
456                                 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
457                                 for (; sw < ew; sw++)
458                                         {
459                                         HOST_c2l(data,l); p[sw]=l;
460                                         }
461                                 if (ec)
462                                         {
463                                         HOST_c2l_p(data,l,ec); p[sw]=l;
464                                         }
465                                 }
466                         return;
467                         }
468                 }
469
470         sw=len/HASH_CBLOCK;
471         if (sw > 0)
472                 {
473 #if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
474                 /*
475                  * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined
476                  * only if sizeof(HASH_LONG)==4.
477                  */
478                 if ((((unsigned long)data)%4) == 0)
479                         {
480                         /* data is properly aligned so that we can cast it: */
481                         HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,sw);
482                         sw*=HASH_CBLOCK;
483                         data+=sw;
484                         len-=sw;
485                         }
486                 else
487 #if !defined(HASH_BLOCK_DATA_ORDER)
488                         while (sw--)
489                                 {
490                                 memcpy (p=c->data,data,HASH_CBLOCK);
491                                 HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1);
492                                 data+=HASH_CBLOCK;
493                                 len-=HASH_CBLOCK;
494                                 }
495 #endif
496 #endif
497 #if defined(HASH_BLOCK_DATA_ORDER)
498                         {
499                         HASH_BLOCK_DATA_ORDER(c,data,sw);
500                         sw*=HASH_CBLOCK;
501                         data+=sw;
502                         len-=sw;
503                         }
504 #endif
505                 }
506
507         if (len!=0)
508                 {
509                 p = c->data;
510                 c->num = len;
511                 ew=len>>2;      /* words to copy */
512                 ec=len&0x03;
513                 for (; ew; ew--,p++)
514                         {
515                         HOST_c2l(data,l); *p=l;
516                         }
517                 HOST_c2l_p(data,l,ec);
518                 *p=l;
519                 }
520         }
521
522
523 void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
524         {
525 #if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
526         if ((((unsigned long)data)%4) == 0)
527                 /* data is properly aligned so that we can cast it: */
528                 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,1);
529         else
530 #if !defined(HASH_BLOCK_DATA_ORDER)
531                 {
532                 memcpy (c->data,data,HASH_CBLOCK);
533                 HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1);
534                 }
535 #endif
536 #endif
537 #if defined(HASH_BLOCK_DATA_ORDER)
538         HASH_BLOCK_DATA_ORDER (c,data,1);
539 #endif
540         }
541
542
543 void HASH_FINAL (unsigned char *md, HASH_CTX *c)
544         {
545         register HASH_LONG *p;
546         register unsigned long l;
547         register int i,j;
548         static const unsigned char end[4]={0x80,0x00,0x00,0x00};
549         const unsigned char *cp=end;
550
551         /* c->num should definitly have room for at least one more byte. */
552         p=c->data;
553         i=c->num>>2;
554         j=c->num&0x03;
555
556 #if 0
557         /* purify often complains about the following line as an
558          * Uninitialized Memory Read.  While this can be true, the
559          * following p_c2l macro will reset l when that case is true.
560          * This is because j&0x03 contains the number of 'valid' bytes
561          * already in p[i].  If and only if j&0x03 == 0, the UMR will
562          * occur but this is also the only time p_c2l will do
563          * l= *(cp++) instead of l|= *(cp++)
564          * Many thanks to Alex Tang <altitude@cic.net> for pickup this
565          * 'potential bug' */
566 #ifdef PURIFY
567         if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */
568 #endif
569         l=p[i];
570 #else
571         l = (j==0) ? 0 : p[i];
572 #endif
573         HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */
574
575         if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */
576                 {
577                 if (i<HASH_LBLOCK) p[i]=0;
578                 HASH_BLOCK_HOST_ORDER (c,p,1);
579                 i=0;
580                 }
581         for (; i<(HASH_LBLOCK-2); i++)
582                 p[i]=0;
583
584 #if   defined(DATA_ORDER_IS_BIG_ENDIAN)
585         p[HASH_LBLOCK-2]=c->Nh;
586         p[HASH_LBLOCK-1]=c->Nl;
587 #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
588         p[HASH_LBLOCK-2]=c->Nl;
589         p[HASH_LBLOCK-1]=c->Nh;
590 #endif
591         HASH_BLOCK_HOST_ORDER (c,p,1);
592
593 #ifndef HASH_MAKE_STRING
594 #error "HASH_MAKE_STRING must be defined!"
595 #else
596         HASH_MAKE_STRING(c,md);
597 #endif
598
599         c->num=0;
600         /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack
601          * but I'm not worried :-)
602         memset((void *)c,0,sizeof(HASH_CTX));
603          */
604         }