18 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <asm/byteorder.h>
40 #define F1(x, y, z) (x ^ y ^ z)
41 #define F2(x, y, z) (z ^ (x & (y ^ z)))
42 #define F3(x, y, z) ((x | ~y) ^ z)
43 #define F4(x, y, z) (y ^ (z & (x ^ y)))
45 #define ROUND(a, b, c, d, f, k, x, s) { \
46 (a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
47 (a) = rol32((a), (s)); \
77 ROUND(cc, dd, aa, bb,
F1,
K1, in[10], 14);
78 ROUND(bb, cc, dd, aa,
F1,
K1, in[11], 15);
89 ROUND(aa, bb, cc, dd,
F2,
K2, in[10], 11);
99 ROUND(cc, dd, aa, bb,
F2,
K2, in[11], 13);
100 ROUND(bb, cc, dd, aa,
F2,
K2, in[8], 12);
103 ROUND(aa, bb, cc, dd,
F3,
K3, in[3], 11);
104 ROUND(dd, aa, bb, cc,
F3,
K3, in[10], 13);
105 ROUND(cc, dd, aa, bb,
F3,
K3, in[14], 6);
107 ROUND(aa, bb, cc, dd,
F3,
K3, in[9], 14);
108 ROUND(dd, aa, bb, cc,
F3,
K3, in[15], 9);
109 ROUND(cc, dd, aa, bb,
F3,
K3, in[8], 13);
110 ROUND(bb, cc, dd, aa,
F3,
K3, in[1], 15);
111 ROUND(aa, bb, cc, dd,
F3,
K3, in[2], 14);
113 ROUND(cc, dd, aa, bb,
F3,
K3, in[0], 13);
115 ROUND(aa, bb, cc, dd,
F3,
K3, in[13], 5);
116 ROUND(dd, aa, bb, cc,
F3,
K3, in[11], 12);
118 ROUND(bb, cc, dd, aa,
F3,
K3, in[12], 5);
121 ROUND(aa, bb, cc, dd,
F4,
K4, in[1], 11);
122 ROUND(dd, aa, bb, cc,
F4,
K4, in[9], 12);
123 ROUND(cc, dd, aa, bb,
F4,
K4, in[11], 14);
124 ROUND(bb, cc, dd, aa,
F4,
K4, in[10], 15);
125 ROUND(aa, bb, cc, dd,
F4,
K4, in[0], 14);
126 ROUND(dd, aa, bb, cc,
F4,
K4, in[8], 15);
127 ROUND(cc, dd, aa, bb,
F4,
K4, in[12], 9);
129 ROUND(aa, bb, cc, dd,
F4,
K4, in[13], 9);
130 ROUND(dd, aa, bb, cc,
F4,
K4, in[3], 14);
132 ROUND(bb, cc, dd, aa,
F4,
K4, in[15], 6);
133 ROUND(aa, bb, cc, dd,
F4,
K4, in[14], 8);
136 ROUND(bb, cc, dd, aa,
F4,
K4, in[2], 12);
140 ROUND(ddd, aaa, bbb, ccc,
F4,
KK1, in[14], 9);
142 ROUND(bbb, ccc, ddd, aaa,
F4,
KK1, in[0], 11);
143 ROUND(aaa, bbb, ccc, ddd,
F4,
KK1, in[9], 13);
144 ROUND(ddd, aaa, bbb, ccc,
F4,
KK1, in[2], 15);
145 ROUND(ccc, ddd, aaa, bbb,
F4,
KK1, in[11], 15);
147 ROUND(aaa, bbb, ccc, ddd,
F4,
KK1, in[13], 7);
149 ROUND(ccc, ddd, aaa, bbb,
F4,
KK1, in[15], 8);
150 ROUND(bbb, ccc, ddd, aaa,
F4,
KK1, in[8], 11);
151 ROUND(aaa, bbb, ccc, ddd,
F4,
KK1, in[1], 14);
152 ROUND(ddd, aaa, bbb, ccc,
F4,
KK1, in[10], 14);
153 ROUND(ccc, ddd, aaa, bbb,
F4,
KK1, in[3], 12);
154 ROUND(bbb, ccc, ddd, aaa,
F4,
KK1, in[12], 6);
158 ROUND(ddd, aaa, bbb, ccc,
F3,
KK2, in[11], 13);
159 ROUND(ccc, ddd, aaa, bbb,
F3,
KK2, in[3], 15);
161 ROUND(aaa, bbb, ccc, ddd,
F3,
KK2, in[0], 12);
162 ROUND(ddd, aaa, bbb, ccc,
F3,
KK2, in[13], 8);
164 ROUND(bbb, ccc, ddd, aaa,
F3,
KK2, in[10], 11);
165 ROUND(aaa, bbb, ccc, ddd,
F3,
KK2, in[14], 7);
166 ROUND(ddd, aaa, bbb, ccc,
F3,
KK2, in[15], 7);
167 ROUND(ccc, ddd, aaa, bbb,
F3,
KK2, in[8], 12);
168 ROUND(bbb, ccc, ddd, aaa,
F3,
KK2, in[12], 7);
170 ROUND(ddd, aaa, bbb, ccc,
F3,
KK2, in[9], 15);
171 ROUND(ccc, ddd, aaa, bbb,
F3,
KK2, in[1], 13);
172 ROUND(bbb, ccc, ddd, aaa,
F3,
KK2, in[2], 11);
175 ROUND(aaa, bbb, ccc, ddd,
F2,
KK3, in[15], 9);
177 ROUND(ccc, ddd, aaa, bbb,
F2,
KK3, in[1], 15);
178 ROUND(bbb, ccc, ddd, aaa,
F2,
KK3, in[3], 11);
180 ROUND(ddd, aaa, bbb, ccc,
F2,
KK3, in[14], 6);
182 ROUND(bbb, ccc, ddd, aaa,
F2,
KK3, in[9], 14);
183 ROUND(aaa, bbb, ccc, ddd,
F2,
KK3, in[11], 12);
184 ROUND(ddd, aaa, bbb, ccc,
F2,
KK3, in[8], 13);
185 ROUND(ccc, ddd, aaa, bbb,
F2,
KK3, in[12], 5);
186 ROUND(bbb, ccc, ddd, aaa,
F2,
KK3, in[2], 14);
187 ROUND(aaa, bbb, ccc, ddd,
F2,
KK3, in[10], 13);
188 ROUND(ddd, aaa, bbb, ccc,
F2,
KK3, in[0], 13);
190 ROUND(bbb, ccc, ddd, aaa,
F2,
KK3, in[13], 5);
193 ROUND(aaa, bbb, ccc, ddd,
F1,
KK4, in[8], 15);
196 ROUND(bbb, ccc, ddd, aaa,
F1,
KK4, in[1], 11);
197 ROUND(aaa, bbb, ccc, ddd,
F1,
KK4, in[3], 14);
198 ROUND(ddd, aaa, bbb, ccc,
F1,
KK4, in[11], 14);
199 ROUND(ccc, ddd, aaa, bbb,
F1,
KK4, in[15], 6);
200 ROUND(bbb, ccc, ddd, aaa,
F1,
KK4, in[0], 14);
202 ROUND(ddd, aaa, bbb, ccc,
F1,
KK4, in[12], 9);
203 ROUND(ccc, ddd, aaa, bbb,
F1,
KK4, in[2], 12);
204 ROUND(bbb, ccc, ddd, aaa,
F1,
KK4, in[13], 9);
205 ROUND(aaa, bbb, ccc, ddd,
F1,
KK4, in[9], 12);
207 ROUND(ccc, ddd, aaa, bbb,
F1,
KK4, in[10], 15);
208 ROUND(bbb, ccc, ddd, aaa,
F1,
KK4, in[14], 8);
211 ddd += cc + state[1];
212 state[1] = state[2] + dd + aaa;
213 state[2] = state[3] + aa + bbb;
214 state[3] = state[0] + bb + ccc;
222 struct rmd128_ctx *rctx = shash_desc_ctx(desc);
239 struct rmd128_ctx *rctx = shash_desc_ctx(desc);
258 while (len >=
sizeof(rctx->
buffer)) {
261 data +=
sizeof(rctx->
buffer);
262 len -=
sizeof(rctx->
buffer);
274 struct rmd128_ctx *rctx = shash_desc_ctx(desc);
284 padlen = (index < 56) ? (56 - index) : ((64+56) - index);
285 rmd128_update(desc, padding, padlen);
288 rmd128_update(desc, (
const u8 *)&bits,
sizeof(bits));
291 for (i = 0; i < 4; i++)
295 memset(rctx, 0,
sizeof(*rctx));
303 .update = rmd128_update,
304 .final = rmd128_final,
307 .cra_name =
"rmd128",
314 static int __init rmd128_mod_init(
void)
319 static void __exit rmd128_mod_fini(
void)