aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/rmd128.c37
1 files changed, 9 insertions, 28 deletions
diff --git a/crypto/rmd128.c b/crypto/rmd128.c
index f72d2ce848d0..89a535aa6eb8 100644
--- a/crypto/rmd128.c
+++ b/crypto/rmd128.c
@@ -44,7 +44,7 @@ struct rmd128_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
@@ -218,28 +218,6 @@ static void rmd128_transform(u32 *state, u32 const *in)
218 return; 218 return;
219} 219}
220 220
221static inline void le32_to_cpu_array(u32 *buf, unsigned int words)
222{
223 while (words--) {
224 le32_to_cpus(buf);
225 buf++;
226 }
227}
228
229static inline void cpu_to_le32_array(u32 *buf, unsigned int words)
230{
231 while (words--) {
232 cpu_to_le32s(buf);
233 buf++;
234 }
235}
236
237static inline void rmd128_transform_helper(struct rmd128_ctx *ctx)
238{
239 le32_to_cpu_array(ctx->buffer, sizeof(ctx->buffer) / sizeof(u32));
240 rmd128_transform(ctx->state, ctx->buffer);
241}
242
243static void rmd128_init(struct crypto_tfm *tfm) 221static void rmd128_init(struct crypto_tfm *tfm)
244{ 222{
245 struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm); 223 struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm);
@@ -272,13 +250,13 @@ static void rmd128_update(struct crypto_tfm *tfm, const u8 *data,
272 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), 250 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
273 data, avail); 251 data, avail);
274 252
275 rmd128_transform_helper(rctx); 253 rmd128_transform(rctx->state, rctx->buffer);
276 data += avail; 254 data += avail;
277 len -= avail; 255 len -= avail;
278 256
279 while (len >= sizeof(rctx->buffer)) { 257 while (len >= sizeof(rctx->buffer)) {
280 memcpy(rctx->buffer, data, sizeof(rctx->buffer)); 258 memcpy(rctx->buffer, data, sizeof(rctx->buffer));
281 rmd128_transform_helper(rctx); 259 rmd128_transform(rctx->state, rctx->buffer);
282 data += sizeof(rctx->buffer); 260 data += sizeof(rctx->buffer);
283 len -= sizeof(rctx->buffer); 261 len -= sizeof(rctx->buffer);
284 } 262 }
@@ -290,10 +268,12 @@ static void rmd128_update(struct crypto_tfm *tfm, const u8 *data,
290static void rmd128_final(struct crypto_tfm *tfm, u8 *out) 268static void rmd128_final(struct crypto_tfm *tfm, u8 *out)
291{ 269{
292 struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm); 270 struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm);
293 u32 index, padlen; 271 u32 i, index, padlen;
294 u64 bits; 272 u64 bits;
273 u32 *dst = (u32 *)out;
295 static const u8 padding[64] = { 0x80, }; 274 static const u8 padding[64] = { 0x80, };
296 bits = rctx->byte_count << 3; 275
276 bits = cpu_to_le64(rctx->byte_count << 3);
297 277
298 /* Pad out to 56 mod 64 */ 278 /* Pad out to 56 mod 64 */
299 index = rctx->byte_count & 0x3f; 279 index = rctx->byte_count & 0x3f;
@@ -304,7 +284,8 @@ static void rmd128_final(struct crypto_tfm *tfm, u8 *out)
304 rmd128_update(tfm, (const u8 *)&bits, sizeof(bits)); 284 rmd128_update(tfm, (const u8 *)&bits, sizeof(bits));
305 285
306 /* Store state in digest */ 286 /* Store state in digest */
307 memcpy(out, rctx->state, sizeof(rctx->state)); 287 for (i = 0; i < 4; i++)
288 dst[i] = cpu_to_le32(rctx->state[i]);
308 289
309 /* Wipe context */ 290 /* Wipe context */
310 memset(rctx, 0, sizeof(*rctx)); 291 memset(rctx, 0, sizeof(*rctx));