linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: serpent - Fix sparse byte order warnings
@ 2021-02-10  7:15 Herbert Xu
  2021-02-10 15:59 ` Ard Biesheuvel
  0 siblings, 1 reply; 2+ messages in thread
From: Herbert Xu @ 2021-02-10  7:15 UTC (permalink / raw)
  To: Linux Crypto Mailing List, ebiggers, Ard Biesheuvel

This patch fixes the byte order markings in serpent.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/crypto/serpent_generic.c b/crypto/serpent_generic.c
index 236c87547a17..45f98b750053 100644
--- a/crypto/serpent_generic.c
+++ b/crypto/serpent_generic.c
@@ -272,6 +272,7 @@ int __serpent_setkey(struct serpent_ctx *ctx, const u8 *key,
 	u32 *k = ctx->expkey;
 	u8  *k8 = (u8 *)k;
 	u32 r0, r1, r2, r3, r4;
+	__le32 *lk;
 	int i;
 
 	/* Copy key, add padding */
@@ -283,22 +284,32 @@ int __serpent_setkey(struct serpent_ctx *ctx, const u8 *key,
 	while (i < SERPENT_MAX_KEY_SIZE)
 		k8[i++] = 0;
 
+	lk = (__le32 *)k;
+	k[0] = le32_to_cpu(lk[0]);
+	k[1] = le32_to_cpu(lk[1]);
+	k[2] = le32_to_cpu(lk[2]);
+	k[3] = le32_to_cpu(lk[3]);
+	k[4] = le32_to_cpu(lk[4]);
+	k[5] = le32_to_cpu(lk[5]);
+	k[6] = le32_to_cpu(lk[6]);
+	k[7] = le32_to_cpu(lk[7]);
+
 	/* Expand key using polynomial */
 
-	r0 = le32_to_cpu(k[3]);
-	r1 = le32_to_cpu(k[4]);
-	r2 = le32_to_cpu(k[5]);
-	r3 = le32_to_cpu(k[6]);
-	r4 = le32_to_cpu(k[7]);
-
-	keyiter(le32_to_cpu(k[0]), r0, r4, r2, 0, 0);
-	keyiter(le32_to_cpu(k[1]), r1, r0, r3, 1, 1);
-	keyiter(le32_to_cpu(k[2]), r2, r1, r4, 2, 2);
-	keyiter(le32_to_cpu(k[3]), r3, r2, r0, 3, 3);
-	keyiter(le32_to_cpu(k[4]), r4, r3, r1, 4, 4);
-	keyiter(le32_to_cpu(k[5]), r0, r4, r2, 5, 5);
-	keyiter(le32_to_cpu(k[6]), r1, r0, r3, 6, 6);
-	keyiter(le32_to_cpu(k[7]), r2, r1, r4, 7, 7);
+	r0 = k[3];
+	r1 = k[4];
+	r2 = k[5];
+	r3 = k[6];
+	r4 = k[7];
+
+	keyiter(k[0], r0, r4, r2, 0, 0);
+	keyiter(k[1], r1, r0, r3, 1, 1);
+	keyiter(k[2], r2, r1, r4, 2, 2);
+	keyiter(k[3], r3, r2, r0, 3, 3);
+	keyiter(k[4], r4, r3, r1, 4, 4);
+	keyiter(k[5], r0, r4, r2, 5, 5);
+	keyiter(k[6], r1, r0, r3, 6, 6);
+	keyiter(k[7], r2, r1, r4, 7, 7);
 
 	keyiter(k[0], r3, r2, r0, 8, 8);
 	keyiter(k[1], r4, r3, r1, 9, 9);
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] crypto: serpent - Fix sparse byte order warnings
  2021-02-10  7:15 [PATCH] crypto: serpent - Fix sparse byte order warnings Herbert Xu
@ 2021-02-10 15:59 ` Ard Biesheuvel
  0 siblings, 0 replies; 2+ messages in thread
From: Ard Biesheuvel @ 2021-02-10 15:59 UTC (permalink / raw)
  To: Herbert Xu; +Cc: Linux Crypto Mailing List, Eric Biggers

On Wed, 10 Feb 2021 at 08:16, Herbert Xu <herbert@gondor.apana.org.au> wrote:
>
> This patch fixes the byte order markings in serpent.
>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Tested-by: Ard Biesheuvel <ardb@kernel.org> # arm64 big-endian

>
> diff --git a/crypto/serpent_generic.c b/crypto/serpent_generic.c
> index 236c87547a17..45f98b750053 100644
> --- a/crypto/serpent_generic.c
> +++ b/crypto/serpent_generic.c
> @@ -272,6 +272,7 @@ int __serpent_setkey(struct serpent_ctx *ctx, const u8 *key,
>         u32 *k = ctx->expkey;
>         u8  *k8 = (u8 *)k;
>         u32 r0, r1, r2, r3, r4;
> +       __le32 *lk;
>         int i;
>
>         /* Copy key, add padding */
> @@ -283,22 +284,32 @@ int __serpent_setkey(struct serpent_ctx *ctx, const u8 *key,
>         while (i < SERPENT_MAX_KEY_SIZE)
>                 k8[i++] = 0;
>
> +       lk = (__le32 *)k;
> +       k[0] = le32_to_cpu(lk[0]);
> +       k[1] = le32_to_cpu(lk[1]);
> +       k[2] = le32_to_cpu(lk[2]);
> +       k[3] = le32_to_cpu(lk[3]);
> +       k[4] = le32_to_cpu(lk[4]);
> +       k[5] = le32_to_cpu(lk[5]);
> +       k[6] = le32_to_cpu(lk[6]);
> +       k[7] = le32_to_cpu(lk[7]);
> +
>         /* Expand key using polynomial */
>
> -       r0 = le32_to_cpu(k[3]);
> -       r1 = le32_to_cpu(k[4]);
> -       r2 = le32_to_cpu(k[5]);
> -       r3 = le32_to_cpu(k[6]);
> -       r4 = le32_to_cpu(k[7]);
> -
> -       keyiter(le32_to_cpu(k[0]), r0, r4, r2, 0, 0);
> -       keyiter(le32_to_cpu(k[1]), r1, r0, r3, 1, 1);
> -       keyiter(le32_to_cpu(k[2]), r2, r1, r4, 2, 2);
> -       keyiter(le32_to_cpu(k[3]), r3, r2, r0, 3, 3);
> -       keyiter(le32_to_cpu(k[4]), r4, r3, r1, 4, 4);
> -       keyiter(le32_to_cpu(k[5]), r0, r4, r2, 5, 5);
> -       keyiter(le32_to_cpu(k[6]), r1, r0, r3, 6, 6);
> -       keyiter(le32_to_cpu(k[7]), r2, r1, r4, 7, 7);
> +       r0 = k[3];
> +       r1 = k[4];
> +       r2 = k[5];
> +       r3 = k[6];
> +       r4 = k[7];
> +
> +       keyiter(k[0], r0, r4, r2, 0, 0);
> +       keyiter(k[1], r1, r0, r3, 1, 1);
> +       keyiter(k[2], r2, r1, r4, 2, 2);
> +       keyiter(k[3], r3, r2, r0, 3, 3);
> +       keyiter(k[4], r4, r3, r1, 4, 4);
> +       keyiter(k[5], r0, r4, r2, 5, 5);
> +       keyiter(k[6], r1, r0, r3, 6, 6);
> +       keyiter(k[7], r2, r1, r4, 7, 7);
>
>         keyiter(k[0], r3, r2, r0, 8, 8);
>         keyiter(k[1], r4, r3, r1, 9, 9);
> --
> Email: Herbert Xu <herbert@gondor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-10 16:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10  7:15 [PATCH] crypto: serpent - Fix sparse byte order warnings Herbert Xu
2021-02-10 15:59 ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).