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;
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(ee, aa, bb, cc, dd,
F2,
K2, in[7], 7);
92 ROUND(dd, ee, aa, bb, cc,
F2,
K2, in[4], 6);
93 ROUND(cc, dd, ee, aa, bb,
F2,
K2, in[13], 8);
94 ROUND(bb, cc, dd, ee, aa,
F2,
K2, in[1], 13);
95 ROUND(aa, bb, cc, dd, ee,
F2,
K2, in[10], 11);
96 ROUND(ee, aa, bb, cc, dd,
F2,
K2, in[6], 9);
97 ROUND(dd, ee, aa, bb, cc,
F2,
K2, in[15], 7);
98 ROUND(cc, dd, ee, aa, bb,
F2,
K2, in[3], 15);
99 ROUND(bb, cc, dd, ee, aa,
F2,
K2, in[12], 7);
100 ROUND(aa, bb, cc, dd, ee,
F2,
K2, in[0], 12);
101 ROUND(ee, aa, bb, cc, dd,
F2,
K2, in[9], 15);
102 ROUND(dd, ee, aa, bb, cc,
F2,
K2, in[5], 9);
103 ROUND(cc, dd, ee, aa, bb,
F2,
K2, in[2], 11);
104 ROUND(bb, cc, dd, ee, aa,
F2,
K2, in[14], 7);
105 ROUND(aa, bb, cc, dd, ee,
F2,
K2, in[11], 13);
106 ROUND(ee, aa, bb, cc, dd,
F2,
K2, in[8], 12);
109 ROUND(dd, ee, aa, bb, cc,
F3,
K3, in[3], 11);
110 ROUND(cc, dd, ee, aa, bb,
F3,
K3, in[10], 13);
111 ROUND(bb, cc, dd, ee, aa,
F3,
K3, in[14], 6);
112 ROUND(aa, bb, cc, dd, ee,
F3,
K3, in[4], 7);
113 ROUND(ee, aa, bb, cc, dd,
F3,
K3, in[9], 14);
114 ROUND(dd, ee, aa, bb, cc,
F3,
K3, in[15], 9);
115 ROUND(cc, dd, ee, aa, bb,
F3,
K3, in[8], 13);
116 ROUND(bb, cc, dd, ee, aa,
F3,
K3, in[1], 15);
117 ROUND(aa, bb, cc, dd, ee,
F3,
K3, in[2], 14);
118 ROUND(ee, aa, bb, cc, dd,
F3,
K3, in[7], 8);
119 ROUND(dd, ee, aa, bb, cc,
F3,
K3, in[0], 13);
120 ROUND(cc, dd, ee, aa, bb,
F3,
K3, in[6], 6);
121 ROUND(bb, cc, dd, ee, aa,
F3,
K3, in[13], 5);
122 ROUND(aa, bb, cc, dd, ee,
F3,
K3, in[11], 12);
123 ROUND(ee, aa, bb, cc, dd,
F3,
K3, in[5], 7);
124 ROUND(dd, ee, aa, bb, cc,
F3,
K3, in[12], 5);
127 ROUND(cc, dd, ee, aa, bb,
F4,
K4, in[1], 11);
128 ROUND(bb, cc, dd, ee, aa,
F4,
K4, in[9], 12);
129 ROUND(aa, bb, cc, dd, ee,
F4,
K4, in[11], 14);
130 ROUND(ee, aa, bb, cc, dd,
F4,
K4, in[10], 15);
131 ROUND(dd, ee, aa, bb, cc,
F4,
K4, in[0], 14);
132 ROUND(cc, dd, ee, aa, bb,
F4,
K4, in[8], 15);
133 ROUND(bb, cc, dd, ee, aa,
F4,
K4, in[12], 9);
134 ROUND(aa, bb, cc, dd, ee,
F4,
K4, in[4], 8);
135 ROUND(ee, aa, bb, cc, dd,
F4,
K4, in[13], 9);
136 ROUND(dd, ee, aa, bb, cc,
F4,
K4, in[3], 14);
137 ROUND(cc, dd, ee, aa, bb,
F4,
K4, in[7], 5);
138 ROUND(bb, cc, dd, ee, aa,
F4,
K4, in[15], 6);
139 ROUND(aa, bb, cc, dd, ee,
F4,
K4, in[14], 8);
140 ROUND(ee, aa, bb, cc, dd,
F4,
K4, in[5], 6);
141 ROUND(dd, ee, aa, bb, cc,
F4,
K4, in[6], 5);
142 ROUND(cc, dd, ee, aa, bb,
F4,
K4, in[2], 12);
145 ROUND(bb, cc, dd, ee, aa,
F5,
K5, in[4], 9);
146 ROUND(aa, bb, cc, dd, ee,
F5,
K5, in[0], 15);
147 ROUND(ee, aa, bb, cc, dd,
F5,
K5, in[5], 5);
148 ROUND(dd, ee, aa, bb, cc,
F5,
K5, in[9], 11);
149 ROUND(cc, dd, ee, aa, bb,
F5,
K5, in[7], 6);
150 ROUND(bb, cc, dd, ee, aa,
F5,
K5, in[12], 8);
151 ROUND(aa, bb, cc, dd, ee,
F5,
K5, in[2], 13);
152 ROUND(ee, aa, bb, cc, dd,
F5,
K5, in[10], 12);
153 ROUND(dd, ee, aa, bb, cc,
F5,
K5, in[14], 5);
154 ROUND(cc, dd, ee, aa, bb,
F5,
K5, in[1], 12);
155 ROUND(bb, cc, dd, ee, aa,
F5,
K5, in[3], 13);
156 ROUND(aa, bb, cc, dd, ee,
F5,
K5, in[8], 14);
157 ROUND(ee, aa, bb, cc, dd,
F5,
K5, in[11], 11);
158 ROUND(dd, ee, aa, bb, cc,
F5,
K5, in[6], 8);
159 ROUND(cc, dd, ee, aa, bb,
F5,
K5, in[15], 5);
160 ROUND(bb, cc, dd, ee, aa,
F5,
K5, in[13], 6);
163 ROUND(aaa, bbb, ccc, ddd, eee,
F5,
KK1, in[5], 8);
164 ROUND(eee, aaa, bbb, ccc, ddd,
F5,
KK1, in[14], 9);
165 ROUND(ddd, eee, aaa, bbb, ccc,
F5,
KK1, in[7], 9);
166 ROUND(ccc, ddd, eee, aaa, bbb,
F5,
KK1, in[0], 11);
167 ROUND(bbb, ccc, ddd, eee, aaa,
F5,
KK1, in[9], 13);
168 ROUND(aaa, bbb, ccc, ddd, eee,
F5,
KK1, in[2], 15);
169 ROUND(eee, aaa, bbb, ccc, ddd,
F5,
KK1, in[11], 15);
170 ROUND(ddd, eee, aaa, bbb, ccc,
F5,
KK1, in[4], 5);
171 ROUND(ccc, ddd, eee, aaa, bbb,
F5,
KK1, in[13], 7);
172 ROUND(bbb, ccc, ddd, eee, aaa,
F5,
KK1, in[6], 7);
173 ROUND(aaa, bbb, ccc, ddd, eee,
F5,
KK1, in[15], 8);
174 ROUND(eee, aaa, bbb, ccc, ddd,
F5,
KK1, in[8], 11);
175 ROUND(ddd, eee, aaa, bbb, ccc,
F5,
KK1, in[1], 14);
176 ROUND(ccc, ddd, eee, aaa, bbb,
F5,
KK1, in[10], 14);
177 ROUND(bbb, ccc, ddd, eee, aaa,
F5,
KK1, in[3], 12);
178 ROUND(aaa, bbb, ccc, ddd, eee,
F5,
KK1, in[12], 6);
181 ROUND(eee, aaa, bbb, ccc, ddd,
F4,
KK2, in[6], 9);
182 ROUND(ddd, eee, aaa, bbb, ccc,
F4,
KK2, in[11], 13);
183 ROUND(ccc, ddd, eee, aaa, bbb,
F4,
KK2, in[3], 15);
184 ROUND(bbb, ccc, ddd, eee, aaa,
F4,
KK2, in[7], 7);
185 ROUND(aaa, bbb, ccc, ddd, eee,
F4,
KK2, in[0], 12);
186 ROUND(eee, aaa, bbb, ccc, ddd,
F4,
KK2, in[13], 8);
187 ROUND(ddd, eee, aaa, bbb, ccc,
F4,
KK2, in[5], 9);
188 ROUND(ccc, ddd, eee, aaa, bbb,
F4,
KK2, in[10], 11);
189 ROUND(bbb, ccc, ddd, eee, aaa,
F4,
KK2, in[14], 7);
190 ROUND(aaa, bbb, ccc, ddd, eee,
F4,
KK2, in[15], 7);
191 ROUND(eee, aaa, bbb, ccc, ddd,
F4,
KK2, in[8], 12);
192 ROUND(ddd, eee, aaa, bbb, ccc,
F4,
KK2, in[12], 7);
193 ROUND(ccc, ddd, eee, aaa, bbb,
F4,
KK2, in[4], 6);
194 ROUND(bbb, ccc, ddd, eee, aaa,
F4,
KK2, in[9], 15);
195 ROUND(aaa, bbb, ccc, ddd, eee,
F4,
KK2, in[1], 13);
196 ROUND(eee, aaa, bbb, ccc, ddd,
F4,
KK2, in[2], 11);
199 ROUND(ddd, eee, aaa, bbb, ccc,
F3,
KK3, in[15], 9);
200 ROUND(ccc, ddd, eee, aaa, bbb,
F3,
KK3, in[5], 7);
201 ROUND(bbb, ccc, ddd, eee, aaa,
F3,
KK3, in[1], 15);
202 ROUND(aaa, bbb, ccc, ddd, eee,
F3,
KK3, in[3], 11);
203 ROUND(eee, aaa, bbb, ccc, ddd,
F3,
KK3, in[7], 8);
204 ROUND(ddd, eee, aaa, bbb, ccc,
F3,
KK3, in[14], 6);
205 ROUND(ccc, ddd, eee, aaa, bbb,
F3,
KK3, in[6], 6);
206 ROUND(bbb, ccc, ddd, eee, aaa,
F3,
KK3, in[9], 14);
207 ROUND(aaa, bbb, ccc, ddd, eee,
F3,
KK3, in[11], 12);
208 ROUND(eee, aaa, bbb, ccc, ddd,
F3,
KK3, in[8], 13);
209 ROUND(ddd, eee, aaa, bbb, ccc,
F3,
KK3, in[12], 5);
210 ROUND(ccc, ddd, eee, aaa, bbb,
F3,
KK3, in[2], 14);
211 ROUND(bbb, ccc, ddd, eee, aaa,
F3,
KK3, in[10], 13);
212 ROUND(aaa, bbb, ccc, ddd, eee,
F3,
KK3, in[0], 13);
213 ROUND(eee, aaa, bbb, ccc, ddd,
F3,
KK3, in[4], 7);
214 ROUND(ddd, eee, aaa, bbb, ccc,
F3,
KK3, in[13], 5);
217 ROUND(ccc, ddd, eee, aaa, bbb,
F2,
KK4, in[8], 15);
218 ROUND(bbb, ccc, ddd, eee, aaa,
F2,
KK4, in[6], 5);
219 ROUND(aaa, bbb, ccc, ddd, eee,
F2,
KK4, in[4], 8);
220 ROUND(eee, aaa, bbb, ccc, ddd,
F2,
KK4, in[1], 11);
221 ROUND(ddd, eee, aaa, bbb, ccc,
F2,
KK4, in[3], 14);
222 ROUND(ccc, ddd, eee, aaa, bbb,
F2,
KK4, in[11], 14);
223 ROUND(bbb, ccc, ddd, eee, aaa,
F2,
KK4, in[15], 6);
224 ROUND(aaa, bbb, ccc, ddd, eee,
F2,
KK4, in[0], 14);
225 ROUND(eee, aaa, bbb, ccc, ddd,
F2,
KK4, in[5], 6);
226 ROUND(ddd, eee, aaa, bbb, ccc,
F2,
KK4, in[12], 9);
227 ROUND(ccc, ddd, eee, aaa, bbb,
F2,
KK4, in[2], 12);
228 ROUND(bbb, ccc, ddd, eee, aaa,
F2,
KK4, in[13], 9);
229 ROUND(aaa, bbb, ccc, ddd, eee,
F2,
KK4, in[9], 12);
230 ROUND(eee, aaa, bbb, ccc, ddd,
F2,
KK4, in[7], 5);
231 ROUND(ddd, eee, aaa, bbb, ccc,
F2,
KK4, in[10], 15);
232 ROUND(ccc, ddd, eee, aaa, bbb,
F2,
KK4, in[14], 8);
235 ROUND(bbb, ccc, ddd, eee, aaa,
F1,
KK5, in[12], 8);
236 ROUND(aaa, bbb, ccc, ddd, eee,
F1,
KK5, in[15], 5);
237 ROUND(eee, aaa, bbb, ccc, ddd,
F1,
KK5, in[10], 12);
238 ROUND(ddd, eee, aaa, bbb, ccc,
F1,
KK5, in[4], 9);
239 ROUND(ccc, ddd, eee, aaa, bbb,
F1,
KK5, in[1], 12);
240 ROUND(bbb, ccc, ddd, eee, aaa,
F1,
KK5, in[5], 5);
241 ROUND(aaa, bbb, ccc, ddd, eee,
F1,
KK5, in[8], 14);
242 ROUND(eee, aaa, bbb, ccc, ddd,
F1,
KK5, in[7], 6);
243 ROUND(ddd, eee, aaa, bbb, ccc,
F1,
KK5, in[6], 8);
244 ROUND(ccc, ddd, eee, aaa, bbb,
F1,
KK5, in[2], 13);
245 ROUND(bbb, ccc, ddd, eee, aaa,
F1,
KK5, in[13], 6);
246 ROUND(aaa, bbb, ccc, ddd, eee,
F1,
KK5, in[14], 5);
247 ROUND(eee, aaa, bbb, ccc, ddd,
F1,
KK5, in[0], 15);
248 ROUND(ddd, eee, aaa, bbb, ccc,
F1,
KK5, in[3], 13);
249 ROUND(ccc, ddd, eee, aaa, bbb,
F1,
KK5, in[9], 11);
250 ROUND(bbb, ccc, ddd, eee, aaa,
F1,
KK5, in[11], 11);
253 ddd += cc + state[1];
254 state[1] = state[2] + dd + eee;
255 state[2] = state[3] + ee + aaa;
256 state[3] = state[4] + aa + bbb;
257 state[4] = state[0] + bb + ccc;
265 struct rmd160_ctx *rctx = shash_desc_ctx(desc);
283 struct rmd160_ctx *rctx = shash_desc_ctx(desc);
302 while (len >=
sizeof(rctx->
buffer)) {
305 data +=
sizeof(rctx->
buffer);
306 len -=
sizeof(rctx->
buffer);
318 struct rmd160_ctx *rctx = shash_desc_ctx(desc);
328 padlen = (index < 56) ? (56 - index) : ((64+56) - index);
329 rmd160_update(desc, padding, padlen);
332 rmd160_update(desc, (
const u8 *)&bits,
sizeof(bits));
335 for (i = 0; i < 5; i++)
339 memset(rctx, 0,
sizeof(*rctx));
347 .update = rmd160_update,
348 .final = rmd160_final,
351 .cra_name =
"rmd160",
358 static int __init rmd160_mod_init(
void)
363 static void __exit rmd160_mod_fini(
void)