diff mbox series

crypto: ecdh - fix big endian bug in ECC library

Message ID 20191023095044.12319-1-ard.biesheuvel@linaro.org
State Accepted
Commit f398243e9fd6a3a059c1ea7b380c40628dbf0c61
Headers show
Series crypto: ecdh - fix big endian bug in ECC library | expand

Commit Message

Ard Biesheuvel Oct. 23, 2019, 9:50 a.m. UTC
The elliptic curve arithmetic library used by the EC-DH KPP implementation
assumes big endian byte order, and unconditionally reverses the byte
and word order of multi-limb quantities. On big endian systems, the byte
reordering is not necessary, while the word ordering needs to be retained.

So replace the __swab64() invocation with a call to be64_to_cpu() which
should do the right thing for both little and big endian builds.

Cc: <stable@vger.kernel.org> # v4.9+
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 crypto/ecc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

-- 
2.20.1

Comments

Herbert Xu Nov. 1, 2019, 6:08 a.m. UTC | #1
On Wed, Oct 23, 2019 at 11:50:44AM +0200, Ard Biesheuvel wrote:
> The elliptic curve arithmetic library used by the EC-DH KPP implementation

> assumes big endian byte order, and unconditionally reverses the byte

> and word order of multi-limb quantities. On big endian systems, the byte

> reordering is not necessary, while the word ordering needs to be retained.

> 

> So replace the __swab64() invocation with a call to be64_to_cpu() which

> should do the right thing for both little and big endian builds.

> 

> Cc: <stable@vger.kernel.org> # v4.9+

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> ---

>  crypto/ecc.c | 3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)


Patch applied.  Thanks.
-- 
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
diff mbox series

Patch

diff --git a/crypto/ecc.c b/crypto/ecc.c
index dfe114bc0c4a..8ee787723c5c 100644
--- a/crypto/ecc.c
+++ b/crypto/ecc.c
@@ -1284,10 +1284,11 @@  EXPORT_SYMBOL(ecc_point_mult_shamir);
 static inline void ecc_swap_digits(const u64 *in, u64 *out,
 				   unsigned int ndigits)
 {
+	const __be64 *src = (__force __be64 *)in;
 	int i;
 
 	for (i = 0; i < ndigits; i++)
-		out[i] = __swab64(in[ndigits - 1 - i]);
+		out[i] = be64_to_cpu(src[ndigits - 1 - i]);
 }
 
 static int __ecc_is_key_valid(const struct ecc_curve *curve,