1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert * Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.
4*7f2fe78bSCy Schubert *
5*7f2fe78bSCy Schubert * License to copy and use this software is granted provided that
6*7f2fe78bSCy Schubert * it is identified as the "RSA Data Security, Inc. MD5 Message-
7*7f2fe78bSCy Schubert * Digest Algorithm" in all material mentioning or referencing this
8*7f2fe78bSCy Schubert * software or this function.
9*7f2fe78bSCy Schubert *
10*7f2fe78bSCy Schubert * License is also granted to make and use derivative works
11*7f2fe78bSCy Schubert * provided that such works are identified as "derived from the RSA
12*7f2fe78bSCy Schubert * Data Security, Inc. MD5 Message-Digest Algorithm" in all
13*7f2fe78bSCy Schubert * material mentioning or referencing the derived work.
14*7f2fe78bSCy Schubert *
15*7f2fe78bSCy Schubert * RSA Data Security, Inc. makes no representations concerning
16*7f2fe78bSCy Schubert * either the merchantability of this software or the suitability
17*7f2fe78bSCy Schubert * of this software for any particular purpose. It is provided "as
18*7f2fe78bSCy Schubert * is" without express or implied warranty of any kind.
19*7f2fe78bSCy Schubert *
20*7f2fe78bSCy Schubert * These notices must be retained in any copies of any part of this
21*7f2fe78bSCy Schubert * documentation and/or software.
22*7f2fe78bSCy Schubert */
23*7f2fe78bSCy Schubert
24*7f2fe78bSCy Schubert /*
25*7f2fe78bSCy Schubert ***********************************************************************
26*7f2fe78bSCy Schubert ** md5.c -- the source code for MD5 routines **
27*7f2fe78bSCy Schubert ** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
28*7f2fe78bSCy Schubert ** Created: 2/17/90 RLR **
29*7f2fe78bSCy Schubert ** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **
30*7f2fe78bSCy Schubert ***********************************************************************
31*7f2fe78bSCy Schubert */
32*7f2fe78bSCy Schubert
33*7f2fe78bSCy Schubert /*
34*7f2fe78bSCy Schubert * Modified by John Carr, MIT, to use Kerberos 5 typedefs.
35*7f2fe78bSCy Schubert */
36*7f2fe78bSCy Schubert
37*7f2fe78bSCy Schubert #include "crypto_int.h"
38*7f2fe78bSCy Schubert #include "rsa-md5.h"
39*7f2fe78bSCy Schubert
40*7f2fe78bSCy Schubert #ifdef K5_BUILTIN_MD5
41*7f2fe78bSCy Schubert
42*7f2fe78bSCy Schubert /*
43*7f2fe78bSCy Schubert ***********************************************************************
44*7f2fe78bSCy Schubert ** Message-digest routines: **
45*7f2fe78bSCy Schubert ** To form the message digest for a message M **
46*7f2fe78bSCy Schubert ** (1) Initialize a context buffer mdContext using krb5int_MD5Init **
47*7f2fe78bSCy Schubert ** (2) Call krb5int_MD5Update on mdContext and M **
48*7f2fe78bSCy Schubert ** (3) Call krb5int_MD5Final on mdContext **
49*7f2fe78bSCy Schubert ** The message digest is now in mdContext->digest[0...15] **
50*7f2fe78bSCy Schubert ***********************************************************************
51*7f2fe78bSCy Schubert */
52*7f2fe78bSCy Schubert
53*7f2fe78bSCy Schubert /* forward declaration */
54*7f2fe78bSCy Schubert static void Transform (krb5_ui_4 *buf, krb5_ui_4 *in);
55*7f2fe78bSCy Schubert
56*7f2fe78bSCy Schubert static const unsigned char PADDING[64] = {
57*7f2fe78bSCy Schubert 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58*7f2fe78bSCy Schubert 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59*7f2fe78bSCy Schubert 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60*7f2fe78bSCy Schubert 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61*7f2fe78bSCy Schubert 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62*7f2fe78bSCy Schubert 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63*7f2fe78bSCy Schubert 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64*7f2fe78bSCy Schubert 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
65*7f2fe78bSCy Schubert };
66*7f2fe78bSCy Schubert
67*7f2fe78bSCy Schubert /* F, G, H and I are basic MD5 functions */
68*7f2fe78bSCy Schubert #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
69*7f2fe78bSCy Schubert #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
70*7f2fe78bSCy Schubert #define H(x, y, z) ((x) ^ (y) ^ (z))
71*7f2fe78bSCy Schubert #define I(x, y, z) ((y) ^ ((x) | (~z)))
72*7f2fe78bSCy Schubert
73*7f2fe78bSCy Schubert /* ROTATE_LEFT rotates x left n bits */
74*7f2fe78bSCy Schubert #define ROTATE_LEFT(x, n) ((((x) << (n)) & 0xffffffff) | ((x) >> (32-(n))))
75*7f2fe78bSCy Schubert
76*7f2fe78bSCy Schubert /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
77*7f2fe78bSCy Schubert /* Rotation is separate from addition to prevent recomputation */
78*7f2fe78bSCy Schubert #define FF(a, b, c, d, x, s, ac) \
79*7f2fe78bSCy Schubert {(a) += F ((b), (c), (d)) + (x) + (krb5_ui_4)(ac); \
80*7f2fe78bSCy Schubert (a) &= 0xffffffff; \
81*7f2fe78bSCy Schubert (a) = ROTATE_LEFT ((a), (s)); \
82*7f2fe78bSCy Schubert (a) += (b); \
83*7f2fe78bSCy Schubert (a) &= 0xffffffff; \
84*7f2fe78bSCy Schubert }
85*7f2fe78bSCy Schubert #define GG(a, b, c, d, x, s, ac) \
86*7f2fe78bSCy Schubert {(a) += G ((b), (c), (d)) + (x) + (krb5_ui_4)(ac); \
87*7f2fe78bSCy Schubert (a) &= 0xffffffff; \
88*7f2fe78bSCy Schubert (a) = ROTATE_LEFT ((a), (s)); \
89*7f2fe78bSCy Schubert (a) += (b); \
90*7f2fe78bSCy Schubert (a) &= 0xffffffff; \
91*7f2fe78bSCy Schubert }
92*7f2fe78bSCy Schubert #define HH(a, b, c, d, x, s, ac) \
93*7f2fe78bSCy Schubert {(a) += H ((b), (c), (d)) + (x) + (krb5_ui_4)(ac); \
94*7f2fe78bSCy Schubert (a) &= 0xffffffff; \
95*7f2fe78bSCy Schubert (a) = ROTATE_LEFT ((a), (s)); \
96*7f2fe78bSCy Schubert (a) += (b); \
97*7f2fe78bSCy Schubert (a) &= 0xffffffff; \
98*7f2fe78bSCy Schubert }
99*7f2fe78bSCy Schubert #define II(a, b, c, d, x, s, ac) \
100*7f2fe78bSCy Schubert {(a) += I ((b), (c), (d)) + (x) + (krb5_ui_4)(ac); \
101*7f2fe78bSCy Schubert (a) &= 0xffffffff; \
102*7f2fe78bSCy Schubert (a) = ROTATE_LEFT ((a), (s)); \
103*7f2fe78bSCy Schubert (a) += (b); \
104*7f2fe78bSCy Schubert (a) &= 0xffffffff; \
105*7f2fe78bSCy Schubert }
106*7f2fe78bSCy Schubert
107*7f2fe78bSCy Schubert /* The routine krb5int_MD5Init initializes the message-digest context
108*7f2fe78bSCy Schubert mdContext. All fields are set to zero.
109*7f2fe78bSCy Schubert */
110*7f2fe78bSCy Schubert void
krb5int_MD5Init(krb5_MD5_CTX * mdContext)111*7f2fe78bSCy Schubert krb5int_MD5Init (krb5_MD5_CTX *mdContext)
112*7f2fe78bSCy Schubert {
113*7f2fe78bSCy Schubert mdContext->i[0] = mdContext->i[1] = (krb5_ui_4)0;
114*7f2fe78bSCy Schubert
115*7f2fe78bSCy Schubert /* Load magic initialization constants.
116*7f2fe78bSCy Schubert */
117*7f2fe78bSCy Schubert mdContext->buf[0] = 0x67452301UL;
118*7f2fe78bSCy Schubert mdContext->buf[1] = 0xefcdab89UL;
119*7f2fe78bSCy Schubert mdContext->buf[2] = 0x98badcfeUL;
120*7f2fe78bSCy Schubert mdContext->buf[3] = 0x10325476UL;
121*7f2fe78bSCy Schubert }
122*7f2fe78bSCy Schubert
123*7f2fe78bSCy Schubert /* The routine krb5int_MD5Update updates the message-digest context to
124*7f2fe78bSCy Schubert account for the presence of each of the characters inBuf[0..inLen-1]
125*7f2fe78bSCy Schubert in the message whose digest is being computed.
126*7f2fe78bSCy Schubert */
127*7f2fe78bSCy Schubert void
krb5int_MD5Update(krb5_MD5_CTX * mdContext,const unsigned char * inBuf,unsigned int inLen)128*7f2fe78bSCy Schubert krb5int_MD5Update (krb5_MD5_CTX *mdContext, const unsigned char *inBuf, unsigned int inLen)
129*7f2fe78bSCy Schubert {
130*7f2fe78bSCy Schubert krb5_ui_4 in[16];
131*7f2fe78bSCy Schubert int mdi;
132*7f2fe78bSCy Schubert unsigned int i, ii;
133*7f2fe78bSCy Schubert
134*7f2fe78bSCy Schubert /* compute number of bytes mod 64 */
135*7f2fe78bSCy Schubert mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
136*7f2fe78bSCy Schubert
137*7f2fe78bSCy Schubert /* update number of bits */
138*7f2fe78bSCy Schubert if ((mdContext->i[0] + ((krb5_ui_4)inLen << 3)) < mdContext->i[0])
139*7f2fe78bSCy Schubert mdContext->i[1]++;
140*7f2fe78bSCy Schubert mdContext->i[0] += ((krb5_ui_4)inLen << 3);
141*7f2fe78bSCy Schubert mdContext->i[1] += ((krb5_ui_4)inLen >> 29);
142*7f2fe78bSCy Schubert
143*7f2fe78bSCy Schubert while (inLen--) {
144*7f2fe78bSCy Schubert /* add new character to buffer, increment mdi */
145*7f2fe78bSCy Schubert mdContext->in[mdi++] = *inBuf++;
146*7f2fe78bSCy Schubert
147*7f2fe78bSCy Schubert /* transform if necessary */
148*7f2fe78bSCy Schubert if (mdi == 0x40) {
149*7f2fe78bSCy Schubert for (i = 0, ii = 0; i < 16; i++, ii += 4)
150*7f2fe78bSCy Schubert in[i] = load_32_le(mdContext->in+ii);
151*7f2fe78bSCy Schubert Transform (mdContext->buf, in);
152*7f2fe78bSCy Schubert mdi = 0;
153*7f2fe78bSCy Schubert }
154*7f2fe78bSCy Schubert }
155*7f2fe78bSCy Schubert }
156*7f2fe78bSCy Schubert
157*7f2fe78bSCy Schubert /* The routine krb5int_MD5Final terminates the message-digest computation and
158*7f2fe78bSCy Schubert ends with the desired message digest in mdContext->digest[0...15].
159*7f2fe78bSCy Schubert */
160*7f2fe78bSCy Schubert void
krb5int_MD5Final(krb5_MD5_CTX * mdContext)161*7f2fe78bSCy Schubert krb5int_MD5Final (krb5_MD5_CTX *mdContext)
162*7f2fe78bSCy Schubert {
163*7f2fe78bSCy Schubert krb5_ui_4 in[16];
164*7f2fe78bSCy Schubert int mdi;
165*7f2fe78bSCy Schubert unsigned int i, ii;
166*7f2fe78bSCy Schubert unsigned int padLen;
167*7f2fe78bSCy Schubert
168*7f2fe78bSCy Schubert /* save number of bits */
169*7f2fe78bSCy Schubert in[14] = mdContext->i[0];
170*7f2fe78bSCy Schubert in[15] = mdContext->i[1];
171*7f2fe78bSCy Schubert
172*7f2fe78bSCy Schubert /* compute number of bytes mod 64 */
173*7f2fe78bSCy Schubert mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
174*7f2fe78bSCy Schubert
175*7f2fe78bSCy Schubert /* pad out to 56 mod 64 */
176*7f2fe78bSCy Schubert padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
177*7f2fe78bSCy Schubert krb5int_MD5Update (mdContext, PADDING, padLen);
178*7f2fe78bSCy Schubert
179*7f2fe78bSCy Schubert /* append length in bits and transform */
180*7f2fe78bSCy Schubert for (i = 0, ii = 0; i < 14; i++, ii += 4)
181*7f2fe78bSCy Schubert in[i] = load_32_le(mdContext->in+ii);
182*7f2fe78bSCy Schubert Transform (mdContext->buf, in);
183*7f2fe78bSCy Schubert
184*7f2fe78bSCy Schubert /* store buffer in digest */
185*7f2fe78bSCy Schubert for (i = 0, ii = 0; i < 4; i++, ii += 4) {
186*7f2fe78bSCy Schubert store_32_le(mdContext->buf[i], mdContext->digest+ii);
187*7f2fe78bSCy Schubert }
188*7f2fe78bSCy Schubert }
189*7f2fe78bSCy Schubert
190*7f2fe78bSCy Schubert /* Basic MD5 step. Transforms buf based on in.
191*7f2fe78bSCy Schubert */
Transform(krb5_ui_4 * buf,krb5_ui_4 * in)192*7f2fe78bSCy Schubert static void Transform (krb5_ui_4 *buf, krb5_ui_4 *in)
193*7f2fe78bSCy Schubert {
194*7f2fe78bSCy Schubert krb5_ui_4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
195*7f2fe78bSCy Schubert
196*7f2fe78bSCy Schubert #if defined(CONFIG_SMALL) && !defined(CONFIG_SMALL_NO_CRYPTO)
197*7f2fe78bSCy Schubert
198*7f2fe78bSCy Schubert int i;
199*7f2fe78bSCy Schubert #define ROTATE { krb5_ui_4 temp; temp = d, d = c, c = b, b = a, a = temp; }
200*7f2fe78bSCy Schubert for (i = 0; i < 16; i++) {
201*7f2fe78bSCy Schubert const unsigned char round1s[] = { 7, 12, 17, 22 };
202*7f2fe78bSCy Schubert const krb5_ui_4 round1consts[] = {
203*7f2fe78bSCy Schubert 3614090360UL, 3905402710UL, 606105819UL, 3250441966UL,
204*7f2fe78bSCy Schubert 4118548399UL, 1200080426UL, 2821735955UL, 4249261313UL,
205*7f2fe78bSCy Schubert 1770035416UL, 2336552879UL, 4294925233UL, 2304563134UL,
206*7f2fe78bSCy Schubert 1804603682UL, 4254626195UL, 2792965006UL, 1236535329UL,
207*7f2fe78bSCy Schubert };
208*7f2fe78bSCy Schubert FF (a, b, c, d, in[i], round1s[i%4], round1consts[i]);
209*7f2fe78bSCy Schubert ROTATE;
210*7f2fe78bSCy Schubert }
211*7f2fe78bSCy Schubert for (i = 0; i < 16; i++) {
212*7f2fe78bSCy Schubert const unsigned char round2s[] = { 5, 9, 14, 20 };
213*7f2fe78bSCy Schubert const krb5_ui_4 round2consts[] = {
214*7f2fe78bSCy Schubert 4129170786UL, 3225465664UL, 643717713UL, 3921069994UL,
215*7f2fe78bSCy Schubert 3593408605UL, 38016083UL, 3634488961UL, 3889429448UL,
216*7f2fe78bSCy Schubert 568446438UL, 3275163606UL, 4107603335UL, 1163531501UL,
217*7f2fe78bSCy Schubert 2850285829UL, 4243563512UL, 1735328473UL, 2368359562UL,
218*7f2fe78bSCy Schubert };
219*7f2fe78bSCy Schubert int r2index = (1 + i * 5) % 16;
220*7f2fe78bSCy Schubert GG (a, b, c, d, in[r2index], round2s[i%4], round2consts[i]);
221*7f2fe78bSCy Schubert ROTATE;
222*7f2fe78bSCy Schubert }
223*7f2fe78bSCy Schubert for (i = 0; i < 16; i++) {
224*7f2fe78bSCy Schubert static const unsigned char round3s[] = { 4, 11, 16, 23 };
225*7f2fe78bSCy Schubert static const krb5_ui_4 round3consts[] = {
226*7f2fe78bSCy Schubert 4294588738UL, 2272392833UL, 1839030562UL, 4259657740UL,
227*7f2fe78bSCy Schubert 2763975236UL, 1272893353UL, 4139469664UL, 3200236656UL,
228*7f2fe78bSCy Schubert 681279174UL, 3936430074UL, 3572445317UL, 76029189UL,
229*7f2fe78bSCy Schubert 3654602809UL, 3873151461UL, 530742520UL, 3299628645UL,
230*7f2fe78bSCy Schubert };
231*7f2fe78bSCy Schubert int r3index = (5 + i * 3) % 16;
232*7f2fe78bSCy Schubert HH (a, b, c, d, in[r3index], round3s[i%4], round3consts[i]);
233*7f2fe78bSCy Schubert ROTATE;
234*7f2fe78bSCy Schubert }
235*7f2fe78bSCy Schubert for (i = 0; i < 16; i++) {
236*7f2fe78bSCy Schubert static const unsigned char round4s[] = { 6, 10, 15, 21 };
237*7f2fe78bSCy Schubert static const krb5_ui_4 round4consts[] = {
238*7f2fe78bSCy Schubert 4096336452UL, 1126891415UL, 2878612391UL, 4237533241UL,
239*7f2fe78bSCy Schubert 1700485571UL, 2399980690UL, 4293915773UL, 2240044497UL,
240*7f2fe78bSCy Schubert 1873313359UL, 4264355552UL, 2734768916UL, 1309151649UL,
241*7f2fe78bSCy Schubert 4149444226UL, 3174756917UL, 718787259UL, 3951481745UL,
242*7f2fe78bSCy Schubert };
243*7f2fe78bSCy Schubert int r4index = (7 * i) % 16;
244*7f2fe78bSCy Schubert II (a, b, c, d, in[r4index], round4s[i%4], round4consts[i]);
245*7f2fe78bSCy Schubert ROTATE;
246*7f2fe78bSCy Schubert }
247*7f2fe78bSCy Schubert
248*7f2fe78bSCy Schubert #else
249*7f2fe78bSCy Schubert
250*7f2fe78bSCy Schubert /* Round 1 */
251*7f2fe78bSCy Schubert #define S11 7
252*7f2fe78bSCy Schubert #define S12 12
253*7f2fe78bSCy Schubert #define S13 17
254*7f2fe78bSCy Schubert #define S14 22
255*7f2fe78bSCy Schubert FF ( a, b, c, d, in[ 0], S11, 3614090360UL); /* 1 */
256*7f2fe78bSCy Schubert FF ( d, a, b, c, in[ 1], S12, 3905402710UL); /* 2 */
257*7f2fe78bSCy Schubert FF ( c, d, a, b, in[ 2], S13, 606105819UL); /* 3 */
258*7f2fe78bSCy Schubert FF ( b, c, d, a, in[ 3], S14, 3250441966UL); /* 4 */
259*7f2fe78bSCy Schubert FF ( a, b, c, d, in[ 4], S11, 4118548399UL); /* 5 */
260*7f2fe78bSCy Schubert FF ( d, a, b, c, in[ 5], S12, 1200080426UL); /* 6 */
261*7f2fe78bSCy Schubert FF ( c, d, a, b, in[ 6], S13, 2821735955UL); /* 7 */
262*7f2fe78bSCy Schubert FF ( b, c, d, a, in[ 7], S14, 4249261313UL); /* 8 */
263*7f2fe78bSCy Schubert FF ( a, b, c, d, in[ 8], S11, 1770035416UL); /* 9 */
264*7f2fe78bSCy Schubert FF ( d, a, b, c, in[ 9], S12, 2336552879UL); /* 10 */
265*7f2fe78bSCy Schubert FF ( c, d, a, b, in[10], S13, 4294925233UL); /* 11 */
266*7f2fe78bSCy Schubert FF ( b, c, d, a, in[11], S14, 2304563134UL); /* 12 */
267*7f2fe78bSCy Schubert FF ( a, b, c, d, in[12], S11, 1804603682UL); /* 13 */
268*7f2fe78bSCy Schubert FF ( d, a, b, c, in[13], S12, 4254626195UL); /* 14 */
269*7f2fe78bSCy Schubert FF ( c, d, a, b, in[14], S13, 2792965006UL); /* 15 */
270*7f2fe78bSCy Schubert FF ( b, c, d, a, in[15], S14, 1236535329UL); /* 16 */
271*7f2fe78bSCy Schubert
272*7f2fe78bSCy Schubert /* Round 2 */
273*7f2fe78bSCy Schubert #define S21 5
274*7f2fe78bSCy Schubert #define S22 9
275*7f2fe78bSCy Schubert #define S23 14
276*7f2fe78bSCy Schubert #define S24 20
277*7f2fe78bSCy Schubert GG ( a, b, c, d, in[ 1], S21, 4129170786UL); /* 17 */
278*7f2fe78bSCy Schubert GG ( d, a, b, c, in[ 6], S22, 3225465664UL); /* 18 */
279*7f2fe78bSCy Schubert GG ( c, d, a, b, in[11], S23, 643717713UL); /* 19 */
280*7f2fe78bSCy Schubert GG ( b, c, d, a, in[ 0], S24, 3921069994UL); /* 20 */
281*7f2fe78bSCy Schubert GG ( a, b, c, d, in[ 5], S21, 3593408605UL); /* 21 */
282*7f2fe78bSCy Schubert GG ( d, a, b, c, in[10], S22, 38016083UL); /* 22 */
283*7f2fe78bSCy Schubert GG ( c, d, a, b, in[15], S23, 3634488961UL); /* 23 */
284*7f2fe78bSCy Schubert GG ( b, c, d, a, in[ 4], S24, 3889429448UL); /* 24 */
285*7f2fe78bSCy Schubert GG ( a, b, c, d, in[ 9], S21, 568446438UL); /* 25 */
286*7f2fe78bSCy Schubert GG ( d, a, b, c, in[14], S22, 3275163606UL); /* 26 */
287*7f2fe78bSCy Schubert GG ( c, d, a, b, in[ 3], S23, 4107603335UL); /* 27 */
288*7f2fe78bSCy Schubert GG ( b, c, d, a, in[ 8], S24, 1163531501UL); /* 28 */
289*7f2fe78bSCy Schubert GG ( a, b, c, d, in[13], S21, 2850285829UL); /* 29 */
290*7f2fe78bSCy Schubert GG ( d, a, b, c, in[ 2], S22, 4243563512UL); /* 30 */
291*7f2fe78bSCy Schubert GG ( c, d, a, b, in[ 7], S23, 1735328473UL); /* 31 */
292*7f2fe78bSCy Schubert GG ( b, c, d, a, in[12], S24, 2368359562UL); /* 32 */
293*7f2fe78bSCy Schubert
294*7f2fe78bSCy Schubert /* Round 3 */
295*7f2fe78bSCy Schubert #define S31 4
296*7f2fe78bSCy Schubert #define S32 11
297*7f2fe78bSCy Schubert #define S33 16
298*7f2fe78bSCy Schubert #define S34 23
299*7f2fe78bSCy Schubert HH ( a, b, c, d, in[ 5], S31, 4294588738UL); /* 33 */
300*7f2fe78bSCy Schubert HH ( d, a, b, c, in[ 8], S32, 2272392833UL); /* 34 */
301*7f2fe78bSCy Schubert HH ( c, d, a, b, in[11], S33, 1839030562UL); /* 35 */
302*7f2fe78bSCy Schubert HH ( b, c, d, a, in[14], S34, 4259657740UL); /* 36 */
303*7f2fe78bSCy Schubert HH ( a, b, c, d, in[ 1], S31, 2763975236UL); /* 37 */
304*7f2fe78bSCy Schubert HH ( d, a, b, c, in[ 4], S32, 1272893353UL); /* 38 */
305*7f2fe78bSCy Schubert HH ( c, d, a, b, in[ 7], S33, 4139469664UL); /* 39 */
306*7f2fe78bSCy Schubert HH ( b, c, d, a, in[10], S34, 3200236656UL); /* 40 */
307*7f2fe78bSCy Schubert HH ( a, b, c, d, in[13], S31, 681279174UL); /* 41 */
308*7f2fe78bSCy Schubert HH ( d, a, b, c, in[ 0], S32, 3936430074UL); /* 42 */
309*7f2fe78bSCy Schubert HH ( c, d, a, b, in[ 3], S33, 3572445317UL); /* 43 */
310*7f2fe78bSCy Schubert HH ( b, c, d, a, in[ 6], S34, 76029189UL); /* 44 */
311*7f2fe78bSCy Schubert HH ( a, b, c, d, in[ 9], S31, 3654602809UL); /* 45 */
312*7f2fe78bSCy Schubert HH ( d, a, b, c, in[12], S32, 3873151461UL); /* 46 */
313*7f2fe78bSCy Schubert HH ( c, d, a, b, in[15], S33, 530742520UL); /* 47 */
314*7f2fe78bSCy Schubert HH ( b, c, d, a, in[ 2], S34, 3299628645UL); /* 48 */
315*7f2fe78bSCy Schubert
316*7f2fe78bSCy Schubert /* Round 4 */
317*7f2fe78bSCy Schubert #define S41 6
318*7f2fe78bSCy Schubert #define S42 10
319*7f2fe78bSCy Schubert #define S43 15
320*7f2fe78bSCy Schubert #define S44 21
321*7f2fe78bSCy Schubert II ( a, b, c, d, in[ 0], S41, 4096336452UL); /* 49 */
322*7f2fe78bSCy Schubert II ( d, a, b, c, in[ 7], S42, 1126891415UL); /* 50 */
323*7f2fe78bSCy Schubert II ( c, d, a, b, in[14], S43, 2878612391UL); /* 51 */
324*7f2fe78bSCy Schubert II ( b, c, d, a, in[ 5], S44, 4237533241UL); /* 52 */
325*7f2fe78bSCy Schubert II ( a, b, c, d, in[12], S41, 1700485571UL); /* 53 */
326*7f2fe78bSCy Schubert II ( d, a, b, c, in[ 3], S42, 2399980690UL); /* 54 */
327*7f2fe78bSCy Schubert II ( c, d, a, b, in[10], S43, 4293915773UL); /* 55 */
328*7f2fe78bSCy Schubert II ( b, c, d, a, in[ 1], S44, 2240044497UL); /* 56 */
329*7f2fe78bSCy Schubert II ( a, b, c, d, in[ 8], S41, 1873313359UL); /* 57 */
330*7f2fe78bSCy Schubert II ( d, a, b, c, in[15], S42, 4264355552UL); /* 58 */
331*7f2fe78bSCy Schubert II ( c, d, a, b, in[ 6], S43, 2734768916UL); /* 59 */
332*7f2fe78bSCy Schubert II ( b, c, d, a, in[13], S44, 1309151649UL); /* 60 */
333*7f2fe78bSCy Schubert II ( a, b, c, d, in[ 4], S41, 4149444226UL); /* 61 */
334*7f2fe78bSCy Schubert II ( d, a, b, c, in[11], S42, 3174756917UL); /* 62 */
335*7f2fe78bSCy Schubert II ( c, d, a, b, in[ 2], S43, 718787259UL); /* 63 */
336*7f2fe78bSCy Schubert II ( b, c, d, a, in[ 9], S44, 3951481745UL); /* 64 */
337*7f2fe78bSCy Schubert
338*7f2fe78bSCy Schubert #endif /* small? */
339*7f2fe78bSCy Schubert
340*7f2fe78bSCy Schubert buf[0] += a;
341*7f2fe78bSCy Schubert buf[1] += b;
342*7f2fe78bSCy Schubert buf[2] += c;
343*7f2fe78bSCy Schubert buf[3] += d;
344*7f2fe78bSCy Schubert }
345*7f2fe78bSCy Schubert
346*7f2fe78bSCy Schubert #endif /* K5_BUILTIN_MD5 */
347