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 18e59c1c98SArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_AES) += libaes.o 19e59c1c98SArd Biesheuvellibaes-y := aes.o 20e59c1c98SArd Biesheuvel 21f1354404SArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_AESCFB) += libaescfb.o 22f1354404SArd Biesheuvellibaescfb-y := aescfb.o 23f1354404SArd Biesheuvel 24520af5daSArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_AESGCM) += libaesgcm.o 25520af5daSArd Biesheuvellibaesgcm-y := aesgcm.o 26520af5daSArd Biesheuvel 27dc51f257SArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_ARC4) += libarc4.o 28dc51f257SArd Biesheuvellibarc4-y := arc4.o 2904007b0eSArd Biesheuvel 3061c581a4SArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_GF128MUL) += gf128mul.o 3161c581a4SArd Biesheuvel 3239ee3970SEric Biggers################################################################################ 3339ee3970SEric Biggers 346048fdccSJason A. Donenfeld# blake2s is used by the /dev/random driver which is always builtin 3539ee3970SEric Biggersobj-y += blake2s.o 3639ee3970SEric Biggersifeq ($(CONFIG_CRYPTO_LIB_BLAKE2S_ARCH),y) 3739ee3970SEric BiggersCFLAGS_blake2s.o += -I$(src)/$(SRCARCH) 3839ee3970SEric Biggersobj-$(CONFIG_ARM) += arm/blake2s-core.o 3939ee3970SEric Biggersobj-$(CONFIG_X86) += x86/blake2s-core.o 4039ee3970SEric Biggersendif 4166d7fb94SJason A. Donenfeld 4213cecc52SEric Biggers################################################################################ 4313cecc52SEric Biggers 4413cecc52SEric Biggers# chacha20_block() is used by the /dev/random driver which is always builtin 4513cecc52SEric Biggersobj-y += chacha-block-generic.o 4613cecc52SEric Biggers 4713cecc52SEric Biggersobj-$(CONFIG_CRYPTO_LIB_CHACHA) += libchacha.o 4813cecc52SEric Biggerslibchacha-y := chacha.o 4913cecc52SEric Biggers 5013cecc52SEric Biggersifeq ($(CONFIG_CRYPTO_LIB_CHACHA_ARCH),y) 5113cecc52SEric BiggersCFLAGS_chacha.o += -I$(src)/$(SRCARCH) 5213cecc52SEric Biggers 5313cecc52SEric Biggersifeq ($(CONFIG_ARM),y) 5413cecc52SEric Biggerslibchacha-y += arm/chacha-scalar-core.o 5513cecc52SEric Biggerslibchacha-$(CONFIG_KERNEL_MODE_NEON) += arm/chacha-neon-core.o 5613cecc52SEric Biggersendif 5713cecc52SEric Biggers 5813cecc52SEric Biggerslibchacha-$(CONFIG_ARM64) += arm64/chacha-neon-core.o 5913cecc52SEric Biggers 6013cecc52SEric Biggersifeq ($(CONFIG_MIPS),y) 6113cecc52SEric Biggerslibchacha-y += mips/chacha-core.o 6213cecc52SEric BiggersAFLAGS_mips/chacha-core.o += -O2 # needed to fill branch delay slots 6313cecc52SEric Biggersendif 6413cecc52SEric Biggers 6513cecc52SEric Biggerslibchacha-$(CONFIG_PPC) += powerpc/chacha-p10le-8x.o 6613cecc52SEric Biggerslibchacha-$(CONFIG_RISCV) += riscv/chacha-riscv64-zvkb.o 6713cecc52SEric Biggerslibchacha-$(CONFIG_S390) += s390/chacha-s390.o 6813cecc52SEric Biggerslibchacha-$(CONFIG_X86) += x86/chacha-ssse3-x86_64.o \ 6913cecc52SEric Biggers x86/chacha-avx2-x86_64.o \ 7013cecc52SEric Biggers x86/chacha-avx512vl-x86_64.o 7113cecc52SEric Biggersendif # CONFIG_CRYPTO_LIB_CHACHA_ARCH 7213cecc52SEric Biggers 7313cecc52SEric Biggers################################################################################ 7413cecc52SEric Biggers 75ed20078bSArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_CHACHA20POLY1305) += libchacha20poly1305.o 76ed20078bSArd Biesheuvellibchacha20poly1305-y += chacha20poly1305.o 7740b99697SEric Biggerslibchacha20poly1305-$(CONFIG_CRYPTO_SELFTESTS) += chacha20poly1305-selftest.o 78ed20078bSArd Biesheuvel 79*68546e56SEric Biggers################################################################################ 80*68546e56SEric Biggers 81*68546e56SEric Biggersobj-$(CONFIG_CRYPTO_LIB_CURVE25519) += libcurve25519.o 82*68546e56SEric Biggerslibcurve25519-y := curve25519.o 83*68546e56SEric Biggers 84*68546e56SEric Biggers# Disable GCOV in odd or sensitive code 85*68546e56SEric BiggersGCOV_PROFILE_curve25519.o := n 86*68546e56SEric Biggers 87*68546e56SEric Biggersifeq ($(CONFIG_ARCH_SUPPORTS_INT128),y) 88*68546e56SEric Biggerslibcurve25519-$(CONFIG_CRYPTO_LIB_CURVE25519_GENERIC) += curve25519-hacl64.o 89*68546e56SEric Biggerselse 90*68546e56SEric Biggerslibcurve25519-$(CONFIG_CRYPTO_LIB_CURVE25519_GENERIC) += curve25519-fiat32.o 91*68546e56SEric Biggersendif 922f13daeeSNathan Chancellor# clang versions prior to 18 may blow out the stack with KASAN 932f13daeeSNathan Chancellorifeq ($(call clang-min-version, 180000),) 942f13daeeSNathan ChancellorKASAN_SANITIZE_curve25519-hacl64.o := n 952f13daeeSNathan Chancellorendif 96a8bdf2c4SHerbert Xu 97*68546e56SEric Biggersifeq ($(CONFIG_CRYPTO_LIB_CURVE25519_ARCH),y) 98*68546e56SEric BiggersCFLAGS_curve25519.o += -I$(src)/$(SRCARCH) 99*68546e56SEric Biggerslibcurve25519-$(CONFIG_ARM) += arm/curve25519-core.o 100*68546e56SEric Biggerslibcurve25519-$(CONFIG_PPC) += powerpc/curve25519-ppc64le_asm.o 101*68546e56SEric Biggersendif 102*68546e56SEric Biggers 103*68546e56SEric Biggers################################################################################ 1040ed42a6fSJason A. Donenfeld 10504007b0eSArd Biesheuvelobj-$(CONFIG_CRYPTO_LIB_DES) += libdes.o 10604007b0eSArd Biesheuvellibdes-y := des.o 10701d3aee8SHans de Goede 108e1644613SEric Biggers################################################################################ 109e1644613SEric Biggers 110e1644613SEric Biggersobj-$(CONFIG_CRYPTO_LIB_MD5) += libmd5.o 111e1644613SEric Biggerslibmd5-y := md5.o 112e1644613SEric Biggersifeq ($(CONFIG_CRYPTO_LIB_MD5_ARCH),y) 113e1644613SEric BiggersCFLAGS_md5.o += -I$(src)/$(SRCARCH) 11409371e13SEric Biggerslibmd5-$(CONFIG_PPC) += powerpc/md5-asm.o 115a1848f6eSEric Biggerslibmd5-$(CONFIG_SPARC) += sparc/md5_asm.o 116e1644613SEric Biggersendif # CONFIG_CRYPTO_LIB_MD5_ARCH 117e1644613SEric Biggers 118e1644613SEric Biggers################################################################################ 119e1644613SEric Biggers 1209b9d4ef0SHerbert Xuobj-$(CONFIG_CRYPTO_LIB_POLY1305) += libpoly1305.o 121b646b782SEric Biggerslibpoly1305-y := poly1305.o 122b646b782SEric Biggersifeq ($(CONFIG_ARCH_SUPPORTS_INT128),y) 123b646b782SEric Biggerslibpoly1305-$(CONFIG_CRYPTO_LIB_POLY1305_GENERIC) += poly1305-donna64.o 124b646b782SEric Biggerselse 125b646b782SEric Biggerslibpoly1305-$(CONFIG_CRYPTO_LIB_POLY1305_GENERIC) += poly1305-donna32.o 126b646b782SEric Biggersendif 12748ea8c6eSArd Biesheuvel 128b646b782SEric Biggersifeq ($(CONFIG_CRYPTO_LIB_POLY1305_ARCH),y) 129b646b782SEric BiggersCFLAGS_poly1305.o += -I$(src)/$(SRCARCH) 130b646b782SEric Biggers 131b646b782SEric Biggersifeq ($(CONFIG_ARM),y) 132b646b782SEric Biggerslibpoly1305-y += arm/poly1305-core.o 133b646b782SEric Biggers$(obj)/arm/poly1305-core.S: $(src)/arm/poly1305-armv4.pl 134b646b782SEric Biggers $(call cmd,perlasm) 135b646b782SEric Biggers# massage the perlasm code a bit so we only get the NEON routine if we need it 136b646b782SEric Biggerspoly1305-aflags-$(CONFIG_CPU_V7) := -U__LINUX_ARM_ARCH__ -D__LINUX_ARM_ARCH__=5 137b646b782SEric Biggerspoly1305-aflags-$(CONFIG_KERNEL_MODE_NEON) := -U__LINUX_ARM_ARCH__ -D__LINUX_ARM_ARCH__=7 138b646b782SEric BiggersAFLAGS_arm/poly1305-core.o += $(poly1305-aflags-y) $(aflags-thumb2-y) 139b646b782SEric Biggersendif 140b646b782SEric Biggers 141b646b782SEric Biggersifeq ($(CONFIG_ARM64),y) 142b646b782SEric Biggerslibpoly1305-y += arm64/poly1305-core.o 143b646b782SEric Biggers$(obj)/arm64/poly1305-core.S: $(src)/arm64/poly1305-armv8.pl 144b646b782SEric Biggers $(call cmd,perlasm_with_args) 145b646b782SEric Biggersendif 146b646b782SEric Biggers 147b646b782SEric Biggersifeq ($(CONFIG_MIPS),y) 148b646b782SEric Biggerslibpoly1305-y += mips/poly1305-core.o 149b646b782SEric Biggerspoly1305-perlasm-flavour-$(CONFIG_32BIT) := o32 150b646b782SEric Biggerspoly1305-perlasm-flavour-$(CONFIG_64BIT) := 64 151b646b782SEric Biggersquiet_cmd_perlasm_poly1305 = PERLASM $@ 152b646b782SEric Biggers cmd_perlasm_poly1305 = $(PERL) $< $(poly1305-perlasm-flavour-y) $@ 153b646b782SEric Biggers# Use if_changed instead of cmd, in case the flavour changed. 154b646b782SEric Biggers$(obj)/mips/poly1305-core.S: $(src)/mips/poly1305-mips.pl FORCE 155b646b782SEric Biggers $(call if_changed,perlasm_poly1305) 156b646b782SEric Biggerstargets += mips/poly1305-core.S 157b646b782SEric Biggersendif 158b646b782SEric Biggers 159b646b782SEric Biggerslibpoly1305-$(CONFIG_PPC) += powerpc/poly1305-p10le_64.o 160b646b782SEric Biggers 161bef9c755SZhihang Shaoifeq ($(CONFIG_RISCV),y) 162bef9c755SZhihang Shaolibpoly1305-y += riscv/poly1305-core.o 163bef9c755SZhihang Shaopoly1305-perlasm-flavour-$(CONFIG_32BIT) := 32 164bef9c755SZhihang Shaopoly1305-perlasm-flavour-$(CONFIG_64BIT) := 64 165bef9c755SZhihang Shaoquiet_cmd_perlasm_poly1305 = PERLASM $@ 166bef9c755SZhihang Shao cmd_perlasm_poly1305 = $(PERL) $< $(poly1305-perlasm-flavour-y) $@ 167bef9c755SZhihang Shao# Use if_changed instead of cmd, in case the flavour changed. 168bef9c755SZhihang Shao$(obj)/riscv/poly1305-core.S: $(src)/riscv/poly1305-riscv.pl FORCE 169bef9c755SZhihang Shao $(call if_changed,perlasm_poly1305) 170bef9c755SZhihang Shaotargets += riscv/poly1305-core.S 171bef9c755SZhihang ShaoAFLAGS_riscv/poly1305-core.o += -Dpoly1305_init=poly1305_block_init 172bef9c755SZhihang Shaoendif 173bef9c755SZhihang Shao 174b646b782SEric Biggersifeq ($(CONFIG_X86),y) 175b646b782SEric Biggerslibpoly1305-y += x86/poly1305-x86_64-cryptogams.o 176b646b782SEric Biggers$(obj)/x86/poly1305-x86_64-cryptogams.S: $(src)/x86/poly1305-x86_64-cryptogams.pl 177b646b782SEric Biggers $(call cmd,perlasm) 178b646b782SEric Biggersendif 179b646b782SEric Biggers 180b646b782SEric Biggersendif # CONFIG_CRYPTO_LIB_POLY1305_ARCH 181b646b782SEric Biggers 182b646b782SEric Biggers# clean-files must be defined unconditionally 183b646b782SEric Biggersclean-files += arm/poly1305-core.S \ 184b646b782SEric Biggers arm64/poly1305-core.S \ 185b646b782SEric Biggers mips/poly1305-core.S \ 186bef9c755SZhihang Shao riscv/poly1305-core.S \ 187b646b782SEric Biggers x86/poly1305-x86_64-cryptogams.S 1889b9d4ef0SHerbert Xu 18990860aefSEric Biggers################################################################################ 19090860aefSEric Biggers 191ec8f7f48SEric Biggersobj-$(CONFIG_CRYPTO_LIB_SHA1) += libsha1.o 192ec8f7f48SEric Biggerslibsha1-y := sha1.o 19390860aefSEric Biggersifeq ($(CONFIG_CRYPTO_LIB_SHA1_ARCH),y) 19490860aefSEric BiggersCFLAGS_sha1.o += -I$(src)/$(SRCARCH) 19570cb6ca5SEric Biggersifeq ($(CONFIG_ARM),y) 19670cb6ca5SEric Biggerslibsha1-y += arm/sha1-armv4-large.o 19770cb6ca5SEric Biggerslibsha1-$(CONFIG_KERNEL_MODE_NEON) += arm/sha1-armv7-neon.o \ 19870cb6ca5SEric Biggers arm/sha1-ce-core.o 19970cb6ca5SEric Biggersendif 20000d549bbSEric Biggerslibsha1-$(CONFIG_ARM64) += arm64/sha1-ce-core.o 2016b9ae8cfSEric Biggersifeq ($(CONFIG_PPC),y) 2026b9ae8cfSEric Biggerslibsha1-y += powerpc/sha1-powerpc-asm.o 2036b9ae8cfSEric Biggerslibsha1-$(CONFIG_SPE) += powerpc/sha1-spe-asm.o 2046b9ae8cfSEric Biggersendif 205c7510599SEric Biggerslibsha1-$(CONFIG_SPARC) += sparc/sha1_asm.o 206f3d6cb3dSEric Biggerslibsha1-$(CONFIG_X86) += x86/sha1-ssse3-and-avx.o \ 207f3d6cb3dSEric Biggers x86/sha1-avx2-asm.o \ 208f3d6cb3dSEric Biggers x86/sha1-ni-asm.o 20990860aefSEric Biggersendif # CONFIG_CRYPTO_LIB_SHA1_ARCH 210463f7408SEric Biggers 211e96cb950SEric Biggers################################################################################ 212e96cb950SEric Biggers 21301d3aee8SHans de Goedeobj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o 21401d3aee8SHans de Goedelibsha256-y := sha256.o 215e96cb950SEric Biggersifeq ($(CONFIG_CRYPTO_LIB_SHA256_ARCH),y) 216e96cb950SEric BiggersCFLAGS_sha256.o += -I$(src)/$(SRCARCH) 21766d7fb94SJason A. Donenfeld 218e96cb950SEric Biggersifeq ($(CONFIG_ARM),y) 219e96cb950SEric Biggerslibsha256-y += arm/sha256-ce.o arm/sha256-core.o 220e96cb950SEric Biggers$(obj)/arm/sha256-core.S: $(src)/arm/sha256-armv4.pl 221e96cb950SEric Biggers $(call cmd,perlasm) 222e96cb950SEric BiggersAFLAGS_arm/sha256-core.o += $(aflags-thumb2-y) 223e96cb950SEric Biggersendif 224e96cb950SEric Biggers 225e96cb950SEric Biggersifeq ($(CONFIG_ARM64),y) 226e96cb950SEric Biggerslibsha256-y += arm64/sha256-core.o 227e96cb950SEric Biggers$(obj)/arm64/sha256-core.S: $(src)/arm64/sha2-armv8.pl 228e96cb950SEric Biggers $(call cmd,perlasm_with_args) 229e96cb950SEric Biggerslibsha256-$(CONFIG_KERNEL_MODE_NEON) += arm64/sha256-ce.o 230e96cb950SEric Biggersendif 231e96cb950SEric Biggers 232e96cb950SEric Biggerslibsha256-$(CONFIG_PPC) += powerpc/sha256-spe-asm.o 233e96cb950SEric Biggerslibsha256-$(CONFIG_RISCV) += riscv/sha256-riscv64-zvknha_or_zvknhb-zvkb.o 234e96cb950SEric Biggerslibsha256-$(CONFIG_SPARC) += sparc/sha256_asm.o 235e96cb950SEric Biggerslibsha256-$(CONFIG_X86) += x86/sha256-ssse3-asm.o \ 236e96cb950SEric Biggers x86/sha256-avx-asm.o \ 237e96cb950SEric Biggers x86/sha256-avx2-asm.o \ 238e96cb950SEric Biggers x86/sha256-ni-asm.o 239e96cb950SEric Biggersendif # CONFIG_CRYPTO_LIB_SHA256_ARCH 240e96cb950SEric Biggers 241e96cb950SEric Biggers################################################################################ 242950e5c84SEric Biggers 243b693c703SEric Biggersobj-$(CONFIG_CRYPTO_LIB_SHA512) += libsha512.o 244b693c703SEric Biggerslibsha512-y := sha512.o 245b693c703SEric Biggersifeq ($(CONFIG_CRYPTO_LIB_SHA512_ARCH),y) 246b693c703SEric BiggersCFLAGS_sha512.o += -I$(src)/$(SRCARCH) 24724c91b62SEric Biggers 24824c91b62SEric Biggersifeq ($(CONFIG_ARM),y) 24924c91b62SEric Biggerslibsha512-y += arm/sha512-core.o 25024c91b62SEric Biggers$(obj)/arm/sha512-core.S: $(src)/arm/sha512-armv4.pl 25124c91b62SEric Biggers $(call cmd,perlasm) 25224c91b62SEric BiggersAFLAGS_arm/sha512-core.o += $(aflags-thumb2-y) 25324c91b62SEric Biggersendif 25424c91b62SEric Biggers 25560e3f1e9SEric Biggersifeq ($(CONFIG_ARM64),y) 25660e3f1e9SEric Biggerslibsha512-y += arm64/sha512-core.o 25761f86c70SEric Biggers$(obj)/arm64/sha512-core.S: $(src)/arm64/sha2-armv8.pl 25860e3f1e9SEric Biggers $(call cmd,perlasm_with_args) 25960e3f1e9SEric Biggerslibsha512-$(CONFIG_KERNEL_MODE_NEON) += arm64/sha512-ce-core.o 26060e3f1e9SEric Biggersendif 261b59059a2SEric Biggers 262b59059a2SEric Biggerslibsha512-$(CONFIG_RISCV) += riscv/sha512-riscv64-zvknhb-zvkb.o 26302b35babSEric Biggerslibsha512-$(CONFIG_SPARC) += sparc/sha512_asm.o 264484c1811SEric Biggerslibsha512-$(CONFIG_X86) += x86/sha512-ssse3-asm.o \ 265484c1811SEric Biggers x86/sha512-avx-asm.o \ 266484c1811SEric Biggers x86/sha512-avx2-asm.o 267b693c703SEric Biggersendif # CONFIG_CRYPTO_LIB_SHA512_ARCH 268b693c703SEric Biggers 269e96cb950SEric Biggers################################################################################ 270e96cb950SEric Biggers 2712a598d0bSHerbert Xuobj-$(CONFIG_MPILIB) += mpi/ 2724964a1d9SEric Biggers 273ac90aad0SEric Biggersobj-$(CONFIG_CRYPTO_SELFTESTS_FULL) += simd.o 274f4065b2fSHerbert Xu 275f4065b2fSHerbert Xuobj-$(CONFIG_CRYPTO_LIB_SM3) += libsm3.o 276f4065b2fSHerbert Xulibsm3-y := sm3.o 2774a32e5dcSEric Biggers 278fd7e5de4STal Zussman# clean-files must be defined unconditionally 279fd7e5de4STal Zussmanclean-files += arm/sha256-core.S arm/sha512-core.S 280fd7e5de4STal Zussmanclean-files += arm64/sha256-core.S arm64/sha512-core.S 281