Skip to content

Commit 5cdcc22

Browse files
committed
[CRYPTO] rmd: Use pointer form of endian swapping operations
This patch converts the relevant code in the rmd implementations to use the pointer form of the endian swapping operations. This allows certain architectures to generate more optimised code. For example, on sparc64 this more than halves the CPU cycles on a typical hashing operation. Based on a patch by David Miller. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 0936a94 commit 5cdcc22

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎crypto/rmd128.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct rmd128_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)) + le32_to_cpu(x) + (k); \
47+
(a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
4848
(a) = rol32((a), (s)); \
4949
}
5050

@@ -285,7 +285,7 @@ static void rmd128_final(struct crypto_tfm *tfm, u8 *out)
285285

286286
/* Store state in digest */
287287
for (i = 0; i < 4; i++)
288-
dst[i] = cpu_to_le32(rctx->state[i]);
288+
dst[i] = cpu_to_le32p(&rctx->state[i]);
289289

290290
/* Wipe context */
291291
memset(rctx, 0, sizeof(*rctx));

‎crypto/rmd160.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct rmd160_ctx {
4747
#define F5(x, y, z) (x ^ (y | ~z))
4848

4949
#define ROUND(a, b, c, d, e, f, k, x, s) { \
50-
(a) += f((b), (c), (d)) + le32_to_cpu(x) + (k); \
50+
(a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
5151
(a) = rol32((a), (s)) + (e); \
5252
(c) = rol32((c), 10); \
5353
}
@@ -329,7 +329,7 @@ static void rmd160_final(struct crypto_tfm *tfm, u8 *out)
329329

330330
/* Store state in digest */
331331
for (i = 0; i < 5; i++)
332-
dst[i] = cpu_to_le32(rctx->state[i]);
332+
dst[i] = cpu_to_le32p(&rctx->state[i]);
333333

334334
/* Wipe context */
335335
memset(rctx, 0, sizeof(*rctx));

‎crypto/rmd256.c‎

Lines changed: 2 additions & 2 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)) + le32_to_cpu(x) + (k); \
47+
(a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
4848
(a) = rol32((a), (s)); \
4949
}
5050

@@ -304,7 +304,7 @@ static void rmd256_final(struct crypto_tfm *tfm, u8 *out)
304304

305305
/* Store state in digest */
306306
for (i = 0; i < 8; i++)
307-
dst[i] = cpu_to_le32(rctx->state[i]);
307+
dst[i] = cpu_to_le32p(&rctx->state[i]);
308308

309309
/* Wipe context */
310310
memset(rctx, 0, sizeof(*rctx));

‎crypto/rmd320.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct rmd320_ctx {
4747
#define F5(x, y, z) (x ^ (y | ~z))
4848

4949
#define ROUND(a, b, c, d, e, f, k, x, s) { \
50-
(a) += f((b), (c), (d)) + le32_to_cpu(x) + (k); \
50+
(a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
5151
(a) = rol32((a), (s)) + (e); \
5252
(c) = rol32((c), 10); \
5353
}
@@ -353,7 +353,7 @@ static void rmd320_final(struct crypto_tfm *tfm, u8 *out)
353353

354354
/* Store state in digest */
355355
for (i = 0; i < 10; i++)
356-
dst[i] = cpu_to_le32(rctx->state[i]);
356+
dst[i] = cpu_to_le32p(&rctx->state[i]);
357357

358358
/* Wipe context */
359359
memset(rctx, 0, sizeof(*rctx));

0 commit comments

Comments
 (0)