xref: /haiku/src/libs/compat/freebsd_iflib/md5c.c (revision 83c8026372f488c72c263927e98ccbcf34538cd9)
1*83c80263SAugustin Cavalier /*-
2*83c80263SAugustin Cavalier  * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
3*83c80263SAugustin Cavalier  *
4*83c80263SAugustin Cavalier  * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
5*83c80263SAugustin Cavalier  * rights reserved.
6*83c80263SAugustin Cavalier  *
7*83c80263SAugustin Cavalier  * License to copy and use this software is granted provided that it
8*83c80263SAugustin Cavalier  * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
9*83c80263SAugustin Cavalier  * Algorithm" in all material mentioning or referencing this software
10*83c80263SAugustin Cavalier  * or this function.
11*83c80263SAugustin Cavalier  *
12*83c80263SAugustin Cavalier  * License is also granted to make and use derivative works provided
13*83c80263SAugustin Cavalier  * that such works are identified as "derived from the RSA Data
14*83c80263SAugustin Cavalier  * Security, Inc. MD5 Message-Digest Algorithm" in all material
15*83c80263SAugustin Cavalier  * mentioning or referencing the derived work.
16*83c80263SAugustin Cavalier  *
17*83c80263SAugustin Cavalier  * RSA Data Security, Inc. makes no representations concerning either
18*83c80263SAugustin Cavalier  * the merchantability of this software or the suitability of this
19*83c80263SAugustin Cavalier  * software for any particular purpose. It is provided "as is"
20*83c80263SAugustin Cavalier  * without express or implied warranty of any kind.
21*83c80263SAugustin Cavalier  *
22*83c80263SAugustin Cavalier  * These notices must be retained in any copies of any part of this
23*83c80263SAugustin Cavalier  * documentation and/or software.
24*83c80263SAugustin Cavalier  *
25*83c80263SAugustin Cavalier  * This code is the same as the code published by RSA Inc.  It has been
26*83c80263SAugustin Cavalier  * edited for clarity and style only.
27*83c80263SAugustin Cavalier  */
28*83c80263SAugustin Cavalier 
29*83c80263SAugustin Cavalier /*
30*83c80263SAugustin Cavalier  * This file should be kept in sync with src/lib/libmd/md5c.c
31*83c80263SAugustin Cavalier  */
32*83c80263SAugustin Cavalier #include <sys/cdefs.h>
33*83c80263SAugustin Cavalier __FBSDID("$FreeBSD$");
34*83c80263SAugustin Cavalier 
35*83c80263SAugustin Cavalier #include <sys/types.h>
36*83c80263SAugustin Cavalier 
37*83c80263SAugustin Cavalier #ifdef _KERNEL
38*83c80263SAugustin Cavalier #include <sys/systm.h>
39*83c80263SAugustin Cavalier #else
40*83c80263SAugustin Cavalier #include <string.h>
41*83c80263SAugustin Cavalier #endif
42*83c80263SAugustin Cavalier 
43*83c80263SAugustin Cavalier #include <machine/endian.h>
44*83c80263SAugustin Cavalier #include <sys/endian.h>
45*83c80263SAugustin Cavalier #include <sys/md5.h>
46*83c80263SAugustin Cavalier 
47*83c80263SAugustin Cavalier static void MD5Transform(u_int32_t [4], const unsigned char [64]);
48*83c80263SAugustin Cavalier 
49*83c80263SAugustin Cavalier #if (BYTE_ORDER == LITTLE_ENDIAN)
50*83c80263SAugustin Cavalier #define Encode memcpy
51*83c80263SAugustin Cavalier #define Decode memcpy
52*83c80263SAugustin Cavalier #else
53*83c80263SAugustin Cavalier 
54*83c80263SAugustin Cavalier /*
55*83c80263SAugustin Cavalier  * Encodes input (u_int32_t) into output (unsigned char). Assumes len is
56*83c80263SAugustin Cavalier  * a multiple of 4.
57*83c80263SAugustin Cavalier  */
58*83c80263SAugustin Cavalier 
59*83c80263SAugustin Cavalier static void
Encode(unsigned char * output,u_int32_t * input,unsigned int len)60*83c80263SAugustin Cavalier Encode (unsigned char *output, u_int32_t *input, unsigned int len)
61*83c80263SAugustin Cavalier {
62*83c80263SAugustin Cavalier 	unsigned int i;
63*83c80263SAugustin Cavalier 	uint32_t ip;
64*83c80263SAugustin Cavalier 
65*83c80263SAugustin Cavalier 	for (i = 0; i < len / 4; i++) {
66*83c80263SAugustin Cavalier 		ip = input[i];
67*83c80263SAugustin Cavalier 		*output++ = ip;
68*83c80263SAugustin Cavalier 		*output++ = ip >> 8;
69*83c80263SAugustin Cavalier 		*output++ = ip >> 16;
70*83c80263SAugustin Cavalier 		*output++ = ip >> 24;
71*83c80263SAugustin Cavalier 	}
72*83c80263SAugustin Cavalier }
73*83c80263SAugustin Cavalier 
74*83c80263SAugustin Cavalier /*
75*83c80263SAugustin Cavalier  * Decodes input (unsigned char) into output (u_int32_t). Assumes len is
76*83c80263SAugustin Cavalier  * a multiple of 4.
77*83c80263SAugustin Cavalier  */
78*83c80263SAugustin Cavalier 
79*83c80263SAugustin Cavalier static void
Decode(u_int32_t * output,const unsigned char * input,unsigned int len)80*83c80263SAugustin Cavalier Decode (u_int32_t *output, const unsigned char *input, unsigned int len)
81*83c80263SAugustin Cavalier {
82*83c80263SAugustin Cavalier 	unsigned int i;
83*83c80263SAugustin Cavalier 
84*83c80263SAugustin Cavalier 	for (i = 0; i < len; i += 4) {
85*83c80263SAugustin Cavalier 		*output++ = input[i] | (input[i+1] << 8) | (input[i+2] << 16) |
86*83c80263SAugustin Cavalier 		    (input[i+3] << 24);
87*83c80263SAugustin Cavalier 	}
88*83c80263SAugustin Cavalier }
89*83c80263SAugustin Cavalier #endif
90*83c80263SAugustin Cavalier 
91*83c80263SAugustin Cavalier static unsigned char PADDING[64] = {
92*83c80263SAugustin Cavalier   0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93*83c80263SAugustin Cavalier   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94*83c80263SAugustin Cavalier   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
95*83c80263SAugustin Cavalier };
96*83c80263SAugustin Cavalier 
97*83c80263SAugustin Cavalier /* F, G, H and I are basic MD5 functions. */
98*83c80263SAugustin Cavalier #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
99*83c80263SAugustin Cavalier #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
100*83c80263SAugustin Cavalier #define H(x, y, z) ((x) ^ (y) ^ (z))
101*83c80263SAugustin Cavalier #define I(x, y, z) ((y) ^ ((x) | (~z)))
102*83c80263SAugustin Cavalier 
103*83c80263SAugustin Cavalier /* ROTATE_LEFT rotates x left n bits. */
104*83c80263SAugustin Cavalier #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
105*83c80263SAugustin Cavalier 
106*83c80263SAugustin Cavalier /*
107*83c80263SAugustin Cavalier  * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
108*83c80263SAugustin Cavalier  * Rotation is separate from addition to prevent recomputation.
109*83c80263SAugustin Cavalier  */
110*83c80263SAugustin Cavalier #define FF(a, b, c, d, x, s, ac) { \
111*83c80263SAugustin Cavalier 	(a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
112*83c80263SAugustin Cavalier 	(a) = ROTATE_LEFT ((a), (s)); \
113*83c80263SAugustin Cavalier 	(a) += (b); \
114*83c80263SAugustin Cavalier 	}
115*83c80263SAugustin Cavalier #define GG(a, b, c, d, x, s, ac) { \
116*83c80263SAugustin Cavalier 	(a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
117*83c80263SAugustin Cavalier 	(a) = ROTATE_LEFT ((a), (s)); \
118*83c80263SAugustin Cavalier 	(a) += (b); \
119*83c80263SAugustin Cavalier 	}
120*83c80263SAugustin Cavalier #define HH(a, b, c, d, x, s, ac) { \
121*83c80263SAugustin Cavalier 	(a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
122*83c80263SAugustin Cavalier 	(a) = ROTATE_LEFT ((a), (s)); \
123*83c80263SAugustin Cavalier 	(a) += (b); \
124*83c80263SAugustin Cavalier 	}
125*83c80263SAugustin Cavalier #define II(a, b, c, d, x, s, ac) { \
126*83c80263SAugustin Cavalier 	(a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
127*83c80263SAugustin Cavalier 	(a) = ROTATE_LEFT ((a), (s)); \
128*83c80263SAugustin Cavalier 	(a) += (b); \
129*83c80263SAugustin Cavalier 	}
130*83c80263SAugustin Cavalier 
131*83c80263SAugustin Cavalier /* MD5 initialization. Begins an MD5 operation, writing a new context. */
132*83c80263SAugustin Cavalier 
133*83c80263SAugustin Cavalier void
MD5Init(context)134*83c80263SAugustin Cavalier MD5Init (context)
135*83c80263SAugustin Cavalier 	MD5_CTX *context;
136*83c80263SAugustin Cavalier {
137*83c80263SAugustin Cavalier 
138*83c80263SAugustin Cavalier 	context->count[0] = context->count[1] = 0;
139*83c80263SAugustin Cavalier 
140*83c80263SAugustin Cavalier 	/* Load magic initialization constants.  */
141*83c80263SAugustin Cavalier 	context->state[0] = 0x67452301;
142*83c80263SAugustin Cavalier 	context->state[1] = 0xefcdab89;
143*83c80263SAugustin Cavalier 	context->state[2] = 0x98badcfe;
144*83c80263SAugustin Cavalier 	context->state[3] = 0x10325476;
145*83c80263SAugustin Cavalier }
146*83c80263SAugustin Cavalier 
147*83c80263SAugustin Cavalier /*
148*83c80263SAugustin Cavalier  * MD5 block update operation. Continues an MD5 message-digest
149*83c80263SAugustin Cavalier  * operation, processing another message block, and updating the
150*83c80263SAugustin Cavalier  * context.
151*83c80263SAugustin Cavalier  */
152*83c80263SAugustin Cavalier 
153*83c80263SAugustin Cavalier void
MD5Update(context,in,inputLen)154*83c80263SAugustin Cavalier MD5Update (context, in, inputLen)
155*83c80263SAugustin Cavalier 	MD5_CTX *context;
156*83c80263SAugustin Cavalier 	const void *in;
157*83c80263SAugustin Cavalier 	unsigned int inputLen;
158*83c80263SAugustin Cavalier {
159*83c80263SAugustin Cavalier 	unsigned int i, index, partLen;
160*83c80263SAugustin Cavalier 	const unsigned char *input = in;
161*83c80263SAugustin Cavalier 
162*83c80263SAugustin Cavalier 	/* Compute number of bytes mod 64 */
163*83c80263SAugustin Cavalier 	index = (unsigned int)((context->count[0] >> 3) & 0x3F);
164*83c80263SAugustin Cavalier 
165*83c80263SAugustin Cavalier 	/* Update number of bits */
166*83c80263SAugustin Cavalier 	if ((context->count[0] += ((u_int32_t)inputLen << 3))
167*83c80263SAugustin Cavalier 	    < ((u_int32_t)inputLen << 3))
168*83c80263SAugustin Cavalier 		context->count[1]++;
169*83c80263SAugustin Cavalier 	context->count[1] += ((u_int32_t)inputLen >> 29);
170*83c80263SAugustin Cavalier 
171*83c80263SAugustin Cavalier 	partLen = 64 - index;
172*83c80263SAugustin Cavalier 
173*83c80263SAugustin Cavalier 	/* Transform as many times as possible. */
174*83c80263SAugustin Cavalier 	if (inputLen >= partLen) {
175*83c80263SAugustin Cavalier 		memcpy((void *)&context->buffer[index], (const void *)input,
176*83c80263SAugustin Cavalier 		    partLen);
177*83c80263SAugustin Cavalier 		MD5Transform (context->state, context->buffer);
178*83c80263SAugustin Cavalier 
179*83c80263SAugustin Cavalier 		for (i = partLen; i + 63 < inputLen; i += 64)
180*83c80263SAugustin Cavalier 			MD5Transform (context->state, &input[i]);
181*83c80263SAugustin Cavalier 
182*83c80263SAugustin Cavalier 		index = 0;
183*83c80263SAugustin Cavalier 	}
184*83c80263SAugustin Cavalier 	else
185*83c80263SAugustin Cavalier 		i = 0;
186*83c80263SAugustin Cavalier 
187*83c80263SAugustin Cavalier 	/* Buffer remaining input */
188*83c80263SAugustin Cavalier 	memcpy ((void *)&context->buffer[index], (const void *)&input[i],
189*83c80263SAugustin Cavalier 	    inputLen-i);
190*83c80263SAugustin Cavalier }
191*83c80263SAugustin Cavalier 
192*83c80263SAugustin Cavalier /*
193*83c80263SAugustin Cavalier  * MD5 padding. Adds padding followed by original length.
194*83c80263SAugustin Cavalier  */
195*83c80263SAugustin Cavalier 
196*83c80263SAugustin Cavalier static void
MD5Pad(MD5_CTX * context)197*83c80263SAugustin Cavalier MD5Pad (MD5_CTX *context)
198*83c80263SAugustin Cavalier {
199*83c80263SAugustin Cavalier 	unsigned char bits[8];
200*83c80263SAugustin Cavalier 	unsigned int index, padLen;
201*83c80263SAugustin Cavalier 
202*83c80263SAugustin Cavalier 	/* Save number of bits */
203*83c80263SAugustin Cavalier 	Encode (bits, context->count, 8);
204*83c80263SAugustin Cavalier 
205*83c80263SAugustin Cavalier 	/* Pad out to 56 mod 64. */
206*83c80263SAugustin Cavalier 	index = (unsigned int)((context->count[0] >> 3) & 0x3f);
207*83c80263SAugustin Cavalier 	padLen = (index < 56) ? (56 - index) : (120 - index);
208*83c80263SAugustin Cavalier 	MD5Update (context, PADDING, padLen);
209*83c80263SAugustin Cavalier 
210*83c80263SAugustin Cavalier 	/* Append length (before padding) */
211*83c80263SAugustin Cavalier 	MD5Update (context, bits, 8);
212*83c80263SAugustin Cavalier }
213*83c80263SAugustin Cavalier 
214*83c80263SAugustin Cavalier /*
215*83c80263SAugustin Cavalier  * MD5 finalization. Ends an MD5 message-digest operation, writing the
216*83c80263SAugustin Cavalier  * the message digest and zeroizing the context.
217*83c80263SAugustin Cavalier  */
218*83c80263SAugustin Cavalier 
219*83c80263SAugustin Cavalier void
MD5Final(unsigned char digest[MD5_DIGEST_LENGTH],MD5_CTX * context)220*83c80263SAugustin Cavalier MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
221*83c80263SAugustin Cavalier {
222*83c80263SAugustin Cavalier 	/* Do padding. */
223*83c80263SAugustin Cavalier 	MD5Pad (context);
224*83c80263SAugustin Cavalier 
225*83c80263SAugustin Cavalier 	/* Store state in digest */
226*83c80263SAugustin Cavalier 	Encode (digest, context->state, MD5_DIGEST_LENGTH);
227*83c80263SAugustin Cavalier 
228*83c80263SAugustin Cavalier 	/* Zeroize sensitive information. */
229*83c80263SAugustin Cavalier 	memset (context, 0, sizeof (*context));
230*83c80263SAugustin Cavalier }
231*83c80263SAugustin Cavalier 
232*83c80263SAugustin Cavalier /* MD5 basic transformation. Transforms state based on block. */
233*83c80263SAugustin Cavalier 
234*83c80263SAugustin Cavalier static void
MD5Transform(state,block)235*83c80263SAugustin Cavalier MD5Transform (state, block)
236*83c80263SAugustin Cavalier 	u_int32_t state[4];
237*83c80263SAugustin Cavalier 	const unsigned char block[64];
238*83c80263SAugustin Cavalier {
239*83c80263SAugustin Cavalier 	u_int32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
240*83c80263SAugustin Cavalier 
241*83c80263SAugustin Cavalier 	Decode (x, block, 64);
242*83c80263SAugustin Cavalier 
243*83c80263SAugustin Cavalier 	/* Round 1 */
244*83c80263SAugustin Cavalier #define S11 7
245*83c80263SAugustin Cavalier #define S12 12
246*83c80263SAugustin Cavalier #define S13 17
247*83c80263SAugustin Cavalier #define S14 22
248*83c80263SAugustin Cavalier 	FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
249*83c80263SAugustin Cavalier 	FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
250*83c80263SAugustin Cavalier 	FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
251*83c80263SAugustin Cavalier 	FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
252*83c80263SAugustin Cavalier 	FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
253*83c80263SAugustin Cavalier 	FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
254*83c80263SAugustin Cavalier 	FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
255*83c80263SAugustin Cavalier 	FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
256*83c80263SAugustin Cavalier 	FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
257*83c80263SAugustin Cavalier 	FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
258*83c80263SAugustin Cavalier 	FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
259*83c80263SAugustin Cavalier 	FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
260*83c80263SAugustin Cavalier 	FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
261*83c80263SAugustin Cavalier 	FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
262*83c80263SAugustin Cavalier 	FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
263*83c80263SAugustin Cavalier 	FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
264*83c80263SAugustin Cavalier 
265*83c80263SAugustin Cavalier 	/* Round 2 */
266*83c80263SAugustin Cavalier #define S21 5
267*83c80263SAugustin Cavalier #define S22 9
268*83c80263SAugustin Cavalier #define S23 14
269*83c80263SAugustin Cavalier #define S24 20
270*83c80263SAugustin Cavalier 	GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
271*83c80263SAugustin Cavalier 	GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
272*83c80263SAugustin Cavalier 	GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
273*83c80263SAugustin Cavalier 	GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
274*83c80263SAugustin Cavalier 	GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
275*83c80263SAugustin Cavalier 	GG (d, a, b, c, x[10], S22,  0x2441453); /* 22 */
276*83c80263SAugustin Cavalier 	GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
277*83c80263SAugustin Cavalier 	GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
278*83c80263SAugustin Cavalier 	GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
279*83c80263SAugustin Cavalier 	GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
280*83c80263SAugustin Cavalier 	GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
281*83c80263SAugustin Cavalier 	GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
282*83c80263SAugustin Cavalier 	GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
283*83c80263SAugustin Cavalier 	GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
284*83c80263SAugustin Cavalier 	GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
285*83c80263SAugustin Cavalier 	GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
286*83c80263SAugustin Cavalier 
287*83c80263SAugustin Cavalier 	/* Round 3 */
288*83c80263SAugustin Cavalier #define S31 4
289*83c80263SAugustin Cavalier #define S32 11
290*83c80263SAugustin Cavalier #define S33 16
291*83c80263SAugustin Cavalier #define S34 23
292*83c80263SAugustin Cavalier 	HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
293*83c80263SAugustin Cavalier 	HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
294*83c80263SAugustin Cavalier 	HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
295*83c80263SAugustin Cavalier 	HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
296*83c80263SAugustin Cavalier 	HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
297*83c80263SAugustin Cavalier 	HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
298*83c80263SAugustin Cavalier 	HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
299*83c80263SAugustin Cavalier 	HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
300*83c80263SAugustin Cavalier 	HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
301*83c80263SAugustin Cavalier 	HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
302*83c80263SAugustin Cavalier 	HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
303*83c80263SAugustin Cavalier 	HH (b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
304*83c80263SAugustin Cavalier 	HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
305*83c80263SAugustin Cavalier 	HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
306*83c80263SAugustin Cavalier 	HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
307*83c80263SAugustin Cavalier 	HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
308*83c80263SAugustin Cavalier 
309*83c80263SAugustin Cavalier 	/* Round 4 */
310*83c80263SAugustin Cavalier #define S41 6
311*83c80263SAugustin Cavalier #define S42 10
312*83c80263SAugustin Cavalier #define S43 15
313*83c80263SAugustin Cavalier #define S44 21
314*83c80263SAugustin Cavalier 	II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
315*83c80263SAugustin Cavalier 	II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
316*83c80263SAugustin Cavalier 	II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
317*83c80263SAugustin Cavalier 	II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
318*83c80263SAugustin Cavalier 	II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
319*83c80263SAugustin Cavalier 	II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
320*83c80263SAugustin Cavalier 	II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
321*83c80263SAugustin Cavalier 	II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
322*83c80263SAugustin Cavalier 	II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
323*83c80263SAugustin Cavalier 	II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
324*83c80263SAugustin Cavalier 	II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
325*83c80263SAugustin Cavalier 	II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
326*83c80263SAugustin Cavalier 	II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
327*83c80263SAugustin Cavalier 	II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
328*83c80263SAugustin Cavalier 	II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
329*83c80263SAugustin Cavalier 	II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
330*83c80263SAugustin Cavalier 
331*83c80263SAugustin Cavalier 	state[0] += a;
332*83c80263SAugustin Cavalier 	state[1] += b;
333*83c80263SAugustin Cavalier 	state[2] += c;
334*83c80263SAugustin Cavalier 	state[3] += d;
335*83c80263SAugustin Cavalier 
336*83c80263SAugustin Cavalier 	/* Zeroize sensitive information. */
337*83c80263SAugustin Cavalier 	memset ((void *)x, 0, sizeof (x));
338*83c80263SAugustin Cavalier }
339