diff options
Diffstat (limited to 'crypto/rmd256.c')
-rw-r--r-- | crypto/rmd256.c | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/crypto/rmd256.c b/crypto/rmd256.c index 060ee81cb8ad..88f2203751ae 100644 --- a/crypto/rmd256.c +++ b/crypto/rmd256.c | |||
@@ -44,7 +44,7 @@ struct rmd256_ctx { | |||
44 | #define F4(x, y, z) (y ^ (z & (x ^ y))) /* z ? x : y */ | 44 | #define F4(x, y, z) (y ^ (z & (x ^ y))) /* z ? x : y */ |
45 | 45 | ||
46 | #define ROUND(a, b, c, d, f, k, x, s) { \ | 46 | #define ROUND(a, b, c, d, f, k, x, s) { \ |
47 | (a) += f((b), (c), (d)) + (x) + (k); \ | 47 | (a) += f((b), (c), (d)) + le32_to_cpu(x) + (k); \ |
48 | (a) = rol32((a), (s)); \ | 48 | (a) = rol32((a), (s)); \ |
49 | } | 49 | } |
50 | 50 | ||
@@ -233,28 +233,6 @@ static void rmd256_transform(u32 *state, u32 const *in) | |||
233 | return; | 233 | return; |
234 | } | 234 | } |
235 | 235 | ||
236 | static inline void le32_to_cpu_array(u32 *buf, unsigned int words) | ||
237 | { | ||
238 | while (words--) { | ||
239 | le32_to_cpus(buf); | ||
240 | buf++; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | static inline void cpu_to_le32_array(u32 *buf, unsigned int words) | ||
245 | { | ||
246 | while (words--) { | ||
247 | cpu_to_le32s(buf); | ||
248 | buf++; | ||
249 | } | ||
250 | } | ||
251 | |||
252 | static inline void rmd256_transform_helper(struct rmd256_ctx *ctx) | ||
253 | { | ||
254 | le32_to_cpu_array(ctx->buffer, sizeof(ctx->buffer) / sizeof(u32)); | ||
255 | rmd256_transform(ctx->state, ctx->buffer); | ||
256 | } | ||
257 | |||
258 | static void rmd256_init(struct crypto_tfm *tfm) | 236 | static void rmd256_init(struct crypto_tfm *tfm) |
259 | { | 237 | { |
260 | struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm); | 238 | struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm); |
@@ -291,13 +269,13 @@ static void rmd256_update(struct crypto_tfm *tfm, const u8 *data, | |||
291 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), | 269 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), |
292 | data, avail); | 270 | data, avail); |
293 | 271 | ||
294 | rmd256_transform_helper(rctx); | 272 | rmd256_transform(rctx->state, rctx->buffer); |
295 | data += avail; | 273 | data += avail; |
296 | len -= avail; | 274 | len -= avail; |
297 | 275 | ||
298 | while (len >= sizeof(rctx->buffer)) { | 276 | while (len >= sizeof(rctx->buffer)) { |
299 | memcpy(rctx->buffer, data, sizeof(rctx->buffer)); | 277 | memcpy(rctx->buffer, data, sizeof(rctx->buffer)); |
300 | rmd256_transform_helper(rctx); | 278 | rmd256_transform(rctx->state, rctx->buffer); |
301 | data += sizeof(rctx->buffer); | 279 | data += sizeof(rctx->buffer); |
302 | len -= sizeof(rctx->buffer); | 280 | len -= sizeof(rctx->buffer); |
303 | } | 281 | } |
@@ -309,10 +287,12 @@ static void rmd256_update(struct crypto_tfm *tfm, const u8 *data, | |||
309 | static void rmd256_final(struct crypto_tfm *tfm, u8 *out) | 287 | static void rmd256_final(struct crypto_tfm *tfm, u8 *out) |
310 | { | 288 | { |
311 | struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm); | 289 | struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm); |
312 | u32 index, padlen; | 290 | u32 i, index, padlen; |
313 | u64 bits; | 291 | u64 bits; |
292 | u32 *dst = (u32 *)out; | ||
314 | static const u8 padding[64] = { 0x80, }; | 293 | static const u8 padding[64] = { 0x80, }; |
315 | bits = rctx->byte_count << 3; | 294 | |
295 | bits = cpu_to_le64(rctx->byte_count << 3); | ||
316 | 296 | ||
317 | /* Pad out to 56 mod 64 */ | 297 | /* Pad out to 56 mod 64 */ |
318 | index = rctx->byte_count & 0x3f; | 298 | index = rctx->byte_count & 0x3f; |
@@ -323,7 +303,8 @@ static void rmd256_final(struct crypto_tfm *tfm, u8 *out) | |||
323 | rmd256_update(tfm, (const u8 *)&bits, sizeof(bits)); | 303 | rmd256_update(tfm, (const u8 *)&bits, sizeof(bits)); |
324 | 304 | ||
325 | /* Store state in digest */ | 305 | /* Store state in digest */ |
326 | memcpy(out, rctx->state, sizeof(rctx->state)); | 306 | for (i = 0; i < 8; i++) |
307 | dst[i] = cpu_to_le32(rctx->state[i]); | ||
327 | 308 | ||
328 | /* Wipe context */ | 309 | /* Wipe context */ |
329 | memset(rctx, 0, sizeof(*rctx)); | 310 | memset(rctx, 0, sizeof(*rctx)); |