9a380d377cecb483c7793d0eac25b0bc0b2d8712
[openwrt/staging/ynezz.git] /
1 From 50af997532492b0f55bd9928743ac1f99dc1cd41 Mon Sep 17 00:00:00 2001
2 From: "Jason A. Donenfeld" <Jason@zx2c4.com>
3 Date: Sun, 1 Mar 2020 22:52:35 +0800
4 Subject: [PATCH 052/124] crypto: x86/curve25519 - support assemblers with no
5 adx support
6
7 commit 1579f1bc3b753d17a44de3457d5c6f4a5b14c752 upstream.
8
9 Some older version of GAS do not support the ADX instructions, similarly
10 to how they also don't support AVX and such. This commit adds the same
11 build-time detection mechanisms we use for AVX and others for ADX, and
12 then makes sure that the curve25519 library dispatcher calls the right
13 functions.
14
15 Reported-by: Willy Tarreau <w@1wt.eu>
16 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
17 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
18 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
19 ---
20 arch/x86/Makefile | 5 +++--
21 arch/x86/crypto/Makefile | 7 ++++++-
22 include/crypto/curve25519.h | 6 ++++--
23 3 files changed, 13 insertions(+), 5 deletions(-)
24
25 --- a/arch/x86/Makefile
26 +++ b/arch/x86/Makefile
27 @@ -197,9 +197,10 @@ avx2_instr :=$(call as-instr,vpbroadcast
28 avx512_instr :=$(call as-instr,vpmovm2b %k1$(comma)%zmm5,-DCONFIG_AS_AVX512=1)
29 sha1_ni_instr :=$(call as-instr,sha1msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA1_NI=1)
30 sha256_ni_instr :=$(call as-instr,sha256msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA256_NI=1)
31 +adx_instr := $(call as-instr,adox %r10$(comma)%r10,-DCONFIG_AS_ADX=1)
32
33 -KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
34 -KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
35 +KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr) $(adx_instr)
36 +KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr) $(adx_instr)
37
38 KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
39
40 --- a/arch/x86/crypto/Makefile
41 +++ b/arch/x86/crypto/Makefile
42 @@ -11,6 +11,7 @@ avx2_supported := $(call as-instr,vpgath
43 avx512_supported :=$(call as-instr,vpmovm2b %k1$(comma)%zmm5,yes,no)
44 sha1_ni_supported :=$(call as-instr,sha1msg1 %xmm0$(comma)%xmm1,yes,no)
45 sha256_ni_supported :=$(call as-instr,sha256msg1 %xmm0$(comma)%xmm1,yes,no)
46 +adx_supported := $(call as-instr,adox %r10$(comma)%r10,yes,no)
47
48 obj-$(CONFIG_CRYPTO_GLUE_HELPER_X86) += glue_helper.o
49
50 @@ -39,7 +40,11 @@ obj-$(CONFIG_CRYPTO_AEGIS128_AESNI_SSE2)
51
52 obj-$(CONFIG_CRYPTO_NHPOLY1305_SSE2) += nhpoly1305-sse2.o
53 obj-$(CONFIG_CRYPTO_NHPOLY1305_AVX2) += nhpoly1305-avx2.o
54 -obj-$(CONFIG_CRYPTO_CURVE25519_X86) += curve25519-x86_64.o
55 +
56 +# These modules require the assembler to support ADX.
57 +ifeq ($(adx_supported),yes)
58 + obj-$(CONFIG_CRYPTO_CURVE25519_X86) += curve25519-x86_64.o
59 +endif
60
61 # These modules require assembler to support AVX.
62 ifeq ($(avx_supported),yes)
63 --- a/include/crypto/curve25519.h
64 +++ b/include/crypto/curve25519.h
65 @@ -33,7 +33,8 @@ bool __must_check curve25519(u8 mypublic
66 const u8 secret[CURVE25519_KEY_SIZE],
67 const u8 basepoint[CURVE25519_KEY_SIZE])
68 {
69 - if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519))
70 + if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519) &&
71 + (!IS_ENABLED(CONFIG_CRYPTO_CURVE25519_X86) || IS_ENABLED(CONFIG_AS_ADX)))
72 curve25519_arch(mypublic, secret, basepoint);
73 else
74 curve25519_generic(mypublic, secret, basepoint);
75 @@ -49,7 +50,8 @@ __must_check curve25519_generate_public(
76 CURVE25519_KEY_SIZE)))
77 return false;
78
79 - if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519))
80 + if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CURVE25519) &&
81 + (!IS_ENABLED(CONFIG_CRYPTO_CURVE25519_X86) || IS_ENABLED(CONFIG_AS_ADX)))
82 curve25519_base_arch(pub, secret);
83 else
84 curve25519_generic(pub, secret, curve25519_base_point);