Skip to content

Commit 2952ff1

Browse files
Adrian-Ken Rueegseggerherbertx
authored andcommitted
[CRYPTO] rmd256: Fix endian issues
This patch fixes endian issues making rmd256 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>
1 parent c928a0c commit 2952ff1

1 file changed

Lines changed: 9 additions & 28 deletions

File tree

‎crypto/rmd256.c‎

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct rmd256_ctx {
4444
#define F4(x, y, z) (y ^ (z & (x ^ y))) /* z ? x : y */
4545

4646
#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); \
4848
(a) = rol32((a), (s)); \
4949
}
5050

@@ -233,28 +233,6 @@ static void rmd256_transform(u32 *state, u32 const *in)
233233
return;
234234
}
235235

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-
258236
static void rmd256_init(struct crypto_tfm *tfm)
259237
{
260238
struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm);
@@ -291,13 +269,13 @@ static void rmd256_update(struct crypto_tfm *tfm, const u8 *data,
291269
memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
292270
data, avail);
293271

294-
rmd256_transform_helper(rctx);
272+
rmd256_transform(rctx->state, rctx->buffer);
295273
data += avail;
296274
len -= avail;
297275

298276
while (len >= sizeof(rctx->buffer)) {
299277
memcpy(rctx->buffer, data, sizeof(rctx->buffer));
300-
rmd256_transform_helper(rctx);
278+
rmd256_transform(rctx->state, rctx->buffer);
301279
data += sizeof(rctx->buffer);
302280
len -= sizeof(rctx->buffer);
303281
}
@@ -309,10 +287,12 @@ static void rmd256_update(struct crypto_tfm *tfm, const u8 *data,
309287
static void rmd256_final(struct crypto_tfm *tfm, u8 *out)
310288
{
311289
struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm);
312-
u32 index, padlen;
290+
u32 i, index, padlen;
313291
u64 bits;
292+
u32 *dst = (u32 *)out;
314293
static const u8 padding[64] = { 0x80, };
315-
bits = rctx->byte_count << 3;
294+
295+
bits = cpu_to_le64(rctx->byte_count << 3);
316296

317297
/* Pad out to 56 mod 64 */
318298
index = rctx->byte_count & 0x3f;
@@ -323,7 +303,8 @@ static void rmd256_final(struct crypto_tfm *tfm, u8 *out)
323303
rmd256_update(tfm, (const u8 *)&bits, sizeof(bits));
324304

325305
/* 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]);
327308

328309
/* Wipe context */
329310
memset(rctx, 0, sizeof(*rctx));

0 commit comments

Comments
 (0)