3 /* crypto/md/md5_locl.h */
4 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
7 * This package is an SSL implementation written
8 * by Eric Young (eay@cryptsoft.com).
9 * The implementation was written so as to conform with Netscapes SSL.
11 * This library is free for commercial and non-commercial use as long as
12 * the following conditions are aheared to. The following conditions
13 * apply to all code found in this distribution, be it the RC4, RSA,
14 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
15 * included with this distribution is covered by the same copyright terms
16 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
18 * Copyright remains Eric Young's, and as such any Copyright notices in
19 * the code are not to be removed.
20 * If this package is used in a product, Eric Young should be given attribution
21 * as the author of the parts of the library used.
22 * This can be in the form of a textual message at program startup or
23 * in documentation (online or textual) provided with the package.
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
28 * 1. Redistributions of source code must retain the copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 * 3. All advertising materials mentioning features or use of this software
34 * must display the following acknowledgement:
35 * "This product includes cryptographic software written by
36 * Eric Young (eay@cryptsoft.com)"
37 * The word 'cryptographic' can be left out if the rouines from the library
38 * being used are not cryptographic related :-).
39 * 4. If you include any Windows specific code (or a derivative thereof) from
40 * the apps directory (application code) you must include an acknowledgement:
41 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
43 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * The licence and distribution terms for any publically available version or
56 * derivative of this code cannot be changed. i.e. this code cannot simply be
57 * copied and put under another distribution licence
58 * [including the GNU Public Licence.]
65 #define ULONG unsigned long
66 #define UCHAR unsigned char
67 #define UINT unsigned int
74 #define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \
75 l|=(((unsigned long)(*((c)++)))<< 8), \
76 l|=(((unsigned long)(*((c)++)))<<16), \
77 l|=(((unsigned long)(*((c)++)))<<24))
80 #define p_c2l(c,l,n) { \
82 case 0: l =((unsigned long)(*((c)++))); \
83 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
84 case 2: l|=((unsigned long)(*((c)++)))<<16; \
85 case 3: l|=((unsigned long)(*((c)++)))<<24; \
89 /* NOTE the pointer is not incremented at the end of this */
91 #define c2l_p(c,l,n) { \
95 case 3: l =((unsigned long)(*(--(c))))<<16; \
96 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
97 case 1: l|=((unsigned long)(*(--(c)))) ; \
102 #define p_c2l_p(c,l,sc,len) { \
105 case 0: l =((unsigned long)(*((c)++))); \
106 if (--len == 0U) break; \
107 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
108 if (--len == 0U) break; \
109 case 2: l|=((unsigned long)(*((c)++)))<<16; \
114 #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
115 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
116 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
117 *((c)++)=(unsigned char)(((l)>>24)&0xff))
119 /* NOTE - c is not incremented as per l2c */
121 #define l2cn(l1,l2,c,n) { \
124 case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
125 case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
126 case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
127 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
128 case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
129 case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
130 case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
131 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
135 /* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
137 /* 5 instructions with rotate instruction, else 9 */
138 #define Endian_Reverse32(a) \
140 unsigned long l=(a); \
141 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \
144 /* 6 instructions with rotate instruction, else 8 */
145 #define Endian_Reverse32(a) \
147 unsigned long l=(a); \
148 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \
154 #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
155 #define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
158 /* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
159 * simplified to the code below. Wei attributes these optimisations
160 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
162 #define F(x,y,z) ((((y) ^ (z)) & (x)) ^ (z))
163 #define G(x,y,z) ((((x) ^ (y)) & (z)) ^ (y))
164 #define H(x,y,z) ((x) ^ (y) ^ (z))
165 #define I(x,y,z) (((x) | (~(z))) ^ (y))
169 #define ROTATE(a,n) _lrotl(a,n)
171 #define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
175 #define R0(a,b,c,d,k,s,t) { \
176 a+=((k)+(t)+F((b),(c),(d))); \
180 #define R1(a,b,c,d,k,s,t) { \
181 a+=((k)+(t)+G((b),(c),(d))); \
185 #define R2(a,b,c,d,k,s,t) { \
186 a+=((k)+(t)+H((b),(c),(d))); \
190 #define R3(a,b,c,d,k,s,t) { \
191 a+=((k)+(t)+I((b),(c),(d))); \