18 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <asm/byteorder.h>
42 #define F1(x, y, z) (x ^ y ^ z)
43 #define F2(x, y, z) (z ^ (x & (y ^ z)))
44 #define F3(x, y, z) ((x | ~y) ^ z)
45 #define F4(x, y, z) (y ^ (z & (x ^ y)))
46 #define F5(x, y, z) (x ^ (y | ~z))
48 #define ROUND(a, b, c, d, e, f, k, x, s) { \
49 (a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
50 (a) = rol32((a), (s)) + (e); \
51 (c) = rol32((c), 10); \
56 u32 aa,
bb,
cc,
dd, ee, aaa, bbb, ccc, ddd, eee,
tmp;
73 ROUND(aa, bb, cc, dd, ee,
F1,
K1, in[0], 11);
74 ROUND(ee, aa, bb, cc, dd,
F1,
K1, in[1], 14);
75 ROUND(dd, ee, aa, bb, cc,
F1,
K1, in[2], 15);
76 ROUND(cc, dd, ee, aa, bb,
F1,
K1, in[3], 12);
77 ROUND(bb, cc, dd, ee, aa,
F1,
K1, in[4], 5);
78 ROUND(aa, bb, cc, dd, ee,
F1,
K1, in[5], 8);
79 ROUND(ee, aa, bb, cc, dd,
F1,
K1, in[6], 7);
80 ROUND(dd, ee, aa, bb, cc,
F1,
K1, in[7], 9);
81 ROUND(cc, dd, ee, aa, bb,
F1,
K1, in[8], 11);
82 ROUND(bb, cc, dd, ee, aa,
F1,
K1, in[9], 13);
83 ROUND(aa, bb, cc, dd, ee,
F1,
K1, in[10], 14);
84 ROUND(ee, aa, bb, cc, dd,
F1,
K1, in[11], 15);
85 ROUND(dd, ee, aa, bb, cc,
F1,
K1, in[12], 6);
86 ROUND(cc, dd, ee, aa, bb,
F1,
K1, in[13], 7);
87 ROUND(bb, cc, dd, ee, aa,
F1,
K1, in[14], 9);
88 ROUND(aa, bb, cc, dd, ee,
F1,
K1, in[15], 8);
91 ROUND(aaa, bbb, ccc, ddd, eee,
F5,
KK1, in[5], 8);
92 ROUND(eee, aaa, bbb, ccc, ddd,
F5,
KK1, in[14], 9);
93 ROUND(ddd, eee, aaa, bbb, ccc,
F5,
KK1, in[7], 9);
94 ROUND(ccc, ddd, eee, aaa, bbb,
F5,
KK1, in[0], 11);
95 ROUND(bbb, ccc, ddd, eee, aaa,
F5,
KK1, in[9], 13);
96 ROUND(aaa, bbb, ccc, ddd, eee,
F5,
KK1, in[2], 15);
97 ROUND(eee, aaa, bbb, ccc, ddd,
F5,
KK1, in[11], 15);
98 ROUND(ddd, eee, aaa, bbb, ccc,
F5,
KK1, in[4], 5);
99 ROUND(ccc, ddd, eee, aaa, bbb,
F5,
KK1, in[13], 7);
100 ROUND(bbb, ccc, ddd, eee, aaa,
F5,
KK1, in[6], 7);
101 ROUND(aaa, bbb, ccc, ddd, eee,
F5,
KK1, in[15], 8);
102 ROUND(eee, aaa, bbb, ccc, ddd,
F5,
KK1, in[8], 11);
103 ROUND(ddd, eee, aaa, bbb, ccc,
F5,
KK1, in[1], 14);
104 ROUND(ccc, ddd, eee, aaa, bbb,
F5,
KK1, in[10], 14);
105 ROUND(bbb, ccc, ddd, eee, aaa,
F5,
KK1, in[3], 12);
106 ROUND(aaa, bbb, ccc, ddd, eee,
F5,
KK1, in[12], 6);
109 tmp = aa; aa = aaa; aaa =
tmp;
112 ROUND(ee, aa, bb, cc, dd,
F2,
K2, in[7], 7);
113 ROUND(dd, ee, aa, bb, cc,
F2,
K2, in[4], 6);
114 ROUND(cc, dd, ee, aa, bb,
F2,
K2, in[13], 8);
115 ROUND(bb, cc, dd, ee, aa,
F2,
K2, in[1], 13);
116 ROUND(aa, bb, cc, dd, ee,
F2,
K2, in[10], 11);
117 ROUND(ee, aa, bb, cc, dd,
F2,
K2, in[6], 9);
118 ROUND(dd, ee, aa, bb, cc,
F2,
K2, in[15], 7);
119 ROUND(cc, dd, ee, aa, bb,
F2,
K2, in[3], 15);
120 ROUND(bb, cc, dd, ee, aa,
F2,
K2, in[12], 7);
121 ROUND(aa, bb, cc, dd, ee,
F2,
K2, in[0], 12);
122 ROUND(ee, aa, bb, cc, dd,
F2,
K2, in[9], 15);
123 ROUND(dd, ee, aa, bb, cc,
F2,
K2, in[5], 9);
124 ROUND(cc, dd, ee, aa, bb,
F2,
K2, in[2], 11);
125 ROUND(bb, cc, dd, ee, aa,
F2,
K2, in[14], 7);
126 ROUND(aa, bb, cc, dd, ee,
F2,
K2, in[11], 13);
127 ROUND(ee, aa, bb, cc, dd,
F2,
K2, in[8], 12);
130 ROUND(eee, aaa, bbb, ccc, ddd,
F4,
KK2, in[6], 9);
131 ROUND(ddd, eee, aaa, bbb, ccc,
F4,
KK2, in[11], 13);
132 ROUND(ccc, ddd, eee, aaa, bbb,
F4,
KK2, in[3], 15);
133 ROUND(bbb, ccc, ddd, eee, aaa,
F4,
KK2, in[7], 7);
134 ROUND(aaa, bbb, ccc, ddd, eee,
F4,
KK2, in[0], 12);
135 ROUND(eee, aaa, bbb, ccc, ddd,
F4,
KK2, in[13], 8);
136 ROUND(ddd, eee, aaa, bbb, ccc,
F4,
KK2, in[5], 9);
137 ROUND(ccc, ddd, eee, aaa, bbb,
F4,
KK2, in[10], 11);
138 ROUND(bbb, ccc, ddd, eee, aaa,
F4,
KK2, in[14], 7);
139 ROUND(aaa, bbb, ccc, ddd, eee,
F4,
KK2, in[15], 7);
140 ROUND(eee, aaa, bbb, ccc, ddd,
F4,
KK2, in[8], 12);
141 ROUND(ddd, eee, aaa, bbb, ccc,
F4,
KK2, in[12], 7);
142 ROUND(ccc, ddd, eee, aaa, bbb,
F4,
KK2, in[4], 6);
143 ROUND(bbb, ccc, ddd, eee, aaa,
F4,
KK2, in[9], 15);
144 ROUND(aaa, bbb, ccc, ddd, eee,
F4,
KK2, in[1], 13);
145 ROUND(eee, aaa, bbb, ccc, ddd,
F4,
KK2, in[2], 11);
148 tmp =
bb; bb = bbb; bbb =
tmp;
151 ROUND(dd, ee, aa, bb, cc,
F3,
K3, in[3], 11);
152 ROUND(cc, dd, ee, aa, bb,
F3,
K3, in[10], 13);
153 ROUND(bb, cc, dd, ee, aa,
F3,
K3, in[14], 6);
154 ROUND(aa, bb, cc, dd, ee,
F3,
K3, in[4], 7);
155 ROUND(ee, aa, bb, cc, dd,
F3,
K3, in[9], 14);
156 ROUND(dd, ee, aa, bb, cc,
F3,
K3, in[15], 9);
157 ROUND(cc, dd, ee, aa, bb,
F3,
K3, in[8], 13);
158 ROUND(bb, cc, dd, ee, aa,
F3,
K3, in[1], 15);
159 ROUND(aa, bb, cc, dd, ee,
F3,
K3, in[2], 14);
160 ROUND(ee, aa, bb, cc, dd,
F3,
K3, in[7], 8);
161 ROUND(dd, ee, aa, bb, cc,
F3,
K3, in[0], 13);
162 ROUND(cc, dd, ee, aa, bb,
F3,
K3, in[6], 6);
163 ROUND(bb, cc, dd, ee, aa,
F3,
K3, in[13], 5);
164 ROUND(aa, bb, cc, dd, ee,
F3,
K3, in[11], 12);
165 ROUND(ee, aa, bb, cc, dd,
F3,
K3, in[5], 7);
166 ROUND(dd, ee, aa, bb, cc,
F3,
K3, in[12], 5);
169 ROUND(ddd, eee, aaa, bbb, ccc,
F3,
KK3, in[15], 9);
170 ROUND(ccc, ddd, eee, aaa, bbb,
F3,
KK3, in[5], 7);
171 ROUND(bbb, ccc, ddd, eee, aaa,
F3,
KK3, in[1], 15);
172 ROUND(aaa, bbb, ccc, ddd, eee,
F3,
KK3, in[3], 11);
173 ROUND(eee, aaa, bbb, ccc, ddd,
F3,
KK3, in[7], 8);
174 ROUND(ddd, eee, aaa, bbb, ccc,
F3,
KK3, in[14], 6);
175 ROUND(ccc, ddd, eee, aaa, bbb,
F3,
KK3, in[6], 6);
176 ROUND(bbb, ccc, ddd, eee, aaa,
F3,
KK3, in[9], 14);
177 ROUND(aaa, bbb, ccc, ddd, eee,
F3,
KK3, in[11], 12);
178 ROUND(eee, aaa, bbb, ccc, ddd,
F3,
KK3, in[8], 13);
179 ROUND(ddd, eee, aaa, bbb, ccc,
F3,
KK3, in[12], 5);
180 ROUND(ccc, ddd, eee, aaa, bbb,
F3,
KK3, in[2], 14);
181 ROUND(bbb, ccc, ddd, eee, aaa,
F3,
KK3, in[10], 13);
182 ROUND(aaa, bbb, ccc, ddd, eee,
F3,
KK3, in[0], 13);
183 ROUND(eee, aaa, bbb, ccc, ddd,
F3,
KK3, in[4], 7);
184 ROUND(ddd, eee, aaa, bbb, ccc,
F3,
KK3, in[13], 5);
187 tmp =
cc; cc = ccc; ccc =
tmp;
190 ROUND(cc, dd, ee, aa, bb,
F4,
K4, in[1], 11);
191 ROUND(bb, cc, dd, ee, aa,
F4,
K4, in[9], 12);
192 ROUND(aa, bb, cc, dd, ee,
F4,
K4, in[11], 14);
193 ROUND(ee, aa, bb, cc, dd,
F4,
K4, in[10], 15);
194 ROUND(dd, ee, aa, bb, cc,
F4,
K4, in[0], 14);
195 ROUND(cc, dd, ee, aa, bb,
F4,
K4, in[8], 15);
196 ROUND(bb, cc, dd, ee, aa,
F4,
K4, in[12], 9);
197 ROUND(aa, bb, cc, dd, ee,
F4,
K4, in[4], 8);
198 ROUND(ee, aa, bb, cc, dd,
F4,
K4, in[13], 9);
199 ROUND(dd, ee, aa, bb, cc,
F4,
K4, in[3], 14);
200 ROUND(cc, dd, ee, aa, bb,
F4,
K4, in[7], 5);
201 ROUND(bb, cc, dd, ee, aa,
F4,
K4, in[15], 6);
202 ROUND(aa, bb, cc, dd, ee,
F4,
K4, in[14], 8);
203 ROUND(ee, aa, bb, cc, dd,
F4,
K4, in[5], 6);
204 ROUND(dd, ee, aa, bb, cc,
F4,
K4, in[6], 5);
205 ROUND(cc, dd, ee, aa, bb,
F4,
K4, in[2], 12);
208 ROUND(ccc, ddd, eee, aaa, bbb,
F2,
KK4, in[8], 15);
209 ROUND(bbb, ccc, ddd, eee, aaa,
F2,
KK4, in[6], 5);
210 ROUND(aaa, bbb, ccc, ddd, eee,
F2,
KK4, in[4], 8);
211 ROUND(eee, aaa, bbb, ccc, ddd,
F2,
KK4, in[1], 11);
212 ROUND(ddd, eee, aaa, bbb, ccc,
F2,
KK4, in[3], 14);
213 ROUND(ccc, ddd, eee, aaa, bbb,
F2,
KK4, in[11], 14);
214 ROUND(bbb, ccc, ddd, eee, aaa,
F2,
KK4, in[15], 6);
215 ROUND(aaa, bbb, ccc, ddd, eee,
F2,
KK4, in[0], 14);
216 ROUND(eee, aaa, bbb, ccc, ddd,
F2,
KK4, in[5], 6);
217 ROUND(ddd, eee, aaa, bbb, ccc,
F2,
KK4, in[12], 9);
218 ROUND(ccc, ddd, eee, aaa, bbb,
F2,
KK4, in[2], 12);
219 ROUND(bbb, ccc, ddd, eee, aaa,
F2,
KK4, in[13], 9);
220 ROUND(aaa, bbb, ccc, ddd, eee,
F2,
KK4, in[9], 12);
221 ROUND(eee, aaa, bbb, ccc, ddd,
F2,
KK4, in[7], 5);
222 ROUND(ddd, eee, aaa, bbb, ccc,
F2,
KK4, in[10], 15);
223 ROUND(ccc, ddd, eee, aaa, bbb,
F2,
KK4, in[14], 8);
226 tmp =
dd; dd = ddd; ddd =
tmp;
229 ROUND(bb, cc, dd, ee, aa,
F5,
K5, in[4], 9);
230 ROUND(aa, bb, cc, dd, ee,
F5,
K5, in[0], 15);
231 ROUND(ee, aa, bb, cc, dd,
F5,
K5, in[5], 5);
232 ROUND(dd, ee, aa, bb, cc,
F5,
K5, in[9], 11);
233 ROUND(cc, dd, ee, aa, bb,
F5,
K5, in[7], 6);
234 ROUND(bb, cc, dd, ee, aa,
F5,
K5, in[12], 8);
235 ROUND(aa, bb, cc, dd, ee,
F5,
K5, in[2], 13);
236 ROUND(ee, aa, bb, cc, dd,
F5,
K5, in[10], 12);
237 ROUND(dd, ee, aa, bb, cc,
F5,
K5, in[14], 5);
238 ROUND(cc, dd, ee, aa, bb,
F5,
K5, in[1], 12);
239 ROUND(bb, cc, dd, ee, aa,
F5,
K5, in[3], 13);
240 ROUND(aa, bb, cc, dd, ee,
F5,
K5, in[8], 14);
241 ROUND(ee, aa, bb, cc, dd,
F5,
K5, in[11], 11);
242 ROUND(dd, ee, aa, bb, cc,
F5,
K5, in[6], 8);
243 ROUND(cc, dd, ee, aa, bb,
F5,
K5, in[15], 5);
244 ROUND(bb, cc, dd, ee, aa,
F5,
K5, in[13], 6);
247 ROUND(bbb, ccc, ddd, eee, aaa,
F1,
KK5, in[12], 8);
248 ROUND(aaa, bbb, ccc, ddd, eee,
F1,
KK5, in[15], 5);
249 ROUND(eee, aaa, bbb, ccc, ddd,
F1,
KK5, in[10], 12);
250 ROUND(ddd, eee, aaa, bbb, ccc,
F1,
KK5, in[4], 9);
251 ROUND(ccc, ddd, eee, aaa, bbb,
F1,
KK5, in[1], 12);
252 ROUND(bbb, ccc, ddd, eee, aaa,
F1,
KK5, in[5], 5);
253 ROUND(aaa, bbb, ccc, ddd, eee,
F1,
KK5, in[8], 14);
254 ROUND(eee, aaa, bbb, ccc, ddd,
F1,
KK5, in[7], 6);
255 ROUND(ddd, eee, aaa, bbb, ccc,
F1,
KK5, in[6], 8);
256 ROUND(ccc, ddd, eee, aaa, bbb,
F1,
KK5, in[2], 13);
257 ROUND(bbb, ccc, ddd, eee, aaa,
F1,
KK5, in[13], 6);
258 ROUND(aaa, bbb, ccc, ddd, eee,
F1,
KK5, in[14], 5);
259 ROUND(eee, aaa, bbb, ccc, ddd,
F1,
KK5, in[0], 15);
260 ROUND(ddd, eee, aaa, bbb, ccc,
F1,
KK5, in[3], 13);
261 ROUND(ccc, ddd, eee, aaa, bbb,
F1,
KK5, in[9], 11);
262 ROUND(bbb, ccc, ddd, eee, aaa,
F1,
KK5, in[11], 11);
265 tmp = ee; ee = eee; eee =
tmp;
284 struct rmd320_ctx *rctx = shash_desc_ctx(desc);
307 struct rmd320_ctx *rctx = shash_desc_ctx(desc);
326 while (len >=
sizeof(rctx->
buffer)) {
329 data +=
sizeof(rctx->
buffer);
330 len -=
sizeof(rctx->
buffer);
342 struct rmd320_ctx *rctx = shash_desc_ctx(desc);
352 padlen = (index < 56) ? (56 - index) : ((64+56) - index);
353 rmd320_update(desc, padding, padlen);
356 rmd320_update(desc, (
const u8 *)&bits,
sizeof(bits));
359 for (i = 0; i < 10; i++)
363 memset(rctx, 0,
sizeof(*rctx));
371 .update = rmd320_update,
372 .final = rmd320_final,
375 .cra_name =
"rmd320",
382 static int __init rmd320_mod_init(
void)
387 static void __exit rmd320_mod_fini(
void)