Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>
Cc: x86@kernel.org, Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH 1/2] crypto: x86/blowfish - Drop the Blowfish assembly code
Date: Wed,  2 Dec 2026 21:31:07 -0800	[thread overview]
Message-ID: <20261203053108.67661-2-ebiggers@kernel.org> (raw)
In-Reply-To: <20261203053108.67661-1-ebiggers@kernel.org>

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 <ebiggers@kernel.org>
---
 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 <jussi.kivilinna@mbnet.fi>
- */
-
-#include <linux/linkage.h>
-
-.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 <jussi.kivilinna@mbnet.fi>
- *
- * CBC & ECB parts based on code (crypto/cbc.c,ecb.c) by:
- *   Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
- */
-
-#include <crypto/algapi.h>
-#include <crypto/blowfish.h>
-#include <crypto/internal/skcipher.h>
-#include <linux/crypto.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/types.h>
-
-#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


  reply	other threads:[~2026-12-03  5:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  5:31 [PATCH 0/2] crypto: Drop the Blowfish assembly code Eric Biggers
2026-12-03  5:31 ` Eric Biggers [this message]
2026-12-03  5:31 ` [PATCH 2/2] crypto: blowfish - Merge blowfish_common into blowfish_generic Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203053108.67661-2-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox