xref: /linux/lib/crypto/Makefile (revision bef9c755986980eecc18e9cecd847bc3c037aebb)
1dc51f257SArd Biesheuvel# SPDX-License-Identifier: GPL-2.0
2dc51f257SArd Biesheuvel
324c91b62SEric Biggersaflags-thumb2-$(CONFIG_THUMB2_KERNEL)  := -U__thumb2__ -D__thumb2__=1
424c91b62SEric Biggers
524c91b62SEric Biggersquiet_cmd_perlasm = PERLASM $@
624c91b62SEric Biggers      cmd_perlasm = $(PERL) $(<) > $(@)
724c91b62SEric Biggers
860e3f1e9SEric Biggersquiet_cmd_perlasm_with_args = PERLASM $@
960e3f1e9SEric Biggers      cmd_perlasm_with_args = $(PERL) $(<) void $(@)
1060e3f1e9SEric Biggers
114dcf6cadSEric Biggersobj-$(CONFIG_KUNIT)				+= tests/
124dcf6cadSEric Biggers
13aacb37f5SEric Biggersobj-$(CONFIG_CRYPTO_HASH_INFO)			+= hash_info.o
14aacb37f5SEric Biggers
157033b937SEric Biggersobj-$(CONFIG_CRYPTO_LIB_UTILS)			+= libcryptoutils.o
166e78ad0bSEric Biggerslibcryptoutils-y				:= memneq.o utils.o
177033b937SEric Biggers
185fb8ef25SArd Biesheuvel# chacha is used by the /dev/random driver which is always builtin
195fb8ef25SArd Biesheuvelobj-y						+= chacha.o
205fb8ef25SArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_CHACHA_GENERIC)		+= libchacha.o
215fb8ef25SArd Biesheuvel
22e59c1c98SArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_AES)			+= libaes.o
23e59c1c98SArd Biesheuvellibaes-y					:= aes.o
24e59c1c98SArd Biesheuvel
25f1354404SArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_AESCFB)			+= libaescfb.o
26f1354404SArd Biesheuvellibaescfb-y					:= aescfb.o
27f1354404SArd Biesheuvel
28520af5daSArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_AESGCM)			+= libaesgcm.o
29520af5daSArd Biesheuvellibaesgcm-y					:= aesgcm.o
30520af5daSArd Biesheuvel
31dc51f257SArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_ARC4)			+= libarc4.o
32dc51f257SArd Biesheuvellibarc4-y					:= arc4.o
3304007b0eSArd Biesheuvel
3461c581a4SArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_GF128MUL)		+= gf128mul.o
3561c581a4SArd Biesheuvel
366048fdccSJason A. Donenfeld# blake2s is used by the /dev/random driver which is always builtin
376048fdccSJason A. Donenfeldobj-y						+= libblake2s.o
386048fdccSJason A. Donenfeldlibblake2s-y					:= blake2s.o
396048fdccSJason A. Donenfeldlibblake2s-$(CONFIG_CRYPTO_LIB_BLAKE2S_GENERIC)	+= blake2s-generic.o
4040b99697SEric Biggerslibblake2s-$(CONFIG_CRYPTO_SELFTESTS)		+= blake2s-selftest.o
4166d7fb94SJason A. Donenfeld
42ed20078bSArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_CHACHA20POLY1305)	+= libchacha20poly1305.o
43ed20078bSArd Biesheuvellibchacha20poly1305-y				+= chacha20poly1305.o
4440b99697SEric Biggerslibchacha20poly1305-$(CONFIG_CRYPTO_SELFTESTS)	+= chacha20poly1305-selftest.o
45ed20078bSArd Biesheuvel
46a8bdf2c4SHerbert Xuobj-$(CONFIG_CRYPTO_LIB_CURVE25519_GENERIC)	+= libcurve25519-generic.o
47a8bdf2c4SHerbert Xulibcurve25519-generic-y				:= curve25519-fiat32.o
48a8bdf2c4SHerbert Xulibcurve25519-generic-$(CONFIG_ARCH_SUPPORTS_INT128)	:= curve25519-hacl64.o
49a8bdf2c4SHerbert Xulibcurve25519-generic-y				+= curve25519-generic.o
502f13daeeSNathan Chancellor# clang versions prior to 18 may blow out the stack with KASAN
512f13daeeSNathan Chancellorifeq ($(call clang-min-version, 180000),)
522f13daeeSNathan ChancellorKASAN_SANITIZE_curve25519-hacl64.o := n
532f13daeeSNathan Chancellorendif
54a8bdf2c4SHerbert Xu
55a8bdf2c4SHerbert Xuobj-$(CONFIG_CRYPTO_LIB_CURVE25519)		+= libcurve25519.o
560ed42a6fSJason A. Donenfeldlibcurve25519-y					+= curve25519.o
5740b99697SEric Biggerslibcurve25519-$(CONFIG_CRYPTO_SELFTESTS)	+= curve25519-selftest.o
580ed42a6fSJason A. Donenfeld
5904007b0eSArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_DES)			+= libdes.o
6004007b0eSArd Biesheuvellibdes-y					:= des.o
6101d3aee8SHans de Goede
62e1644613SEric Biggers################################################################################
63e1644613SEric Biggers
64e1644613SEric Biggersobj-$(CONFIG_CRYPTO_LIB_MD5) += libmd5.o
65e1644613SEric Biggerslibmd5-y := md5.o
66e1644613SEric Biggersifeq ($(CONFIG_CRYPTO_LIB_MD5_ARCH),y)
67e1644613SEric BiggersCFLAGS_md5.o += -I$(src)/$(SRCARCH)
6809371e13SEric Biggerslibmd5-$(CONFIG_PPC) += powerpc/md5-asm.o
69a1848f6eSEric Biggerslibmd5-$(CONFIG_SPARC) += sparc/md5_asm.o
70e1644613SEric Biggersendif # CONFIG_CRYPTO_LIB_MD5_ARCH
71e1644613SEric Biggers
72e1644613SEric Biggers################################################################################
73e1644613SEric Biggers
749b9d4ef0SHerbert Xuobj-$(CONFIG_CRYPTO_LIB_POLY1305) += libpoly1305.o
75b646b782SEric Biggerslibpoly1305-y := poly1305.o
76b646b782SEric Biggersifeq ($(CONFIG_ARCH_SUPPORTS_INT128),y)
77b646b782SEric Biggerslibpoly1305-$(CONFIG_CRYPTO_LIB_POLY1305_GENERIC) += poly1305-donna64.o
78b646b782SEric Biggerselse
79b646b782SEric Biggerslibpoly1305-$(CONFIG_CRYPTO_LIB_POLY1305_GENERIC) += poly1305-donna32.o
80b646b782SEric Biggersendif
8148ea8c6eSArd Biesheuvel
82b646b782SEric Biggersifeq ($(CONFIG_CRYPTO_LIB_POLY1305_ARCH),y)
83b646b782SEric BiggersCFLAGS_poly1305.o += -I$(src)/$(SRCARCH)
84b646b782SEric Biggers
85b646b782SEric Biggersifeq ($(CONFIG_ARM),y)
86b646b782SEric Biggerslibpoly1305-y += arm/poly1305-core.o
87b646b782SEric Biggers$(obj)/arm/poly1305-core.S: $(src)/arm/poly1305-armv4.pl
88b646b782SEric Biggers	$(call cmd,perlasm)
89b646b782SEric Biggers# massage the perlasm code a bit so we only get the NEON routine if we need it
90b646b782SEric Biggerspoly1305-aflags-$(CONFIG_CPU_V7) := -U__LINUX_ARM_ARCH__ -D__LINUX_ARM_ARCH__=5
91b646b782SEric Biggerspoly1305-aflags-$(CONFIG_KERNEL_MODE_NEON) := -U__LINUX_ARM_ARCH__ -D__LINUX_ARM_ARCH__=7
92b646b782SEric BiggersAFLAGS_arm/poly1305-core.o += $(poly1305-aflags-y) $(aflags-thumb2-y)
93b646b782SEric Biggersendif
94b646b782SEric Biggers
95b646b782SEric Biggersifeq ($(CONFIG_ARM64),y)
96b646b782SEric Biggerslibpoly1305-y += arm64/poly1305-core.o
97b646b782SEric Biggers$(obj)/arm64/poly1305-core.S: $(src)/arm64/poly1305-armv8.pl
98b646b782SEric Biggers	$(call cmd,perlasm_with_args)
99b646b782SEric Biggersendif
100b646b782SEric Biggers
101b646b782SEric Biggersifeq ($(CONFIG_MIPS),y)
102b646b782SEric Biggerslibpoly1305-y += mips/poly1305-core.o
103b646b782SEric Biggerspoly1305-perlasm-flavour-$(CONFIG_32BIT) := o32
104b646b782SEric Biggerspoly1305-perlasm-flavour-$(CONFIG_64BIT) := 64
105b646b782SEric Biggersquiet_cmd_perlasm_poly1305 = PERLASM $@
106b646b782SEric Biggers      cmd_perlasm_poly1305 = $(PERL) $< $(poly1305-perlasm-flavour-y) $@
107b646b782SEric Biggers# Use if_changed instead of cmd, in case the flavour changed.
108b646b782SEric Biggers$(obj)/mips/poly1305-core.S: $(src)/mips/poly1305-mips.pl FORCE
109b646b782SEric Biggers	$(call if_changed,perlasm_poly1305)
110b646b782SEric Biggerstargets += mips/poly1305-core.S
111b646b782SEric Biggersendif
112b646b782SEric Biggers
113b646b782SEric Biggerslibpoly1305-$(CONFIG_PPC) += powerpc/poly1305-p10le_64.o
114b646b782SEric Biggers
115*bef9c755SZhihang Shaoifeq ($(CONFIG_RISCV),y)
116*bef9c755SZhihang Shaolibpoly1305-y += riscv/poly1305-core.o
117*bef9c755SZhihang Shaopoly1305-perlasm-flavour-$(CONFIG_32BIT) := 32
118*bef9c755SZhihang Shaopoly1305-perlasm-flavour-$(CONFIG_64BIT) := 64
119*bef9c755SZhihang Shaoquiet_cmd_perlasm_poly1305 = PERLASM $@
120*bef9c755SZhihang Shao      cmd_perlasm_poly1305 = $(PERL) $< $(poly1305-perlasm-flavour-y) $@
121*bef9c755SZhihang Shao# Use if_changed instead of cmd, in case the flavour changed.
122*bef9c755SZhihang Shao$(obj)/riscv/poly1305-core.S: $(src)/riscv/poly1305-riscv.pl FORCE
123*bef9c755SZhihang Shao	$(call if_changed,perlasm_poly1305)
124*bef9c755SZhihang Shaotargets += riscv/poly1305-core.S
125*bef9c755SZhihang ShaoAFLAGS_riscv/poly1305-core.o += -Dpoly1305_init=poly1305_block_init
126*bef9c755SZhihang Shaoendif
127*bef9c755SZhihang Shao
128b646b782SEric Biggersifeq ($(CONFIG_X86),y)
129b646b782SEric Biggerslibpoly1305-y += x86/poly1305-x86_64-cryptogams.o
130b646b782SEric Biggers$(obj)/x86/poly1305-x86_64-cryptogams.S: $(src)/x86/poly1305-x86_64-cryptogams.pl
131b646b782SEric Biggers	$(call cmd,perlasm)
132b646b782SEric Biggersendif
133b646b782SEric Biggers
134b646b782SEric Biggersendif # CONFIG_CRYPTO_LIB_POLY1305_ARCH
135b646b782SEric Biggers
136b646b782SEric Biggers# clean-files must be defined unconditionally
137b646b782SEric Biggersclean-files += arm/poly1305-core.S \
138b646b782SEric Biggers	       arm64/poly1305-core.S \
139b646b782SEric Biggers	       mips/poly1305-core.S \
140*bef9c755SZhihang Shao	       riscv/poly1305-core.S \
141b646b782SEric Biggers	       x86/poly1305-x86_64-cryptogams.S
1429b9d4ef0SHerbert Xu
14390860aefSEric Biggers################################################################################
14490860aefSEric Biggers
145ec8f7f48SEric Biggersobj-$(CONFIG_CRYPTO_LIB_SHA1) += libsha1.o
146ec8f7f48SEric Biggerslibsha1-y := sha1.o
14790860aefSEric Biggersifeq ($(CONFIG_CRYPTO_LIB_SHA1_ARCH),y)
14890860aefSEric BiggersCFLAGS_sha1.o += -I$(src)/$(SRCARCH)
14970cb6ca5SEric Biggersifeq ($(CONFIG_ARM),y)
15070cb6ca5SEric Biggerslibsha1-y += arm/sha1-armv4-large.o
15170cb6ca5SEric Biggerslibsha1-$(CONFIG_KERNEL_MODE_NEON) += arm/sha1-armv7-neon.o \
15270cb6ca5SEric Biggers				      arm/sha1-ce-core.o
15370cb6ca5SEric Biggersendif
15400d549bbSEric Biggerslibsha1-$(CONFIG_ARM64) += arm64/sha1-ce-core.o
1556b9ae8cfSEric Biggersifeq ($(CONFIG_PPC),y)
1566b9ae8cfSEric Biggerslibsha1-y += powerpc/sha1-powerpc-asm.o
1576b9ae8cfSEric Biggerslibsha1-$(CONFIG_SPE) += powerpc/sha1-spe-asm.o
1586b9ae8cfSEric Biggersendif
159c7510599SEric Biggerslibsha1-$(CONFIG_SPARC) += sparc/sha1_asm.o
160f3d6cb3dSEric Biggerslibsha1-$(CONFIG_X86) += x86/sha1-ssse3-and-avx.o \
161f3d6cb3dSEric Biggers			 x86/sha1-avx2-asm.o \
162f3d6cb3dSEric Biggers			 x86/sha1-ni-asm.o
16390860aefSEric Biggersendif # CONFIG_CRYPTO_LIB_SHA1_ARCH
164463f7408SEric Biggers
165e96cb950SEric Biggers################################################################################
166e96cb950SEric Biggers
16701d3aee8SHans de Goedeobj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o
16801d3aee8SHans de Goedelibsha256-y := sha256.o
169e96cb950SEric Biggersifeq ($(CONFIG_CRYPTO_LIB_SHA256_ARCH),y)
170e96cb950SEric BiggersCFLAGS_sha256.o += -I$(src)/$(SRCARCH)
17166d7fb94SJason A. Donenfeld
172e96cb950SEric Biggersifeq ($(CONFIG_ARM),y)
173e96cb950SEric Biggerslibsha256-y += arm/sha256-ce.o arm/sha256-core.o
174e96cb950SEric Biggers$(obj)/arm/sha256-core.S: $(src)/arm/sha256-armv4.pl
175e96cb950SEric Biggers	$(call cmd,perlasm)
176e96cb950SEric BiggersAFLAGS_arm/sha256-core.o += $(aflags-thumb2-y)
177e96cb950SEric Biggersendif
178e96cb950SEric Biggers
179e96cb950SEric Biggersifeq ($(CONFIG_ARM64),y)
180e96cb950SEric Biggerslibsha256-y += arm64/sha256-core.o
181e96cb950SEric Biggers$(obj)/arm64/sha256-core.S: $(src)/arm64/sha2-armv8.pl
182e96cb950SEric Biggers	$(call cmd,perlasm_with_args)
183e96cb950SEric Biggerslibsha256-$(CONFIG_KERNEL_MODE_NEON) += arm64/sha256-ce.o
184e96cb950SEric Biggersendif
185e96cb950SEric Biggers
186e96cb950SEric Biggerslibsha256-$(CONFIG_PPC) += powerpc/sha256-spe-asm.o
187e96cb950SEric Biggerslibsha256-$(CONFIG_RISCV) += riscv/sha256-riscv64-zvknha_or_zvknhb-zvkb.o
188e96cb950SEric Biggerslibsha256-$(CONFIG_SPARC) += sparc/sha256_asm.o
189e96cb950SEric Biggerslibsha256-$(CONFIG_X86) += x86/sha256-ssse3-asm.o \
190e96cb950SEric Biggers			   x86/sha256-avx-asm.o \
191e96cb950SEric Biggers			   x86/sha256-avx2-asm.o \
192e96cb950SEric Biggers			   x86/sha256-ni-asm.o
193e96cb950SEric Biggersendif # CONFIG_CRYPTO_LIB_SHA256_ARCH
194e96cb950SEric Biggers
195e96cb950SEric Biggers################################################################################
196950e5c84SEric Biggers
197b693c703SEric Biggersobj-$(CONFIG_CRYPTO_LIB_SHA512) += libsha512.o
198b693c703SEric Biggerslibsha512-y := sha512.o
199b693c703SEric Biggersifeq ($(CONFIG_CRYPTO_LIB_SHA512_ARCH),y)
200b693c703SEric BiggersCFLAGS_sha512.o += -I$(src)/$(SRCARCH)
20124c91b62SEric Biggers
20224c91b62SEric Biggersifeq ($(CONFIG_ARM),y)
20324c91b62SEric Biggerslibsha512-y += arm/sha512-core.o
20424c91b62SEric Biggers$(obj)/arm/sha512-core.S: $(src)/arm/sha512-armv4.pl
20524c91b62SEric Biggers	$(call cmd,perlasm)
20624c91b62SEric BiggersAFLAGS_arm/sha512-core.o += $(aflags-thumb2-y)
20724c91b62SEric Biggersendif
20824c91b62SEric Biggers
20960e3f1e9SEric Biggersifeq ($(CONFIG_ARM64),y)
21060e3f1e9SEric Biggerslibsha512-y += arm64/sha512-core.o
21161f86c70SEric Biggers$(obj)/arm64/sha512-core.S: $(src)/arm64/sha2-armv8.pl
21260e3f1e9SEric Biggers	$(call cmd,perlasm_with_args)
21360e3f1e9SEric Biggerslibsha512-$(CONFIG_KERNEL_MODE_NEON) += arm64/sha512-ce-core.o
21460e3f1e9SEric Biggersendif
215b59059a2SEric Biggers
216b59059a2SEric Biggerslibsha512-$(CONFIG_RISCV) += riscv/sha512-riscv64-zvknhb-zvkb.o
21702b35babSEric Biggerslibsha512-$(CONFIG_SPARC) += sparc/sha512_asm.o
218484c1811SEric Biggerslibsha512-$(CONFIG_X86) += x86/sha512-ssse3-asm.o \
219484c1811SEric Biggers			   x86/sha512-avx-asm.o \
220484c1811SEric Biggers			   x86/sha512-avx2-asm.o
221b693c703SEric Biggersendif # CONFIG_CRYPTO_LIB_SHA512_ARCH
222b693c703SEric Biggers
223e96cb950SEric Biggers################################################################################
224e96cb950SEric Biggers
2252a598d0bSHerbert Xuobj-$(CONFIG_MPILIB) += mpi/
2264964a1d9SEric Biggers
227ac90aad0SEric Biggersobj-$(CONFIG_CRYPTO_SELFTESTS_FULL)		+= simd.o
228f4065b2fSHerbert Xu
229f4065b2fSHerbert Xuobj-$(CONFIG_CRYPTO_LIB_SM3)			+= libsm3.o
230f4065b2fSHerbert Xulibsm3-y					:= sm3.o
2314a32e5dcSEric Biggers
2324a32e5dcSEric Biggersobj-$(CONFIG_ARM) += arm/
23361f86c70SEric Biggersobj-$(CONFIG_ARM64) += arm64/
2347e54e993SEric Biggersobj-$(CONFIG_MIPS) += mips/
235676d45abSEric Biggersobj-$(CONFIG_PPC) += powerpc/
236daed4fcfSEric Biggersobj-$(CONFIG_RISCV) += riscv/
237b8456f7aSEric Biggersobj-$(CONFIG_S390) += s390/
23874750aa7SEric Biggersobj-$(CONFIG_X86) += x86/
239fd7e5de4STal Zussman
240fd7e5de4STal Zussman# clean-files must be defined unconditionally
241fd7e5de4STal Zussmanclean-files += arm/sha256-core.S arm/sha512-core.S
242fd7e5de4STal Zussmanclean-files += arm64/sha256-core.S arm64/sha512-core.S
243