Skip to content

Commit f398243

Browse files
Ard Biesheuvelherbertx
authored andcommitted
crypto: ecdh - fix big endian bug in ECC library
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. Fixes: 3c4b239 ("crypto: ecdh - Add ECDH software support") Cc: <[email protected]> # v4.9+ Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 51d13aa commit f398243

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

crypto/ecc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,10 +1284,11 @@ EXPORT_SYMBOL(ecc_point_mult_shamir);
12841284
static inline void ecc_swap_digits(const u64 *in, u64 *out,
12851285
unsigned int ndigits)
12861286
{
1287+
const __be64 *src = (__force __be64 *)in;
12871288
int i;
12881289

12891290
for (i = 0; i < ndigits; i++)
1290-
out[i] = __swab64(in[ndigits - 1 - i]);
1291+
out[i] = be64_to_cpu(src[ndigits - 1 - i]);
12911292
}
12921293

12931294
static int __ecc_is_key_valid(const struct ecc_curve *curve,

0 commit comments

Comments
 (0)