diff options
Diffstat (limited to 'crypto/rmd160.c')
-rw-r--r-- | crypto/rmd160.c | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/crypto/rmd160.c b/crypto/rmd160.c index 80d647aada67..136e31f56d53 100644 --- a/crypto/rmd160.c +++ b/crypto/rmd160.c | |||
@@ -47,7 +47,7 @@ struct rmd160_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 | } |
@@ -261,28 +261,6 @@ static void rmd160_transform(u32 *state, u32 const *in) | |||
261 | return; | 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 | static void rmd160_init(struct crypto_tfm *tfm) | 264 | static void rmd160_init(struct crypto_tfm *tfm) |
287 | { | 265 | { |
288 | struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm); | 266 | struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm); |
@@ -316,13 +294,13 @@ static void rmd160_update(struct crypto_tfm *tfm, const u8 *data, | |||
316 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), | 294 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), |
317 | data, avail); | 295 | data, avail); |
318 | 296 | ||
319 | rmd160_transform_helper(rctx); | 297 | rmd160_transform(rctx->state, rctx->buffer); |
320 | data += avail; | 298 | data += avail; |
321 | len -= avail; | 299 | len -= avail; |
322 | 300 | ||
323 | while (len >= sizeof(rctx->buffer)) { | 301 | while (len >= sizeof(rctx->buffer)) { |
324 | memcpy(rctx->buffer, data, sizeof(rctx->buffer)); | 302 | memcpy(rctx->buffer, data, sizeof(rctx->buffer)); |
325 | rmd160_transform_helper(rctx); | 303 | rmd160_transform(rctx->state, rctx->buffer); |
326 | data += sizeof(rctx->buffer); | 304 | data += sizeof(rctx->buffer); |
327 | len -= sizeof(rctx->buffer); | 305 | len -= sizeof(rctx->buffer); |
328 | } | 306 | } |
@@ -334,10 +312,12 @@ static void rmd160_update(struct crypto_tfm *tfm, const u8 *data, | |||
334 | static void rmd160_final(struct crypto_tfm *tfm, u8 *out) | 312 | static void rmd160_final(struct crypto_tfm *tfm, u8 *out) |
335 | { | 313 | { |
336 | struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm); | 314 | struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm); |
337 | u32 index, padlen; | 315 | u32 i, index, padlen; |
338 | u64 bits; | 316 | u64 bits; |
317 | u32 *dst = (u32 *)out; | ||
339 | static const u8 padding[64] = { 0x80, }; | 318 | static const u8 padding[64] = { 0x80, }; |
340 | bits = rctx->byte_count << 3; | 319 | |
320 | bits = cpu_to_le64(rctx->byte_count << 3); | ||
341 | 321 | ||
342 | /* Pad out to 56 mod 64 */ | 322 | /* Pad out to 56 mod 64 */ |
343 | index = rctx->byte_count & 0x3f; | 323 | index = rctx->byte_count & 0x3f; |
@@ -348,7 +328,8 @@ static void rmd160_final(struct crypto_tfm *tfm, u8 *out) | |||
348 | rmd160_update(tfm, (const u8 *)&bits, sizeof(bits)); | 328 | rmd160_update(tfm, (const u8 *)&bits, sizeof(bits)); |
349 | 329 | ||
350 | /* Store state in digest */ | 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 | /* Wipe context */ | 334 | /* Wipe context */ |
354 | memset(rctx, 0, sizeof(*rctx)); | 335 | memset(rctx, 0, sizeof(*rctx)); |