Commit 5cdcc22f authored by Herbert Xu's avatar Herbert Xu

[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: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 0936a944
...@@ -44,7 +44,7 @@ struct rmd128_ctx { ...@@ -44,7 +44,7 @@ struct rmd128_ctx {
#define F4(x, y, z) (y ^ (z & (x ^ y))) /* z ? x : y */ #define F4(x, y, z) (y ^ (z & (x ^ y))) /* z ? x : y */
#define ROUND(a, b, c, d, f, k, x, s) { \ #define ROUND(a, b, c, d, f, k, x, s) { \
(a) += f((b), (c), (d)) + le32_to_cpu(x) + (k); \ (a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
(a) = rol32((a), (s)); \ (a) = rol32((a), (s)); \
} }
...@@ -285,7 +285,7 @@ static void rmd128_final(struct crypto_tfm *tfm, u8 *out) ...@@ -285,7 +285,7 @@ static void rmd128_final(struct crypto_tfm *tfm, u8 *out)
/* Store state in digest */ /* Store state in digest */
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
dst[i] = cpu_to_le32(rctx->state[i]); dst[i] = cpu_to_le32p(&rctx->state[i]);
/* Wipe context */ /* Wipe context */
memset(rctx, 0, sizeof(*rctx)); memset(rctx, 0, sizeof(*rctx));
......
...@@ -47,7 +47,7 @@ struct rmd160_ctx { ...@@ -47,7 +47,7 @@ struct rmd160_ctx {
#define F5(x, y, z) (x ^ (y | ~z)) #define F5(x, y, z) (x ^ (y | ~z))
#define ROUND(a, b, c, d, e, f, k, x, s) { \ #define ROUND(a, b, c, d, e, f, k, x, s) { \
(a) += f((b), (c), (d)) + le32_to_cpu(x) + (k); \ (a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
(a) = rol32((a), (s)) + (e); \ (a) = rol32((a), (s)) + (e); \
(c) = rol32((c), 10); \ (c) = rol32((c), 10); \
} }
...@@ -329,7 +329,7 @@ static void rmd160_final(struct crypto_tfm *tfm, u8 *out) ...@@ -329,7 +329,7 @@ static void rmd160_final(struct crypto_tfm *tfm, u8 *out)
/* Store state in digest */ /* Store state in digest */
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
dst[i] = cpu_to_le32(rctx->state[i]); dst[i] = cpu_to_le32p(&rctx->state[i]);
/* Wipe context */ /* Wipe context */
memset(rctx, 0, sizeof(*rctx)); memset(rctx, 0, sizeof(*rctx));
......
...@@ -44,7 +44,7 @@ struct rmd256_ctx { ...@@ -44,7 +44,7 @@ struct rmd256_ctx {
#define F4(x, y, z) (y ^ (z & (x ^ y))) /* z ? x : y */ #define F4(x, y, z) (y ^ (z & (x ^ y))) /* z ? x : y */
#define ROUND(a, b, c, d, f, k, x, s) { \ #define ROUND(a, b, c, d, f, k, x, s) { \
(a) += f((b), (c), (d)) + le32_to_cpu(x) + (k); \ (a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
(a) = rol32((a), (s)); \ (a) = rol32((a), (s)); \
} }
...@@ -304,7 +304,7 @@ static void rmd256_final(struct crypto_tfm *tfm, u8 *out) ...@@ -304,7 +304,7 @@ static void rmd256_final(struct crypto_tfm *tfm, u8 *out)
/* Store state in digest */ /* Store state in digest */
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
dst[i] = cpu_to_le32(rctx->state[i]); dst[i] = cpu_to_le32p(&rctx->state[i]);
/* Wipe context */ /* Wipe context */
memset(rctx, 0, sizeof(*rctx)); memset(rctx, 0, sizeof(*rctx));
......
...@@ -47,7 +47,7 @@ struct rmd320_ctx { ...@@ -47,7 +47,7 @@ struct rmd320_ctx {
#define F5(x, y, z) (x ^ (y | ~z)) #define F5(x, y, z) (x ^ (y | ~z))
#define ROUND(a, b, c, d, e, f, k, x, s) { \ #define ROUND(a, b, c, d, e, f, k, x, s) { \
(a) += f((b), (c), (d)) + le32_to_cpu(x) + (k); \ (a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
(a) = rol32((a), (s)) + (e); \ (a) = rol32((a), (s)) + (e); \
(c) = rol32((c), 10); \ (c) = rol32((c), 10); \
} }
...@@ -353,7 +353,7 @@ static void rmd320_final(struct crypto_tfm *tfm, u8 *out) ...@@ -353,7 +353,7 @@ static void rmd320_final(struct crypto_tfm *tfm, u8 *out)
/* Store state in digest */ /* Store state in digest */
for (i = 0; i < 10; i++) for (i = 0; i < 10; i++)
dst[i] = cpu_to_le32(rctx->state[i]); dst[i] = cpu_to_le32p(&rctx->state[i]);
/* Wipe context */ /* Wipe context */
memset(rctx, 0, sizeof(*rctx)); memset(rctx, 0, sizeof(*rctx));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment