diff options
Diffstat (limited to 'crypto/rmd320.c')
-rw-r--r-- | crypto/rmd320.c | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/crypto/rmd320.c b/crypto/rmd320.c index b39c0543a8fa..5b172f89e0c9 100644 --- a/crypto/rmd320.c +++ b/crypto/rmd320.c | |||
@@ -47,7 +47,7 @@ struct rmd320_ctx { | |||
47 | #define F5(x, y, z) (x ^ (y | ~z)) | 47 | #define F5(x, y, z) (x ^ (y | ~z)) |
48 | 48 | ||
49 | #define ROUND(a, b, c, d, e, f, k, x, s) { \ | 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 | (a) = rol32((a), (s)) + (e); \ | 51 | (a) = rol32((a), (s)) + (e); \ |
52 | (c) = rol32((c), 10); \ | 52 | (c) = rol32((c), 10); \ |
53 | } | 53 | } |
@@ -280,28 +280,6 @@ static void rmd320_transform(u32 *state, u32 const *in) | |||
280 | return; | 280 | return; |
281 | } | 281 | } |
282 | 282 | ||
283 | static inline void le32_to_cpu_array(u32 *buf, unsigned int words) | ||
284 | { | ||
285 | while (words--) { | ||
286 | le32_to_cpus(buf); | ||
287 | buf++; | ||
288 | } | ||
289 | } | ||
290 | |||
291 | static inline void cpu_to_le32_array(u32 *buf, unsigned int words) | ||
292 | { | ||
293 | while (words--) { | ||
294 | cpu_to_le32s(buf); | ||
295 | buf++; | ||
296 | } | ||
297 | } | ||
298 | |||
299 | static inline void rmd320_transform_helper(struct rmd320_ctx *ctx) | ||
300 | { | ||
301 | le32_to_cpu_array(ctx->buffer, sizeof(ctx->buffer) / sizeof(u32)); | ||
302 | rmd320_transform(ctx->state, ctx->buffer); | ||
303 | } | ||
304 | |||
305 | static void rmd320_init(struct crypto_tfm *tfm) | 283 | static void rmd320_init(struct crypto_tfm *tfm) |
306 | { | 284 | { |
307 | struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); | 285 | struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); |
@@ -340,13 +318,13 @@ static void rmd320_update(struct crypto_tfm *tfm, const u8 *data, | |||
340 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), | 318 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), |
341 | data, avail); | 319 | data, avail); |
342 | 320 | ||
343 | rmd320_transform_helper(rctx); | 321 | rmd320_transform(rctx->state, rctx->buffer); |
344 | data += avail; | 322 | data += avail; |
345 | len -= avail; | 323 | len -= avail; |
346 | 324 | ||
347 | while (len >= sizeof(rctx->buffer)) { | 325 | while (len >= sizeof(rctx->buffer)) { |
348 | memcpy(rctx->buffer, data, sizeof(rctx->buffer)); | 326 | memcpy(rctx->buffer, data, sizeof(rctx->buffer)); |
349 | rmd320_transform_helper(rctx); | 327 | rmd320_transform(rctx->state, rctx->buffer); |
350 | data += sizeof(rctx->buffer); | 328 | data += sizeof(rctx->buffer); |
351 | len -= sizeof(rctx->buffer); | 329 | len -= sizeof(rctx->buffer); |
352 | } | 330 | } |
@@ -358,10 +336,12 @@ static void rmd320_update(struct crypto_tfm *tfm, const u8 *data, | |||
358 | static void rmd320_final(struct crypto_tfm *tfm, u8 *out) | 336 | static void rmd320_final(struct crypto_tfm *tfm, u8 *out) |
359 | { | 337 | { |
360 | struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); | 338 | struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); |
361 | u32 index, padlen; | 339 | u32 i, index, padlen; |
362 | u64 bits; | 340 | u64 bits; |
341 | u32 *dst = (u32 *)out; | ||
363 | static const u8 padding[64] = { 0x80, }; | 342 | static const u8 padding[64] = { 0x80, }; |
364 | bits = rctx->byte_count << 3; | 343 | |
344 | bits = cpu_to_le64(rctx->byte_count << 3); | ||
365 | 345 | ||
366 | /* Pad out to 56 mod 64 */ | 346 | /* Pad out to 56 mod 64 */ |
367 | index = rctx->byte_count & 0x3f; | 347 | index = rctx->byte_count & 0x3f; |
@@ -372,7 +352,8 @@ static void rmd320_final(struct crypto_tfm *tfm, u8 *out) | |||
372 | rmd320_update(tfm, (const u8 *)&bits, sizeof(bits)); | 352 | rmd320_update(tfm, (const u8 *)&bits, sizeof(bits)); |
373 | 353 | ||
374 | /* Store state in digest */ | 354 | /* Store state in digest */ |
375 | memcpy(out, rctx->state, sizeof(rctx->state)); | 355 | for (i = 0; i < 10; i++) |
356 | dst[i] = cpu_to_le32(rctx->state[i]); | ||
376 | 357 | ||
377 | /* Wipe context */ | 358 | /* Wipe context */ |
378 | memset(rctx, 0, sizeof(*rctx)); | 359 | memset(rctx, 0, sizeof(*rctx)); |