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);
91 ROUND(ccc, ddd, aaa, bbb,
F4,
KK1, in[11], 15);
98 ROUND(ddd, aaa, bbb, ccc,
F4,
KK1, in[10], 14);
100 ROUND(bbb, ccc, ddd, aaa,
F4,
KK1, in[12], 6);
103 tmp = aa; aa = aaa; aaa =
tmp;
108 ROUND(cc, dd, aa, bb,
F2,
K2, in[13], 8);
109 ROUND(bb, cc, dd, aa,
F2,
K2, in[1], 13);
110 ROUND(aa, bb, cc, dd,
F2,
K2, in[10], 11);
112 ROUND(cc, dd, aa, bb,
F2,
K2, in[15], 7);
113 ROUND(bb, cc, dd, aa,
F2,
K2, in[3], 15);
114 ROUND(aa, bb, cc, dd,
F2,
K2, in[12], 7);
115 ROUND(dd, aa, bb, cc,
F2,
K2, in[0], 12);
116 ROUND(cc, dd, aa, bb,
F2,
K2, in[9], 15);
118 ROUND(aa, bb, cc, dd,
F2,
K2, in[2], 11);
119 ROUND(dd, aa, bb, cc,
F2,
K2, in[14], 7);
120 ROUND(cc, dd, aa, bb,
F2,
K2, in[11], 13);
121 ROUND(bb, cc, dd, aa,
F2,
K2, in[8], 12);
125 ROUND(ddd, aaa, bbb, ccc,
F3,
KK2, in[11], 13);
126 ROUND(ccc, ddd, aaa, bbb,
F3,
KK2, in[3], 15);
128 ROUND(aaa, bbb, ccc, ddd,
F3,
KK2, in[0], 12);
129 ROUND(ddd, aaa, bbb, ccc,
F3,
KK2, in[13], 8);
131 ROUND(bbb, ccc, ddd, aaa,
F3,
KK2, in[10], 11);
132 ROUND(aaa, bbb, ccc, ddd,
F3,
KK2, in[14], 7);
133 ROUND(ddd, aaa, bbb, ccc,
F3,
KK2, in[15], 7);
134 ROUND(ccc, ddd, aaa, bbb,
F3,
KK2, in[8], 12);
135 ROUND(bbb, ccc, ddd, aaa,
F3,
KK2, in[12], 7);
137 ROUND(ddd, aaa, bbb, ccc,
F3,
KK2, in[9], 15);
138 ROUND(ccc, ddd, aaa, bbb,
F3,
KK2, in[1], 13);
139 ROUND(bbb, ccc, ddd, aaa,
F3,
KK2, in[2], 11);
142 tmp =
bb; bb = bbb; bbb =
tmp;
145 ROUND(aa, bb, cc, dd,
F3,
K3, in[3], 11);
146 ROUND(dd, aa, bb, cc,
F3,
K3, in[10], 13);
147 ROUND(cc, dd, aa, bb,
F3,
K3, in[14], 6);
149 ROUND(aa, bb, cc, dd,
F3,
K3, in[9], 14);
150 ROUND(dd, aa, bb, cc,
F3,
K3, in[15], 9);
151 ROUND(cc, dd, aa, bb,
F3,
K3, in[8], 13);
152 ROUND(bb, cc, dd, aa,
F3,
K3, in[1], 15);
153 ROUND(aa, bb, cc, dd,
F3,
K3, in[2], 14);
155 ROUND(cc, dd, aa, bb,
F3,
K3, in[0], 13);
157 ROUND(aa, bb, cc, dd,
F3,
K3, in[13], 5);
158 ROUND(dd, aa, bb, cc,
F3,
K3, in[11], 12);
160 ROUND(bb, cc, dd, aa,
F3,
K3, in[12], 5);
163 ROUND(aaa, bbb, ccc, ddd,
F2,
KK3, in[15], 9);
165 ROUND(ccc, ddd, aaa, bbb,
F2,
KK3, in[1], 15);
166 ROUND(bbb, ccc, ddd, aaa,
F2,
KK3, in[3], 11);
168 ROUND(ddd, aaa, bbb, ccc,
F2,
KK3, in[14], 6);
170 ROUND(bbb, ccc, ddd, aaa,
F2,
KK3, in[9], 14);
171 ROUND(aaa, bbb, ccc, ddd,
F2,
KK3, in[11], 12);
172 ROUND(ddd, aaa, bbb, ccc,
F2,
KK3, in[8], 13);
173 ROUND(ccc, ddd, aaa, bbb,
F2,
KK3, in[12], 5);
174 ROUND(bbb, ccc, ddd, aaa,
F2,
KK3, in[2], 14);
175 ROUND(aaa, bbb, ccc, ddd,
F2,
KK3, in[10], 13);
176 ROUND(ddd, aaa, bbb, ccc,
F2,
KK3, in[0], 13);
178 ROUND(bbb, ccc, ddd, aaa,
F2,
KK3, in[13], 5);
181 tmp =
cc; cc = ccc; ccc =
tmp;
184 ROUND(aa, bb, cc, dd,
F4,
K4, in[1], 11);
185 ROUND(dd, aa, bb, cc,
F4,
K4, in[9], 12);
186 ROUND(cc, dd, aa, bb,
F4,
K4, in[11], 14);
187 ROUND(bb, cc, dd, aa,
F4,
K4, in[10], 15);
188 ROUND(aa, bb, cc, dd,
F4,
K4, in[0], 14);
189 ROUND(dd, aa, bb, cc,
F4,
K4, in[8], 15);
190 ROUND(cc, dd, aa, bb,
F4,
K4, in[12], 9);
192 ROUND(aa, bb, cc, dd,
F4,
K4, in[13], 9);
193 ROUND(dd, aa, bb, cc,
F4,
K4, in[3], 14);
195 ROUND(bb, cc, dd, aa,
F4,
K4, in[15], 6);
196 ROUND(aa, bb, cc, dd,
F4,
K4, in[14], 8);
199 ROUND(bb, cc, dd, aa,
F4,
K4, in[2], 12);
202 ROUND(aaa, bbb, ccc, ddd,
F1,
KK4, in[8], 15);
205 ROUND(bbb, ccc, ddd, aaa,
F1,
KK4, in[1], 11);
206 ROUND(aaa, bbb, ccc, ddd,
F1,
KK4, in[3], 14);
207 ROUND(ddd, aaa, bbb, ccc,
F1,
KK4, in[11], 14);
208 ROUND(ccc, ddd, aaa, bbb,
F1,
KK4, in[15], 6);
209 ROUND(bbb, ccc, ddd, aaa,
F1,
KK4, in[0], 14);
211 ROUND(ddd, aaa, bbb, ccc,
F1,
KK4, in[12], 9);
212 ROUND(ccc, ddd, aaa, bbb,
F1,
KK4, in[2], 12);
213 ROUND(bbb, ccc, ddd, aaa,
F1,
KK4, in[13], 9);
214 ROUND(aaa, bbb, ccc, ddd,
F1,
KK4, in[9], 12);
216 ROUND(ccc, ddd, aaa, bbb,
F1,
KK4, in[10], 15);
217 ROUND(bbb, ccc, ddd, aaa,
F1,
KK4, in[14], 8);
220 tmp =
dd; dd = ddd; ddd =
tmp;
237 struct rmd256_ctx *rctx = shash_desc_ctx(desc);
258 struct rmd256_ctx *rctx = shash_desc_ctx(desc);
277 while (len >=
sizeof(rctx->
buffer)) {
280 data +=
sizeof(rctx->
buffer);
281 len -=
sizeof(rctx->
buffer);
293 struct rmd256_ctx *rctx = shash_desc_ctx(desc);
303 padlen = (index < 56) ? (56 - index) : ((64+56) - index);
304 rmd256_update(desc, padding, padlen);
307 rmd256_update(desc, (
const u8 *)&bits,
sizeof(bits));
310 for (i = 0; i < 8; i++)
314 memset(rctx, 0,
sizeof(*rctx));
322 .update = rmd256_update,
323 .final = rmd256_final,
326 .cra_name =
"rmd256",
333 static int __init rmd256_mod_init(
void)
338 static void __exit rmd256_mod_fini(
void)