1*fa2d22afSderaadt /* $OpenBSD: rmd160.c,v 1.5 2011/01/11 15:42:05 deraadt Exp $ */
2973243bcSmarkus /*
3973243bcSmarkus * Copyright (c) 2001 Markus Friedl. All rights reserved.
421f2d90fSderaadt *
5973243bcSmarkus * Redistribution and use in source and binary forms, with or without
6973243bcSmarkus * modification, are permitted provided that the following conditions
7973243bcSmarkus * are met:
8973243bcSmarkus * 1. Redistributions of source code must retain the above copyright
9973243bcSmarkus * notice, this list of conditions and the following disclaimer.
10973243bcSmarkus * 2. Redistributions in binary form must reproduce the above copyright
11973243bcSmarkus * notice, this list of conditions and the following disclaimer in the
12973243bcSmarkus * documentation and/or other materials provided with the distribution.
1321f2d90fSderaadt *
14973243bcSmarkus * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15973243bcSmarkus * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16973243bcSmarkus * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17973243bcSmarkus * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18973243bcSmarkus * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19973243bcSmarkus * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20973243bcSmarkus * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21973243bcSmarkus * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22973243bcSmarkus * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23973243bcSmarkus * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24973243bcSmarkus */
25973243bcSmarkus /*
26973243bcSmarkus * Preneel, Bosselaers, Dobbertin, "The Cryptographic Hash Function RIPEMD-160",
27973243bcSmarkus * RSA Laboratories, CryptoBytes, Volume 3, Number 2, Autumn 1997,
28973243bcSmarkus * ftp://ftp.rsasecurity.com/pub/cryptobytes/crypto3n2.pdf
29973243bcSmarkus */
3021f2d90fSderaadt #include <sys/param.h>
3121f2d90fSderaadt #include <sys/systm.h>
32973243bcSmarkus #include <sys/endian.h>
3321f2d90fSderaadt #include <crypto/rmd160.h>
3421f2d90fSderaadt
35973243bcSmarkus #define PUT_64BIT_LE(cp, value) do { \
36973243bcSmarkus (cp)[7] = (value) >> 56; \
37973243bcSmarkus (cp)[6] = (value) >> 48; \
38973243bcSmarkus (cp)[5] = (value) >> 40; \
39973243bcSmarkus (cp)[4] = (value) >> 32; \
40973243bcSmarkus (cp)[3] = (value) >> 24; \
41973243bcSmarkus (cp)[2] = (value) >> 16; \
42973243bcSmarkus (cp)[1] = (value) >> 8; \
43973243bcSmarkus (cp)[0] = (value); } while (0)
4421f2d90fSderaadt
45973243bcSmarkus #define PUT_32BIT_LE(cp, value) do { \
46973243bcSmarkus (cp)[3] = (value) >> 24; \
47973243bcSmarkus (cp)[2] = (value) >> 16; \
48973243bcSmarkus (cp)[1] = (value) >> 8; \
49973243bcSmarkus (cp)[0] = (value); } while (0)
5021f2d90fSderaadt
51973243bcSmarkus #define H0 0x67452301U
52973243bcSmarkus #define H1 0xEFCDAB89U
53973243bcSmarkus #define H2 0x98BADCFEU
54973243bcSmarkus #define H3 0x10325476U
55973243bcSmarkus #define H4 0xC3D2E1F0U
5621f2d90fSderaadt
57973243bcSmarkus #define K0 0x00000000U
58973243bcSmarkus #define K1 0x5A827999U
59973243bcSmarkus #define K2 0x6ED9EBA1U
60973243bcSmarkus #define K3 0x8F1BBCDCU
61973243bcSmarkus #define K4 0xA953FD4EU
6221f2d90fSderaadt
63973243bcSmarkus #define KK0 0x50A28BE6U
64973243bcSmarkus #define KK1 0x5C4DD124U
65973243bcSmarkus #define KK2 0x6D703EF3U
66973243bcSmarkus #define KK3 0x7A6D76E9U
67973243bcSmarkus #define KK4 0x00000000U
6821f2d90fSderaadt
69973243bcSmarkus /* rotate x left n bits. */
70973243bcSmarkus #define ROL(n, x) (((x) << (n)) | ((x) >> (32-(n))))
7121f2d90fSderaadt
72973243bcSmarkus #define F0(x, y, z) ((x) ^ (y) ^ (z))
73973243bcSmarkus #define F1(x, y, z) (((x) & (y)) | ((~x) & (z)))
74973243bcSmarkus #define F2(x, y, z) (((x) | (~y)) ^ (z))
75973243bcSmarkus #define F3(x, y, z) (((x) & (z)) | ((y) & (~z)))
76973243bcSmarkus #define F4(x, y, z) ((x) ^ ((y) | (~z)))
7721f2d90fSderaadt
78973243bcSmarkus #define R(a, b, c, d, e, Fj, Kj, sj, rj) \
79973243bcSmarkus do { \
80973243bcSmarkus a = ROL(sj, a + Fj(b,c,d) + X(rj) + Kj) + e; \
81973243bcSmarkus c = ROL(10, c); \
82973243bcSmarkus } while(0)
83973243bcSmarkus
84973243bcSmarkus #define X(i) x[i]
85973243bcSmarkus
86973243bcSmarkus static u_char PADDING[64] = {
87973243bcSmarkus 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88973243bcSmarkus 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
89973243bcSmarkus 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
90973243bcSmarkus };
91973243bcSmarkus
92973243bcSmarkus void
RMD160Init(RMD160_CTX * ctx)93973243bcSmarkus RMD160Init(RMD160_CTX *ctx)
9421f2d90fSderaadt {
95973243bcSmarkus ctx->count = 0;
96973243bcSmarkus ctx->state[0] = H0;
97973243bcSmarkus ctx->state[1] = H1;
98973243bcSmarkus ctx->state[2] = H2;
99973243bcSmarkus ctx->state[3] = H3;
100973243bcSmarkus ctx->state[4] = H4;
10121f2d90fSderaadt }
10221f2d90fSderaadt
103973243bcSmarkus void
RMD160Update(RMD160_CTX * ctx,const u_char * input,u_int32_t len)104973243bcSmarkus RMD160Update(RMD160_CTX *ctx, const u_char *input, u_int32_t len)
10521f2d90fSderaadt {
106973243bcSmarkus u_int32_t have, off, need;
10721f2d90fSderaadt
108973243bcSmarkus have = (ctx->count/8) % 64;
109973243bcSmarkus need = 64 - have;
110973243bcSmarkus ctx->count += 8 * len;
111973243bcSmarkus off = 0;
11221f2d90fSderaadt
113973243bcSmarkus if (len >= need) {
114973243bcSmarkus if (have) {
115973243bcSmarkus memcpy(ctx->buffer + have, input, need);
116973243bcSmarkus RMD160Transform(ctx->state, ctx->buffer);
117973243bcSmarkus off = need;
118973243bcSmarkus have = 0;
119973243bcSmarkus }
120973243bcSmarkus /* now the buffer is empty */
121973243bcSmarkus while (off + 64 <= len) {
122973243bcSmarkus RMD160Transform(ctx->state, input+off);
123973243bcSmarkus off += 64;
124973243bcSmarkus }
125973243bcSmarkus }
126973243bcSmarkus if (off < len)
127973243bcSmarkus memcpy(ctx->buffer + have, input+off, len-off);
12821f2d90fSderaadt }
12921f2d90fSderaadt
130973243bcSmarkus void
RMD160Final(u_char digest[20],RMD160_CTX * ctx)131973243bcSmarkus RMD160Final(u_char digest[20], RMD160_CTX *ctx)
13221f2d90fSderaadt {
133973243bcSmarkus int i;
134973243bcSmarkus u_char size[8];
135973243bcSmarkus u_int32_t padlen;
13621f2d90fSderaadt
137973243bcSmarkus PUT_64BIT_LE(size, ctx->count);
13821f2d90fSderaadt
13921f2d90fSderaadt /*
140973243bcSmarkus * pad to 64 byte blocks, at least one byte from PADDING plus 8 bytes
141973243bcSmarkus * for the size
14221f2d90fSderaadt */
143973243bcSmarkus padlen = 64 - ((ctx->count/8) % 64);
144973243bcSmarkus if (padlen < 1 + 8)
145973243bcSmarkus padlen += 64;
146973243bcSmarkus RMD160Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */
147973243bcSmarkus RMD160Update(ctx, size, 8);
148973243bcSmarkus
149973243bcSmarkus if (digest != NULL)
150973243bcSmarkus for (i = 0; i < 5; i++)
151973243bcSmarkus PUT_32BIT_LE(digest + i*4, ctx->state[i]);
152973243bcSmarkus
153*fa2d22afSderaadt explicit_bzero(ctx, sizeof (*ctx));
15421f2d90fSderaadt }
15521f2d90fSderaadt
156973243bcSmarkus void
RMD160Transform(u_int32_t state[5],const u_char block[64])157973243bcSmarkus RMD160Transform(u_int32_t state[5], const u_char block[64])
15821f2d90fSderaadt {
159973243bcSmarkus u_int32_t a, b, c, d, e, aa, bb, cc, dd, ee, t, x[16];
16021f2d90fSderaadt
16121f2d90fSderaadt #if BYTE_ORDER == LITTLE_ENDIAN
162973243bcSmarkus memcpy(x, block, 64);
16321f2d90fSderaadt #else
164973243bcSmarkus int i;
165973243bcSmarkus
166973243bcSmarkus for (i = 0; i < 16; i++)
167ae7178f8Smarkus x[i] = (u_int32_t)(
168ae7178f8Smarkus (u_int32_t)(block[i*4 + 0]) |
169ae7178f8Smarkus (u_int32_t)(block[i*4 + 1]) << 8 |
170ae7178f8Smarkus (u_int32_t)(block[i*4 + 2]) << 16 |
171ae7178f8Smarkus (u_int32_t)(block[i*4 + 3]) << 24);
17221f2d90fSderaadt #endif
17321f2d90fSderaadt
174973243bcSmarkus a = state[0];
175973243bcSmarkus b = state[1];
176973243bcSmarkus c = state[2];
177973243bcSmarkus d = state[3];
178973243bcSmarkus e = state[4];
17921f2d90fSderaadt
180973243bcSmarkus /* Round 1 */
181973243bcSmarkus R(a, b, c, d, e, F0, K0, 11, 0);
182973243bcSmarkus R(e, a, b, c, d, F0, K0, 14, 1);
183973243bcSmarkus R(d, e, a, b, c, F0, K0, 15, 2);
184973243bcSmarkus R(c, d, e, a, b, F0, K0, 12, 3);
185973243bcSmarkus R(b, c, d, e, a, F0, K0, 5, 4);
186973243bcSmarkus R(a, b, c, d, e, F0, K0, 8, 5);
187973243bcSmarkus R(e, a, b, c, d, F0, K0, 7, 6);
188973243bcSmarkus R(d, e, a, b, c, F0, K0, 9, 7);
189973243bcSmarkus R(c, d, e, a, b, F0, K0, 11, 8);
190973243bcSmarkus R(b, c, d, e, a, F0, K0, 13, 9);
191973243bcSmarkus R(a, b, c, d, e, F0, K0, 14, 10);
192973243bcSmarkus R(e, a, b, c, d, F0, K0, 15, 11);
193973243bcSmarkus R(d, e, a, b, c, F0, K0, 6, 12);
194973243bcSmarkus R(c, d, e, a, b, F0, K0, 7, 13);
195973243bcSmarkus R(b, c, d, e, a, F0, K0, 9, 14);
196973243bcSmarkus R(a, b, c, d, e, F0, K0, 8, 15); /* #15 */
197973243bcSmarkus /* Round 2 */
198973243bcSmarkus R(e, a, b, c, d, F1, K1, 7, 7);
199973243bcSmarkus R(d, e, a, b, c, F1, K1, 6, 4);
200973243bcSmarkus R(c, d, e, a, b, F1, K1, 8, 13);
201973243bcSmarkus R(b, c, d, e, a, F1, K1, 13, 1);
202973243bcSmarkus R(a, b, c, d, e, F1, K1, 11, 10);
203973243bcSmarkus R(e, a, b, c, d, F1, K1, 9, 6);
204973243bcSmarkus R(d, e, a, b, c, F1, K1, 7, 15);
205973243bcSmarkus R(c, d, e, a, b, F1, K1, 15, 3);
206973243bcSmarkus R(b, c, d, e, a, F1, K1, 7, 12);
207973243bcSmarkus R(a, b, c, d, e, F1, K1, 12, 0);
208973243bcSmarkus R(e, a, b, c, d, F1, K1, 15, 9);
209973243bcSmarkus R(d, e, a, b, c, F1, K1, 9, 5);
210973243bcSmarkus R(c, d, e, a, b, F1, K1, 11, 2);
211973243bcSmarkus R(b, c, d, e, a, F1, K1, 7, 14);
212973243bcSmarkus R(a, b, c, d, e, F1, K1, 13, 11);
213973243bcSmarkus R(e, a, b, c, d, F1, K1, 12, 8); /* #31 */
214973243bcSmarkus /* Round 3 */
215973243bcSmarkus R(d, e, a, b, c, F2, K2, 11, 3);
216973243bcSmarkus R(c, d, e, a, b, F2, K2, 13, 10);
217973243bcSmarkus R(b, c, d, e, a, F2, K2, 6, 14);
218973243bcSmarkus R(a, b, c, d, e, F2, K2, 7, 4);
219973243bcSmarkus R(e, a, b, c, d, F2, K2, 14, 9);
220973243bcSmarkus R(d, e, a, b, c, F2, K2, 9, 15);
221973243bcSmarkus R(c, d, e, a, b, F2, K2, 13, 8);
222973243bcSmarkus R(b, c, d, e, a, F2, K2, 15, 1);
223973243bcSmarkus R(a, b, c, d, e, F2, K2, 14, 2);
224973243bcSmarkus R(e, a, b, c, d, F2, K2, 8, 7);
225973243bcSmarkus R(d, e, a, b, c, F2, K2, 13, 0);
226973243bcSmarkus R(c, d, e, a, b, F2, K2, 6, 6);
227973243bcSmarkus R(b, c, d, e, a, F2, K2, 5, 13);
228973243bcSmarkus R(a, b, c, d, e, F2, K2, 12, 11);
229973243bcSmarkus R(e, a, b, c, d, F2, K2, 7, 5);
230973243bcSmarkus R(d, e, a, b, c, F2, K2, 5, 12); /* #47 */
231973243bcSmarkus /* Round 4 */
232973243bcSmarkus R(c, d, e, a, b, F3, K3, 11, 1);
233973243bcSmarkus R(b, c, d, e, a, F3, K3, 12, 9);
234973243bcSmarkus R(a, b, c, d, e, F3, K3, 14, 11);
235973243bcSmarkus R(e, a, b, c, d, F3, K3, 15, 10);
236973243bcSmarkus R(d, e, a, b, c, F3, K3, 14, 0);
237973243bcSmarkus R(c, d, e, a, b, F3, K3, 15, 8);
238973243bcSmarkus R(b, c, d, e, a, F3, K3, 9, 12);
239973243bcSmarkus R(a, b, c, d, e, F3, K3, 8, 4);
240973243bcSmarkus R(e, a, b, c, d, F3, K3, 9, 13);
241973243bcSmarkus R(d, e, a, b, c, F3, K3, 14, 3);
242973243bcSmarkus R(c, d, e, a, b, F3, K3, 5, 7);
243973243bcSmarkus R(b, c, d, e, a, F3, K3, 6, 15);
244973243bcSmarkus R(a, b, c, d, e, F3, K3, 8, 14);
245973243bcSmarkus R(e, a, b, c, d, F3, K3, 6, 5);
246973243bcSmarkus R(d, e, a, b, c, F3, K3, 5, 6);
247973243bcSmarkus R(c, d, e, a, b, F3, K3, 12, 2); /* #63 */
248973243bcSmarkus /* Round 5 */
249973243bcSmarkus R(b, c, d, e, a, F4, K4, 9, 4);
250973243bcSmarkus R(a, b, c, d, e, F4, K4, 15, 0);
251973243bcSmarkus R(e, a, b, c, d, F4, K4, 5, 5);
252973243bcSmarkus R(d, e, a, b, c, F4, K4, 11, 9);
253973243bcSmarkus R(c, d, e, a, b, F4, K4, 6, 7);
254973243bcSmarkus R(b, c, d, e, a, F4, K4, 8, 12);
255973243bcSmarkus R(a, b, c, d, e, F4, K4, 13, 2);
256973243bcSmarkus R(e, a, b, c, d, F4, K4, 12, 10);
257973243bcSmarkus R(d, e, a, b, c, F4, K4, 5, 14);
258973243bcSmarkus R(c, d, e, a, b, F4, K4, 12, 1);
259973243bcSmarkus R(b, c, d, e, a, F4, K4, 13, 3);
260973243bcSmarkus R(a, b, c, d, e, F4, K4, 14, 8);
261973243bcSmarkus R(e, a, b, c, d, F4, K4, 11, 11);
262973243bcSmarkus R(d, e, a, b, c, F4, K4, 8, 6);
263973243bcSmarkus R(c, d, e, a, b, F4, K4, 5, 15);
264973243bcSmarkus R(b, c, d, e, a, F4, K4, 6, 13); /* #79 */
26521f2d90fSderaadt
266973243bcSmarkus aa = a ; bb = b; cc = c; dd = d; ee = e;
267973243bcSmarkus
268973243bcSmarkus a = state[0];
269973243bcSmarkus b = state[1];
270973243bcSmarkus c = state[2];
271973243bcSmarkus d = state[3];
272973243bcSmarkus e = state[4];
273973243bcSmarkus
274973243bcSmarkus /* Parallel round 1 */
275973243bcSmarkus R(a, b, c, d, e, F4, KK0, 8, 5);
276973243bcSmarkus R(e, a, b, c, d, F4, KK0, 9, 14);
277973243bcSmarkus R(d, e, a, b, c, F4, KK0, 9, 7);
278973243bcSmarkus R(c, d, e, a, b, F4, KK0, 11, 0);
279973243bcSmarkus R(b, c, d, e, a, F4, KK0, 13, 9);
280973243bcSmarkus R(a, b, c, d, e, F4, KK0, 15, 2);
281973243bcSmarkus R(e, a, b, c, d, F4, KK0, 15, 11);
282973243bcSmarkus R(d, e, a, b, c, F4, KK0, 5, 4);
283973243bcSmarkus R(c, d, e, a, b, F4, KK0, 7, 13);
284973243bcSmarkus R(b, c, d, e, a, F4, KK0, 7, 6);
285973243bcSmarkus R(a, b, c, d, e, F4, KK0, 8, 15);
286973243bcSmarkus R(e, a, b, c, d, F4, KK0, 11, 8);
287973243bcSmarkus R(d, e, a, b, c, F4, KK0, 14, 1);
288973243bcSmarkus R(c, d, e, a, b, F4, KK0, 14, 10);
289973243bcSmarkus R(b, c, d, e, a, F4, KK0, 12, 3);
290973243bcSmarkus R(a, b, c, d, e, F4, KK0, 6, 12); /* #15 */
291973243bcSmarkus /* Parallel round 2 */
292973243bcSmarkus R(e, a, b, c, d, F3, KK1, 9, 6);
293973243bcSmarkus R(d, e, a, b, c, F3, KK1, 13, 11);
294973243bcSmarkus R(c, d, e, a, b, F3, KK1, 15, 3);
295973243bcSmarkus R(b, c, d, e, a, F3, KK1, 7, 7);
296973243bcSmarkus R(a, b, c, d, e, F3, KK1, 12, 0);
297973243bcSmarkus R(e, a, b, c, d, F3, KK1, 8, 13);
298973243bcSmarkus R(d, e, a, b, c, F3, KK1, 9, 5);
299973243bcSmarkus R(c, d, e, a, b, F3, KK1, 11, 10);
300973243bcSmarkus R(b, c, d, e, a, F3, KK1, 7, 14);
301973243bcSmarkus R(a, b, c, d, e, F3, KK1, 7, 15);
302973243bcSmarkus R(e, a, b, c, d, F3, KK1, 12, 8);
303973243bcSmarkus R(d, e, a, b, c, F3, KK1, 7, 12);
304973243bcSmarkus R(c, d, e, a, b, F3, KK1, 6, 4);
305973243bcSmarkus R(b, c, d, e, a, F3, KK1, 15, 9);
306973243bcSmarkus R(a, b, c, d, e, F3, KK1, 13, 1);
307973243bcSmarkus R(e, a, b, c, d, F3, KK1, 11, 2); /* #31 */
308973243bcSmarkus /* Parallel round 3 */
309973243bcSmarkus R(d, e, a, b, c, F2, KK2, 9, 15);
310973243bcSmarkus R(c, d, e, a, b, F2, KK2, 7, 5);
311973243bcSmarkus R(b, c, d, e, a, F2, KK2, 15, 1);
312973243bcSmarkus R(a, b, c, d, e, F2, KK2, 11, 3);
313973243bcSmarkus R(e, a, b, c, d, F2, KK2, 8, 7);
314973243bcSmarkus R(d, e, a, b, c, F2, KK2, 6, 14);
315973243bcSmarkus R(c, d, e, a, b, F2, KK2, 6, 6);
316973243bcSmarkus R(b, c, d, e, a, F2, KK2, 14, 9);
317973243bcSmarkus R(a, b, c, d, e, F2, KK2, 12, 11);
318973243bcSmarkus R(e, a, b, c, d, F2, KK2, 13, 8);
319973243bcSmarkus R(d, e, a, b, c, F2, KK2, 5, 12);
320973243bcSmarkus R(c, d, e, a, b, F2, KK2, 14, 2);
321973243bcSmarkus R(b, c, d, e, a, F2, KK2, 13, 10);
322973243bcSmarkus R(a, b, c, d, e, F2, KK2, 13, 0);
323973243bcSmarkus R(e, a, b, c, d, F2, KK2, 7, 4);
324973243bcSmarkus R(d, e, a, b, c, F2, KK2, 5, 13); /* #47 */
325973243bcSmarkus /* Parallel round 4 */
326973243bcSmarkus R(c, d, e, a, b, F1, KK3, 15, 8);
327973243bcSmarkus R(b, c, d, e, a, F1, KK3, 5, 6);
328973243bcSmarkus R(a, b, c, d, e, F1, KK3, 8, 4);
329973243bcSmarkus R(e, a, b, c, d, F1, KK3, 11, 1);
330973243bcSmarkus R(d, e, a, b, c, F1, KK3, 14, 3);
331973243bcSmarkus R(c, d, e, a, b, F1, KK3, 14, 11);
332973243bcSmarkus R(b, c, d, e, a, F1, KK3, 6, 15);
333973243bcSmarkus R(a, b, c, d, e, F1, KK3, 14, 0);
334973243bcSmarkus R(e, a, b, c, d, F1, KK3, 6, 5);
335973243bcSmarkus R(d, e, a, b, c, F1, KK3, 9, 12);
336973243bcSmarkus R(c, d, e, a, b, F1, KK3, 12, 2);
337973243bcSmarkus R(b, c, d, e, a, F1, KK3, 9, 13);
338973243bcSmarkus R(a, b, c, d, e, F1, KK3, 12, 9);
339973243bcSmarkus R(e, a, b, c, d, F1, KK3, 5, 7);
340973243bcSmarkus R(d, e, a, b, c, F1, KK3, 15, 10);
341973243bcSmarkus R(c, d, e, a, b, F1, KK3, 8, 14); /* #63 */
342973243bcSmarkus /* Parallel round 5 */
343973243bcSmarkus R(b, c, d, e, a, F0, KK4, 8, 12);
344973243bcSmarkus R(a, b, c, d, e, F0, KK4, 5, 15);
345973243bcSmarkus R(e, a, b, c, d, F0, KK4, 12, 10);
346973243bcSmarkus R(d, e, a, b, c, F0, KK4, 9, 4);
347973243bcSmarkus R(c, d, e, a, b, F0, KK4, 12, 1);
348973243bcSmarkus R(b, c, d, e, a, F0, KK4, 5, 5);
349973243bcSmarkus R(a, b, c, d, e, F0, KK4, 14, 8);
350973243bcSmarkus R(e, a, b, c, d, F0, KK4, 6, 7);
351973243bcSmarkus R(d, e, a, b, c, F0, KK4, 8, 6);
352973243bcSmarkus R(c, d, e, a, b, F0, KK4, 13, 2);
353973243bcSmarkus R(b, c, d, e, a, F0, KK4, 6, 13);
354973243bcSmarkus R(a, b, c, d, e, F0, KK4, 5, 14);
355973243bcSmarkus R(e, a, b, c, d, F0, KK4, 15, 0);
356973243bcSmarkus R(d, e, a, b, c, F0, KK4, 13, 3);
357973243bcSmarkus R(c, d, e, a, b, F0, KK4, 11, 9);
358973243bcSmarkus R(b, c, d, e, a, F0, KK4, 11, 11); /* #79 */
359973243bcSmarkus
360973243bcSmarkus t = state[1] + cc + d;
361973243bcSmarkus state[1] = state[2] + dd + e;
362973243bcSmarkus state[2] = state[3] + ee + a;
363973243bcSmarkus state[3] = state[4] + aa + b;
364973243bcSmarkus state[4] = state[0] + bb + c;
365973243bcSmarkus state[0] = t;
366973243bcSmarkus }
367