From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796275915; b=3aTG5BJmKPOCJ1N3dhPoG4yadKzCaUgCwgPqTG6PQcKQwAYTK/7TU4YXt0m3/VuUNXfU e7Qrha4uOnPq14SXj+rPu85CLKxO8kzqZL2eYsGYfC+QpuRBYE08hB5hUksYA7h2VKo9v Z3GgOIeF+p3KbYeH6PCVC1Z1EuHOohkjjyJ9SuERyj/dTyXxRqAGcgHXPd5M7fHF23r3X CU2rZ6DoHZuBOL0+hkAqk5bGyBWlu2OJUK4m8Hy3oRM93MEDn3qaUqi2U0tV5/ImrceP6 pslMWXd/Se0KMn4aj4rf5Rr7oKP2C51+8itPq3aAyzMFjFo1YHWqGSEz6JXQk8YQSJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796275915; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=6GNT0q0JkWA0CAnU9UfeBGdXz0jfujWAts8a07RfYGs=; b=CxL/T1kPZnDTaqEm3fxaUMX/4Ya/B8tllxWehY8nY6e5bjsKtae6hCtYa2HZ62EWckeg C/ghr+W1DdtFyCb96PyL0LJKs6het1DmDkW9oCjMgSjOUUiZPX8YvidhrLL/UdEFl66Co tk4ZN+tBDkoCQ5m0NcaIUXciuG4R71D0NJZZNxv9HucggI2yi0WgtnyLTHASQIrqpqDrk l2+klECEv1LwnaiXICausUkaevz3hvzyWau89/L1NYnTG7oncjgo+PcnMMx5uU+t4gRYY i+O0Xjup0fl46TixwdVkuT7yRSa7z0SlO9sLz8QJDffXwCVs4YkZHdaGRS3W8Eexymg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Zq/TSecb"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02C71606A32C for ; Thu, 3 Dec 2026 05:31:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Zq/TSecb Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3A271F00896; Thu, 3 Dec 2026 05:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796275914; bh=6GNT0q0JkWA0CAnU9UfeBGdXz0jfujWAts8a07RfYGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Zq/TSecbVBOrlJ28cZXhWCTou2KSn7QFcjmbC9tZa8yaNgnos/Ry/XMvuZdhDd02X PrFGNwIf4JDo6dlCSnb2qEEBcSmdXTTsxYGekMWskjmiZScffT7+lWycEwzFEv344P oDYqQvvxl255x++RzCNpx8gzQcynObWBOzKfCCWb7OLFwh0UI7h9qH0JTaK1swIGuy EvKEpWXPcQhybSUf+AVEsT+uUm7WLq8koVN3HVcq3LWydKGTwfsGwm8Mci7DCPKTU+ hUos5GKZRGCGjF/jVnsGQmvtRaQ+HfD4W1UI932B0ywH3srKFKDe7hbPLptMhRbbkg H8Bnsv7e3IA4A== From: Eric Biggers To: linux-crypto@vger.kernel.org, Herbert Xu Cc: x86@kernel.org, Eric Biggers Subject: [PATCH 1/2] crypto: x86/blowfish - Drop the Blowfish assembly code Date: Wed, 2 Dec 2026 21:31:07 -0800 Message-ID: <20261203053108.67661-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203053108.67661-1-ebiggers@kernel.org> References: <20261203053108.67661-1-ebiggers@kernel.org> X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Blowfish is an early 1990s block cipher with an insufficient 64-bit block size. Since 2007 or possibly even earlier, its designer has recommended against using it. It was also never the default for LUKS. The only plausible reason to still use the kernel's Blowfish code is for data recovery from old archival disks that, in rare cases, users may have chosen to encrypt with Blowfish -- primarily in the early 2000s when it saw some use (but even then, better options were available). But even for that very rare case, and even if we exclude userspace programs which are another option, the generic implementation of Blowfish (CONFIG_CRYPTO_BLOWFISH) is perfectly sufficient. There's no need to maintain an x86 assembly file and its associated glue code too. (Note also that when built as a module, blowfish-x86_64 wasn't even autoloaded at boot by CPU feature. So it already goes unused whenever blowfish_generic is built-in or loaded first, or if the default-off option CONFIG_CRYPTO_BLOWFISH_X86_64 wasn't enabled.) Therefore, drop the x86 implementation of Blowfish. Another benefit of this change is that we'll also be able to delete the blowfish_common module, which existed only to share code. Signed-off-by: Eric Biggers --- arch/x86/crypto/Kconfig | 12 - arch/x86/crypto/Makefile | 3 - arch/x86/crypto/blowfish-x86_64-asm_64.S | 354 ----------------------- arch/x86/crypto/blowfish_glue.c | 196 ------------- 4 files changed, 565 deletions(-) delete mode 100644 arch/x86/crypto/blowfish-x86_64-asm_64.S delete mode 100644 arch/x86/crypto/blowfish_glue.c diff --git a/arch/x86/crypto/Kconfig b/arch/x86/crypto/Kconfig index 20f5e2a17e45a..610693c0207cd 100644 --- a/arch/x86/crypto/Kconfig +++ b/arch/x86/crypto/Kconfig @@ -27,18 +27,6 @@ config CRYPTO_AES_NI_INTEL To ensure dm-crypt continues to work in kconfigs with only this option set, this option selects CRYPTO_AES, CRYPTO_CBC, and CRYPTO_XTS. -config CRYPTO_BLOWFISH_X86_64 - tristate "Ciphers: Blowfish, modes: ECB, CBC" - depends on 64BIT - select CRYPTO_SKCIPHER - select CRYPTO_BLOWFISH_COMMON - imply CRYPTO_CTR - help - Block cipher: Blowfish cipher algorithm - Length-preserving ciphers: Blowfish with ECB and CBC modes - - Architecture: x86_64 - config CRYPTO_CAMELLIA_X86_64 tristate "Ciphers: Camellia with modes: ECB, CBC" depends on 64BIT diff --git a/arch/x86/crypto/Makefile b/arch/x86/crypto/Makefile index 09bdea45bc3e7..11de054fdfe42 100644 --- a/arch/x86/crypto/Makefile +++ b/arch/x86/crypto/Makefile @@ -27,9 +27,6 @@ camellia-aesni-avx-x86_64-y := camellia-aesni-avx-asm_64.o camellia_aesni_avx_gl obj-$(CONFIG_CRYPTO_CAMELLIA_AESNI_AVX2_X86_64) += camellia-aesni-avx2.o camellia-aesni-avx2-y := camellia-aesni-avx2-asm_64.o camellia_aesni_avx2_glue.o -obj-$(CONFIG_CRYPTO_BLOWFISH_X86_64) += blowfish-x86_64.o -blowfish-x86_64-y := blowfish-x86_64-asm_64.o blowfish_glue.o - obj-$(CONFIG_CRYPTO_CAST5_AVX_X86_64) += cast5-avx-x86_64.o cast5-avx-x86_64-y := cast5-avx-x86_64-asm_64.o cast5_avx_glue.o diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S deleted file mode 100644 index e88c8e4f013c5..0000000000000 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S +++ /dev/null @@ -1,354 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Blowfish Cipher Algorithm (x86_64) - * - * Copyright (C) 2011 Jussi Kivilinna - */ - -#include - -.file "blowfish-x86_64-asm.S" -.text - -/* structure of crypto context */ -#define p 0 -#define s0 ((16 + 2) * 4) -#define s1 ((16 + 2 + (1 * 256)) * 4) -#define s2 ((16 + 2 + (2 * 256)) * 4) -#define s3 ((16 + 2 + (3 * 256)) * 4) - -/* register macros */ -#define CTX %r12 -#define RIO %rsi - -#define RX0 %rax -#define RX1 %rbx -#define RX2 %rcx -#define RX3 %rdx - -#define RX0d %eax -#define RX1d %ebx -#define RX2d %ecx -#define RX3d %edx - -#define RX0bl %al -#define RX1bl %bl -#define RX2bl %cl -#define RX3bl %dl - -#define RX0bh %ah -#define RX1bh %bh -#define RX2bh %ch -#define RX3bh %dh - -#define RT0 %rdi -#define RT1 %rsi -#define RT2 %r8 -#define RT3 %r9 - -#define RT0d %edi -#define RT1d %esi -#define RT2d %r8d -#define RT3d %r9d - -#define RKEY %r10 - -/*********************************************************************** - * 1-way blowfish - ***********************************************************************/ -#define F() \ - rorq $16, RX0; \ - movzbl RX0bh, RT0d; \ - movzbl RX0bl, RT1d; \ - rolq $16, RX0; \ - movl s0(CTX,RT0,4), RT0d; \ - addl s1(CTX,RT1,4), RT0d; \ - movzbl RX0bh, RT1d; \ - movzbl RX0bl, RT2d; \ - rolq $32, RX0; \ - xorl s2(CTX,RT1,4), RT0d; \ - addl s3(CTX,RT2,4), RT0d; \ - xorq RT0, RX0; - -#define add_roundkey_enc(n) \ - xorq p+4*(n)(CTX), RX0; - -#define round_enc(n) \ - add_roundkey_enc(n); \ - \ - F(); \ - F(); - -#define add_roundkey_dec(n) \ - movq p+4*(n-1)(CTX), RT0; \ - rorq $32, RT0; \ - xorq RT0, RX0; - -#define round_dec(n) \ - add_roundkey_dec(n); \ - \ - F(); \ - F(); \ - -#define read_block() \ - movq (RIO), RX0; \ - rorq $32, RX0; \ - bswapq RX0; - -#define write_block() \ - bswapq RX0; \ - movq RX0, (RIO); - -SYM_FUNC_START(blowfish_enc_blk) - /* input: - * %rdi: ctx - * %rsi: dst - * %rdx: src - */ - movq %r12, %r11; - - movq %rdi, CTX; - movq %rsi, %r10; - movq %rdx, RIO; - - read_block(); - - round_enc(0); - round_enc(2); - round_enc(4); - round_enc(6); - round_enc(8); - round_enc(10); - round_enc(12); - round_enc(14); - add_roundkey_enc(16); - - movq %r11, %r12; - movq %r10, RIO; - - write_block(); - RET; -SYM_FUNC_END(blowfish_enc_blk) - -SYM_FUNC_START(blowfish_dec_blk) - /* input: - * %rdi: ctx - * %rsi: dst - * %rdx: src - */ - movq %r12, %r11; - - movq %rdi, CTX; - movq %rsi, %r10; - movq %rdx, RIO; - - read_block(); - - round_dec(17); - round_dec(15); - round_dec(13); - round_dec(11); - round_dec(9); - round_dec(7); - round_dec(5); - round_dec(3); - add_roundkey_dec(1); - - movq %r10, RIO; - write_block(); - - movq %r11, %r12; - - RET; -SYM_FUNC_END(blowfish_dec_blk) - -/********************************************************************** - 4-way blowfish, four blocks parallel - **********************************************************************/ - -/* F() for 4-way. Slower when used alone/1-way, but faster when used - * parallel/4-way (tested on AMD Phenom II & Intel Xeon E7330). - */ -#define F4(x) \ - movzbl x ## bh, RT1d; \ - movzbl x ## bl, RT3d; \ - rorq $16, x; \ - movzbl x ## bh, RT0d; \ - movzbl x ## bl, RT2d; \ - rorq $16, x; \ - movl s0(CTX,RT0,4), RT0d; \ - addl s1(CTX,RT2,4), RT0d; \ - xorl s2(CTX,RT1,4), RT0d; \ - addl s3(CTX,RT3,4), RT0d; \ - xorq RT0, x; - -#define add_preloaded_roundkey4() \ - xorq RKEY, RX0; \ - xorq RKEY, RX1; \ - xorq RKEY, RX2; \ - xorq RKEY, RX3; - -#define preload_roundkey_enc(n) \ - movq p+4*(n)(CTX), RKEY; - -#define add_roundkey_enc4(n) \ - add_preloaded_roundkey4(); \ - preload_roundkey_enc(n + 2); - -#define round_enc4(n) \ - add_roundkey_enc4(n); \ - \ - F4(RX0); \ - F4(RX1); \ - F4(RX2); \ - F4(RX3); \ - \ - F4(RX0); \ - F4(RX1); \ - F4(RX2); \ - F4(RX3); - -#define preload_roundkey_dec(n) \ - movq p+4*((n)-1)(CTX), RKEY; \ - rorq $32, RKEY; - -#define add_roundkey_dec4(n) \ - add_preloaded_roundkey4(); \ - preload_roundkey_dec(n - 2); - -#define round_dec4(n) \ - add_roundkey_dec4(n); \ - \ - F4(RX0); \ - F4(RX1); \ - F4(RX2); \ - F4(RX3); \ - \ - F4(RX0); \ - F4(RX1); \ - F4(RX2); \ - F4(RX3); - -#define read_block4() \ - movq (RIO), RX0; \ - rorq $32, RX0; \ - bswapq RX0; \ - \ - movq 8(RIO), RX1; \ - rorq $32, RX1; \ - bswapq RX1; \ - \ - movq 16(RIO), RX2; \ - rorq $32, RX2; \ - bswapq RX2; \ - \ - movq 24(RIO), RX3; \ - rorq $32, RX3; \ - bswapq RX3; - -#define write_block4() \ - bswapq RX0; \ - movq RX0, (RIO); \ - \ - bswapq RX1; \ - movq RX1, 8(RIO); \ - \ - bswapq RX2; \ - movq RX2, 16(RIO); \ - \ - bswapq RX3; \ - movq RX3, 24(RIO); - -#define xor_block4() \ - movq (RIO), RT0; \ - bswapq RT0; \ - xorq RT0, RX1; \ - \ - movq 8(RIO), RT2; \ - bswapq RT2; \ - xorq RT2, RX2; \ - \ - movq 16(RIO), RT3; \ - bswapq RT3; \ - xorq RT3, RX3; - -SYM_FUNC_START(blowfish_enc_blk_4way) - /* input: - * %rdi: ctx - * %rsi: dst - * %rdx: src - */ - pushq %r12; - pushq %rbx; - - movq %rdi, CTX - movq %rsi, %r11; - movq %rdx, RIO; - - preload_roundkey_enc(0); - - read_block4(); - - round_enc4(0); - round_enc4(2); - round_enc4(4); - round_enc4(6); - round_enc4(8); - round_enc4(10); - round_enc4(12); - round_enc4(14); - add_preloaded_roundkey4(); - - movq %r11, RIO; - write_block4(); - - popq %rbx; - popq %r12; - RET; -SYM_FUNC_END(blowfish_enc_blk_4way) - -SYM_FUNC_START(__blowfish_dec_blk_4way) - /* input: - * %rdi: ctx - * %rsi: dst - * %rdx: src - * %rcx: cbc (bool) - */ - pushq %r12; - pushq %rbx; - pushq %rcx; - pushq %rdx; - - movq %rdi, CTX; - movq %rsi, %r11; - movq %rdx, RIO; - - preload_roundkey_dec(17); - read_block4(); - - round_dec4(17); - round_dec4(15); - round_dec4(13); - round_dec4(11); - round_dec4(9); - round_dec4(7); - round_dec4(5); - round_dec4(3); - add_preloaded_roundkey4(); - - popq RIO; - popq %r12; - testq %r12, %r12; - jz .L_no_cbc_xor; - - xor_block4(); - -.L_no_cbc_xor: - movq %r11, RIO; - write_block4(); - - popq %rbx; - popq %r12; - - RET; -SYM_FUNC_END(__blowfish_dec_blk_4way) diff --git a/arch/x86/crypto/blowfish_glue.c b/arch/x86/crypto/blowfish_glue.c deleted file mode 100644 index 26c5f2ee5d103..0000000000000 --- a/arch/x86/crypto/blowfish_glue.c +++ /dev/null @@ -1,196 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Glue Code for assembler optimized version of Blowfish - * - * Copyright (c) 2011 Jussi Kivilinna - * - * CBC & ECB parts based on code (crypto/cbc.c,ecb.c) by: - * Copyright (c) 2006 Herbert Xu - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "ecb_cbc_helpers.h" - -/* regular block cipher functions */ -asmlinkage void blowfish_enc_blk(struct bf_ctx *ctx, u8 *dst, const u8 *src); -asmlinkage void blowfish_dec_blk(struct bf_ctx *ctx, u8 *dst, const u8 *src); - -/* 4-way parallel cipher functions */ -asmlinkage void blowfish_enc_blk_4way(struct bf_ctx *ctx, u8 *dst, - const u8 *src); -asmlinkage void __blowfish_dec_blk_4way(struct bf_ctx *ctx, u8 *dst, - const u8 *src, bool cbc); - -static inline void blowfish_dec_ecb_4way(struct bf_ctx *ctx, u8 *dst, - const u8 *src) -{ - return __blowfish_dec_blk_4way(ctx, dst, src, false); -} - -static inline void blowfish_dec_cbc_4way(struct bf_ctx *ctx, u8 *dst, - const u8 *src) -{ - return __blowfish_dec_blk_4way(ctx, dst, src, true); -} - -static void blowfish_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) -{ - blowfish_enc_blk(crypto_tfm_ctx(tfm), dst, src); -} - -static void blowfish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) -{ - blowfish_dec_blk(crypto_tfm_ctx(tfm), dst, src); -} - -static int blowfish_setkey_skcipher(struct crypto_skcipher *tfm, - const u8 *key, unsigned int keylen) -{ - return blowfish_setkey(&tfm->base, key, keylen); -} - -static int ecb_encrypt(struct skcipher_request *req) -{ - ECB_WALK_START(req, BF_BLOCK_SIZE, -1); - ECB_BLOCK(4, blowfish_enc_blk_4way); - ECB_BLOCK(1, blowfish_enc_blk); - ECB_WALK_END(); -} - -static int ecb_decrypt(struct skcipher_request *req) -{ - ECB_WALK_START(req, BF_BLOCK_SIZE, -1); - ECB_BLOCK(4, blowfish_dec_ecb_4way); - ECB_BLOCK(1, blowfish_dec_blk); - ECB_WALK_END(); -} - -static int cbc_encrypt(struct skcipher_request *req) -{ - CBC_WALK_START(req, BF_BLOCK_SIZE, -1); - CBC_ENC_BLOCK(blowfish_enc_blk); - CBC_WALK_END(); -} - -static int cbc_decrypt(struct skcipher_request *req) -{ - CBC_WALK_START(req, BF_BLOCK_SIZE, -1); - CBC_DEC_BLOCK(4, blowfish_dec_cbc_4way); - CBC_DEC_BLOCK(1, blowfish_dec_blk); - CBC_WALK_END(); -} - -static struct crypto_alg bf_cipher_alg = { - .cra_name = "blowfish", - .cra_driver_name = "blowfish-asm", - .cra_priority = 200, - .cra_flags = CRYPTO_ALG_TYPE_CIPHER, - .cra_blocksize = BF_BLOCK_SIZE, - .cra_ctxsize = sizeof(struct bf_ctx), - .cra_module = THIS_MODULE, - .cra_u = { - .cipher = { - .cia_min_keysize = BF_MIN_KEY_SIZE, - .cia_max_keysize = BF_MAX_KEY_SIZE, - .cia_setkey = blowfish_setkey, - .cia_encrypt = blowfish_encrypt, - .cia_decrypt = blowfish_decrypt, - } - } -}; - -static struct skcipher_alg bf_skcipher_algs[] = { - { - .base.cra_name = "ecb(blowfish)", - .base.cra_driver_name = "ecb-blowfish-asm", - .base.cra_priority = 300, - .base.cra_blocksize = BF_BLOCK_SIZE, - .base.cra_ctxsize = sizeof(struct bf_ctx), - .base.cra_module = THIS_MODULE, - .min_keysize = BF_MIN_KEY_SIZE, - .max_keysize = BF_MAX_KEY_SIZE, - .setkey = blowfish_setkey_skcipher, - .encrypt = ecb_encrypt, - .decrypt = ecb_decrypt, - }, { - .base.cra_name = "cbc(blowfish)", - .base.cra_driver_name = "cbc-blowfish-asm", - .base.cra_priority = 300, - .base.cra_blocksize = BF_BLOCK_SIZE, - .base.cra_ctxsize = sizeof(struct bf_ctx), - .base.cra_module = THIS_MODULE, - .min_keysize = BF_MIN_KEY_SIZE, - .max_keysize = BF_MAX_KEY_SIZE, - .ivsize = BF_BLOCK_SIZE, - .setkey = blowfish_setkey_skcipher, - .encrypt = cbc_encrypt, - .decrypt = cbc_decrypt, - }, -}; - -static bool is_blacklisted_cpu(void) -{ - if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) - return false; - - if (boot_cpu_data.x86 == 0x0f) { - /* - * On Pentium 4, blowfish-x86_64 is slower than generic C - * implementation because use of 64bit rotates (which are really - * slow on P4). Therefore blacklist P4s. - */ - return true; - } - - return false; -} - -static int force; -module_param(force, int, 0); -MODULE_PARM_DESC(force, "Force module load, ignore CPU blacklist"); - -static int __init blowfish_init(void) -{ - int err; - - if (!force && is_blacklisted_cpu()) { - printk(KERN_INFO - "blowfish-x86_64: performance on this CPU " - "would be suboptimal: disabling " - "blowfish-x86_64.\n"); - return -ENODEV; - } - - err = crypto_register_alg(&bf_cipher_alg); - if (err) - return err; - - err = crypto_register_skciphers(bf_skcipher_algs, - ARRAY_SIZE(bf_skcipher_algs)); - if (err) - crypto_unregister_alg(&bf_cipher_alg); - - return err; -} - -static void __exit blowfish_fini(void) -{ - crypto_unregister_alg(&bf_cipher_alg); - crypto_unregister_skciphers(bf_skcipher_algs, - ARRAY_SIZE(bf_skcipher_algs)); -} - -module_init(blowfish_init); -module_exit(blowfish_fini); - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("Blowfish Cipher Algorithm, asm optimized"); -MODULE_ALIAS_CRYPTO("blowfish"); -MODULE_ALIAS_CRYPTO("blowfish-asm"); -- 2.56.1