Commit c928a0cddd070720268013fd012508059aa3de5a
Committed by
Herbert Xu
1 parent
0f923a2aab
[CRYPTO] rmd160: Fix endian issues
This patch fixes endian issues making rmd160 work properly on big-endian machines. Signed-off-by: Adrian-Ken Rueegsegger <rueegsegger@swiss-it.ch> Acked-by: Sebastian Siewior <sebastian@breakpoint.cc> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 1 changed file with 9 additions and 28 deletions Side-by-side Diff
crypto/rmd160.c
... | ... | @@ -47,7 +47,7 @@ |
47 | 47 | #define F5(x, y, z) (x ^ (y | ~z)) |
48 | 48 | |
49 | 49 | #define ROUND(a, b, c, d, e, f, k, x, s) { \ |
50 | - (a) += f((b), (c), (d)) + (x) + (k); \ | |
50 | + (a) += f((b), (c), (d)) + le32_to_cpu(x) + (k); \ | |
51 | 51 | (a) = rol32((a), (s)) + (e); \ |
52 | 52 | (c) = rol32((c), 10); \ |
53 | 53 | } |
... | ... | @@ -261,28 +261,6 @@ |
261 | 261 | return; |
262 | 262 | } |
263 | 263 | |
264 | -static inline void le32_to_cpu_array(u32 *buf, unsigned int words) | |
265 | -{ | |
266 | - while (words--) { | |
267 | - le32_to_cpus(buf); | |
268 | - buf++; | |
269 | - } | |
270 | -} | |
271 | - | |
272 | -static inline void cpu_to_le32_array(u32 *buf, unsigned int words) | |
273 | -{ | |
274 | - while (words--) { | |
275 | - cpu_to_le32s(buf); | |
276 | - buf++; | |
277 | - } | |
278 | -} | |
279 | - | |
280 | -static inline void rmd160_transform_helper(struct rmd160_ctx *ctx) | |
281 | -{ | |
282 | - le32_to_cpu_array(ctx->buffer, sizeof(ctx->buffer) / sizeof(u32)); | |
283 | - rmd160_transform(ctx->state, ctx->buffer); | |
284 | -} | |
285 | - | |
286 | 264 | static void rmd160_init(struct crypto_tfm *tfm) |
287 | 265 | { |
288 | 266 | struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm); |
289 | 267 | |
... | ... | @@ -316,13 +294,13 @@ |
316 | 294 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), |
317 | 295 | data, avail); |
318 | 296 | |
319 | - rmd160_transform_helper(rctx); | |
297 | + rmd160_transform(rctx->state, rctx->buffer); | |
320 | 298 | data += avail; |
321 | 299 | len -= avail; |
322 | 300 | |
323 | 301 | while (len >= sizeof(rctx->buffer)) { |
324 | 302 | memcpy(rctx->buffer, data, sizeof(rctx->buffer)); |
325 | - rmd160_transform_helper(rctx); | |
303 | + rmd160_transform(rctx->state, rctx->buffer); | |
326 | 304 | data += sizeof(rctx->buffer); |
327 | 305 | len -= sizeof(rctx->buffer); |
328 | 306 | } |
329 | 307 | |
330 | 308 | |
331 | 309 | |
... | ... | @@ -334,11 +312,13 @@ |
334 | 312 | static void rmd160_final(struct crypto_tfm *tfm, u8 *out) |
335 | 313 | { |
336 | 314 | struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm); |
337 | - u32 index, padlen; | |
315 | + u32 i, index, padlen; | |
338 | 316 | u64 bits; |
317 | + u32 *dst = (u32 *)out; | |
339 | 318 | static const u8 padding[64] = { 0x80, }; |
340 | - bits = rctx->byte_count << 3; | |
341 | 319 | |
320 | + bits = cpu_to_le64(rctx->byte_count << 3); | |
321 | + | |
342 | 322 | /* Pad out to 56 mod 64 */ |
343 | 323 | index = rctx->byte_count & 0x3f; |
344 | 324 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); |
... | ... | @@ -348,7 +328,8 @@ |
348 | 328 | rmd160_update(tfm, (const u8 *)&bits, sizeof(bits)); |
349 | 329 | |
350 | 330 | /* Store state in digest */ |
351 | - memcpy(out, rctx->state, sizeof(rctx->state)); | |
331 | + for (i = 0; i < 5; i++) | |
332 | + dst[i] = cpu_to_le32(rctx->state[i]); | |
352 | 333 | |
353 | 334 | /* Wipe context */ |
354 | 335 | memset(rctx, 0, sizeof(*rctx)); |