From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org,
sparclinux@vger.kernel.org, x86@kernel.org,
Harald Freudenberger <freude@linux.ibm.com>,
Holger Dengler <dengler@linux.ibm.com>,
Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH 2/3] crypto: sparc - Remove des and des3_ede code
Date: Thu, 26 Mar 2026 13:12:44 -0700 [thread overview]
Message-ID: <20260326201246.57544-3-ebiggers@kernel.org> (raw)
In-Reply-To: <20260326201246.57544-1-ebiggers@kernel.org>
Since DES and Triple DES are obsolete, there is very little point in
maintining architecture-optimized code for them. Remove it.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
arch/sparc/crypto/Kconfig | 14 -
arch/sparc/crypto/Makefile | 2 -
arch/sparc/crypto/des_asm.S | 419 ------------------------------
arch/sparc/crypto/des_glue.c | 482 -----------------------------------
4 files changed, 917 deletions(-)
delete mode 100644 arch/sparc/crypto/des_asm.S
delete mode 100644 arch/sparc/crypto/des_glue.c
diff --git a/arch/sparc/crypto/Kconfig b/arch/sparc/crypto/Kconfig
index c1932ce46c7f..8db3f6eea5dc 100644
--- a/arch/sparc/crypto/Kconfig
+++ b/arch/sparc/crypto/Kconfig
@@ -1,23 +1,9 @@
# SPDX-License-Identifier: GPL-2.0
menu "Accelerated Cryptographic Algorithms for CPU (sparc64)"
-config CRYPTO_DES_SPARC64
- tristate "Ciphers: DES and Triple DES EDE, modes: ECB/CBC"
- depends on SPARC64
- select CRYPTO_ALGAPI
- select CRYPTO_LIB_DES
- select CRYPTO_SKCIPHER
- help
- Block cipher: DES (FIPS 46-2) cipher algorithm
- Block cipher: Triple DES EDE (FIPS 46-3) cipher algorithm
- Length-preserving ciphers: DES with ECB and CBC modes
- Length-preserving ciphers: Tripe DES EDE with ECB and CBC modes
-
- Architecture: sparc64
-
config CRYPTO_AES_SPARC64
tristate "Ciphers: AES, modes: ECB, CBC, CTR"
depends on SPARC64
select CRYPTO_LIB_AES
select CRYPTO_SKCIPHER
diff --git a/arch/sparc/crypto/Makefile b/arch/sparc/crypto/Makefile
index cdf9f4b3efbb..ab4a7765babf 100644
--- a/arch/sparc/crypto/Makefile
+++ b/arch/sparc/crypto/Makefile
@@ -2,11 +2,9 @@
#
# Arch-specific CryptoAPI modules.
#
obj-$(CONFIG_CRYPTO_AES_SPARC64) += aes-sparc64.o
-obj-$(CONFIG_CRYPTO_DES_SPARC64) += des-sparc64.o
obj-$(CONFIG_CRYPTO_CAMELLIA_SPARC64) += camellia-sparc64.o
aes-sparc64-y := aes_glue.o
-des-sparc64-y := des_asm.o des_glue.o
camellia-sparc64-y := camellia_asm.o camellia_glue.o
diff --git a/arch/sparc/crypto/des_asm.S b/arch/sparc/crypto/des_asm.S
deleted file mode 100644
index d534446cbef9..000000000000
--- a/arch/sparc/crypto/des_asm.S
+++ /dev/null
@@ -1,419 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#include <linux/linkage.h>
-#include <asm/opcodes.h>
-#include <asm/visasm.h>
-
- .align 32
-ENTRY(des_sparc64_key_expand)
- /* %o0=input_key, %o1=output_key */
- VISEntryHalf
- ld [%o0 + 0x00], %f0
- ld [%o0 + 0x04], %f1
- DES_KEXPAND(0, 0, 0)
- DES_KEXPAND(0, 1, 2)
- DES_KEXPAND(2, 3, 6)
- DES_KEXPAND(2, 2, 4)
- DES_KEXPAND(6, 3, 10)
- DES_KEXPAND(6, 2, 8)
- DES_KEXPAND(10, 3, 14)
- DES_KEXPAND(10, 2, 12)
- DES_KEXPAND(14, 1, 16)
- DES_KEXPAND(16, 3, 20)
- DES_KEXPAND(16, 2, 18)
- DES_KEXPAND(20, 3, 24)
- DES_KEXPAND(20, 2, 22)
- DES_KEXPAND(24, 3, 28)
- DES_KEXPAND(24, 2, 26)
- DES_KEXPAND(28, 1, 30)
- std %f0, [%o1 + 0x00]
- std %f2, [%o1 + 0x08]
- std %f4, [%o1 + 0x10]
- std %f6, [%o1 + 0x18]
- std %f8, [%o1 + 0x20]
- std %f10, [%o1 + 0x28]
- std %f12, [%o1 + 0x30]
- std %f14, [%o1 + 0x38]
- std %f16, [%o1 + 0x40]
- std %f18, [%o1 + 0x48]
- std %f20, [%o1 + 0x50]
- std %f22, [%o1 + 0x58]
- std %f24, [%o1 + 0x60]
- std %f26, [%o1 + 0x68]
- std %f28, [%o1 + 0x70]
- std %f30, [%o1 + 0x78]
- retl
- VISExitHalf
-ENDPROC(des_sparc64_key_expand)
-
- .align 32
-ENTRY(des_sparc64_crypt)
- /* %o0=key, %o1=input, %o2=output */
- VISEntry
- ldd [%o1 + 0x00], %f32
- ldd [%o0 + 0x00], %f0
- ldd [%o0 + 0x08], %f2
- ldd [%o0 + 0x10], %f4
- ldd [%o0 + 0x18], %f6
- ldd [%o0 + 0x20], %f8
- ldd [%o0 + 0x28], %f10
- ldd [%o0 + 0x30], %f12
- ldd [%o0 + 0x38], %f14
- ldd [%o0 + 0x40], %f16
- ldd [%o0 + 0x48], %f18
- ldd [%o0 + 0x50], %f20
- ldd [%o0 + 0x58], %f22
- ldd [%o0 + 0x60], %f24
- ldd [%o0 + 0x68], %f26
- ldd [%o0 + 0x70], %f28
- ldd [%o0 + 0x78], %f30
- DES_IP(32, 32)
- DES_ROUND(0, 2, 32, 32)
- DES_ROUND(4, 6, 32, 32)
- DES_ROUND(8, 10, 32, 32)
- DES_ROUND(12, 14, 32, 32)
- DES_ROUND(16, 18, 32, 32)
- DES_ROUND(20, 22, 32, 32)
- DES_ROUND(24, 26, 32, 32)
- DES_ROUND(28, 30, 32, 32)
- DES_IIP(32, 32)
- std %f32, [%o2 + 0x00]
- retl
- VISExit
-ENDPROC(des_sparc64_crypt)
-
- .align 32
-ENTRY(des_sparc64_load_keys)
- /* %o0=key */
- VISEntry
- ldd [%o0 + 0x00], %f0
- ldd [%o0 + 0x08], %f2
- ldd [%o0 + 0x10], %f4
- ldd [%o0 + 0x18], %f6
- ldd [%o0 + 0x20], %f8
- ldd [%o0 + 0x28], %f10
- ldd [%o0 + 0x30], %f12
- ldd [%o0 + 0x38], %f14
- ldd [%o0 + 0x40], %f16
- ldd [%o0 + 0x48], %f18
- ldd [%o0 + 0x50], %f20
- ldd [%o0 + 0x58], %f22
- ldd [%o0 + 0x60], %f24
- ldd [%o0 + 0x68], %f26
- ldd [%o0 + 0x70], %f28
- retl
- ldd [%o0 + 0x78], %f30
-ENDPROC(des_sparc64_load_keys)
-
- .align 32
-ENTRY(des_sparc64_ecb_crypt)
- /* %o0=input, %o1=output, %o2=len */
-1: ldd [%o0 + 0x00], %f32
- add %o0, 0x08, %o0
- DES_IP(32, 32)
- DES_ROUND(0, 2, 32, 32)
- DES_ROUND(4, 6, 32, 32)
- DES_ROUND(8, 10, 32, 32)
- DES_ROUND(12, 14, 32, 32)
- DES_ROUND(16, 18, 32, 32)
- DES_ROUND(20, 22, 32, 32)
- DES_ROUND(24, 26, 32, 32)
- DES_ROUND(28, 30, 32, 32)
- DES_IIP(32, 32)
- std %f32, [%o1 + 0x00]
- subcc %o2, 0x08, %o2
- bne,pt %icc, 1b
- add %o1, 0x08, %o1
- retl
- nop
-ENDPROC(des_sparc64_ecb_crypt)
-
- .align 32
-ENTRY(des_sparc64_cbc_encrypt)
- /* %o0=input, %o1=output, %o2=len, %o3=IV */
- ldd [%o3 + 0x00], %f32
-1: ldd [%o0 + 0x00], %f34
- fxor %f32, %f34, %f32
- DES_IP(32, 32)
- DES_ROUND(0, 2, 32, 32)
- DES_ROUND(4, 6, 32, 32)
- DES_ROUND(8, 10, 32, 32)
- DES_ROUND(12, 14, 32, 32)
- DES_ROUND(16, 18, 32, 32)
- DES_ROUND(20, 22, 32, 32)
- DES_ROUND(24, 26, 32, 32)
- DES_ROUND(28, 30, 32, 32)
- DES_IIP(32, 32)
- std %f32, [%o1 + 0x00]
- add %o0, 0x08, %o0
- subcc %o2, 0x08, %o2
- bne,pt %icc, 1b
- add %o1, 0x08, %o1
- retl
- std %f32, [%o3 + 0x00]
-ENDPROC(des_sparc64_cbc_encrypt)
-
- .align 32
-ENTRY(des_sparc64_cbc_decrypt)
- /* %o0=input, %o1=output, %o2=len, %o3=IV */
- ldd [%o3 + 0x00], %f34
-1: ldd [%o0 + 0x00], %f36
- DES_IP(36, 32)
- DES_ROUND(0, 2, 32, 32)
- DES_ROUND(4, 6, 32, 32)
- DES_ROUND(8, 10, 32, 32)
- DES_ROUND(12, 14, 32, 32)
- DES_ROUND(16, 18, 32, 32)
- DES_ROUND(20, 22, 32, 32)
- DES_ROUND(24, 26, 32, 32)
- DES_ROUND(28, 30, 32, 32)
- DES_IIP(32, 32)
- fxor %f32, %f34, %f32
- fsrc2 %f36, %f34
- std %f32, [%o1 + 0x00]
- add %o0, 0x08, %o0
- subcc %o2, 0x08, %o2
- bne,pt %icc, 1b
- add %o1, 0x08, %o1
- retl
- std %f36, [%o3 + 0x00]
-ENDPROC(des_sparc64_cbc_decrypt)
-
- .align 32
-ENTRY(des3_ede_sparc64_crypt)
- /* %o0=key, %o1=input, %o2=output */
- VISEntry
- ldd [%o1 + 0x00], %f32
- ldd [%o0 + 0x00], %f0
- ldd [%o0 + 0x08], %f2
- ldd [%o0 + 0x10], %f4
- ldd [%o0 + 0x18], %f6
- ldd [%o0 + 0x20], %f8
- ldd [%o0 + 0x28], %f10
- ldd [%o0 + 0x30], %f12
- ldd [%o0 + 0x38], %f14
- ldd [%o0 + 0x40], %f16
- ldd [%o0 + 0x48], %f18
- ldd [%o0 + 0x50], %f20
- ldd [%o0 + 0x58], %f22
- ldd [%o0 + 0x60], %f24
- ldd [%o0 + 0x68], %f26
- ldd [%o0 + 0x70], %f28
- ldd [%o0 + 0x78], %f30
- DES_IP(32, 32)
- DES_ROUND(0, 2, 32, 32)
- ldd [%o0 + 0x80], %f0
- ldd [%o0 + 0x88], %f2
- DES_ROUND(4, 6, 32, 32)
- ldd [%o0 + 0x90], %f4
- ldd [%o0 + 0x98], %f6
- DES_ROUND(8, 10, 32, 32)
- ldd [%o0 + 0xa0], %f8
- ldd [%o0 + 0xa8], %f10
- DES_ROUND(12, 14, 32, 32)
- ldd [%o0 + 0xb0], %f12
- ldd [%o0 + 0xb8], %f14
- DES_ROUND(16, 18, 32, 32)
- ldd [%o0 + 0xc0], %f16
- ldd [%o0 + 0xc8], %f18
- DES_ROUND(20, 22, 32, 32)
- ldd [%o0 + 0xd0], %f20
- ldd [%o0 + 0xd8], %f22
- DES_ROUND(24, 26, 32, 32)
- ldd [%o0 + 0xe0], %f24
- ldd [%o0 + 0xe8], %f26
- DES_ROUND(28, 30, 32, 32)
- ldd [%o0 + 0xf0], %f28
- ldd [%o0 + 0xf8], %f30
- DES_IIP(32, 32)
- DES_IP(32, 32)
- DES_ROUND(0, 2, 32, 32)
- ldd [%o0 + 0x100], %f0
- ldd [%o0 + 0x108], %f2
- DES_ROUND(4, 6, 32, 32)
- ldd [%o0 + 0x110], %f4
- ldd [%o0 + 0x118], %f6
- DES_ROUND(8, 10, 32, 32)
- ldd [%o0 + 0x120], %f8
- ldd [%o0 + 0x128], %f10
- DES_ROUND(12, 14, 32, 32)
- ldd [%o0 + 0x130], %f12
- ldd [%o0 + 0x138], %f14
- DES_ROUND(16, 18, 32, 32)
- ldd [%o0 + 0x140], %f16
- ldd [%o0 + 0x148], %f18
- DES_ROUND(20, 22, 32, 32)
- ldd [%o0 + 0x150], %f20
- ldd [%o0 + 0x158], %f22
- DES_ROUND(24, 26, 32, 32)
- ldd [%o0 + 0x160], %f24
- ldd [%o0 + 0x168], %f26
- DES_ROUND(28, 30, 32, 32)
- ldd [%o0 + 0x170], %f28
- ldd [%o0 + 0x178], %f30
- DES_IIP(32, 32)
- DES_IP(32, 32)
- DES_ROUND(0, 2, 32, 32)
- DES_ROUND(4, 6, 32, 32)
- DES_ROUND(8, 10, 32, 32)
- DES_ROUND(12, 14, 32, 32)
- DES_ROUND(16, 18, 32, 32)
- DES_ROUND(20, 22, 32, 32)
- DES_ROUND(24, 26, 32, 32)
- DES_ROUND(28, 30, 32, 32)
- DES_IIP(32, 32)
-
- std %f32, [%o2 + 0x00]
- retl
- VISExit
-ENDPROC(des3_ede_sparc64_crypt)
-
- .align 32
-ENTRY(des3_ede_sparc64_load_keys)
- /* %o0=key */
- VISEntry
- ldd [%o0 + 0x00], %f0
- ldd [%o0 + 0x08], %f2
- ldd [%o0 + 0x10], %f4
- ldd [%o0 + 0x18], %f6
- ldd [%o0 + 0x20], %f8
- ldd [%o0 + 0x28], %f10
- ldd [%o0 + 0x30], %f12
- ldd [%o0 + 0x38], %f14
- ldd [%o0 + 0x40], %f16
- ldd [%o0 + 0x48], %f18
- ldd [%o0 + 0x50], %f20
- ldd [%o0 + 0x58], %f22
- ldd [%o0 + 0x60], %f24
- ldd [%o0 + 0x68], %f26
- ldd [%o0 + 0x70], %f28
- ldd [%o0 + 0x78], %f30
- ldd [%o0 + 0x80], %f32
- ldd [%o0 + 0x88], %f34
- ldd [%o0 + 0x90], %f36
- ldd [%o0 + 0x98], %f38
- ldd [%o0 + 0xa0], %f40
- ldd [%o0 + 0xa8], %f42
- ldd [%o0 + 0xb0], %f44
- ldd [%o0 + 0xb8], %f46
- ldd [%o0 + 0xc0], %f48
- ldd [%o0 + 0xc8], %f50
- ldd [%o0 + 0xd0], %f52
- ldd [%o0 + 0xd8], %f54
- ldd [%o0 + 0xe0], %f56
- retl
- ldd [%o0 + 0xe8], %f58
-ENDPROC(des3_ede_sparc64_load_keys)
-
-#define DES3_LOOP_BODY(X) \
- DES_IP(X, X) \
- DES_ROUND(0, 2, X, X) \
- DES_ROUND(4, 6, X, X) \
- DES_ROUND(8, 10, X, X) \
- DES_ROUND(12, 14, X, X) \
- DES_ROUND(16, 18, X, X) \
- ldd [%o0 + 0xf0], %f16; \
- ldd [%o0 + 0xf8], %f18; \
- DES_ROUND(20, 22, X, X) \
- ldd [%o0 + 0x100], %f20; \
- ldd [%o0 + 0x108], %f22; \
- DES_ROUND(24, 26, X, X) \
- ldd [%o0 + 0x110], %f24; \
- ldd [%o0 + 0x118], %f26; \
- DES_ROUND(28, 30, X, X) \
- ldd [%o0 + 0x120], %f28; \
- ldd [%o0 + 0x128], %f30; \
- DES_IIP(X, X) \
- DES_IP(X, X) \
- DES_ROUND(32, 34, X, X) \
- ldd [%o0 + 0x130], %f0; \
- ldd [%o0 + 0x138], %f2; \
- DES_ROUND(36, 38, X, X) \
- ldd [%o0 + 0x140], %f4; \
- ldd [%o0 + 0x148], %f6; \
- DES_ROUND(40, 42, X, X) \
- ldd [%o0 + 0x150], %f8; \
- ldd [%o0 + 0x158], %f10; \
- DES_ROUND(44, 46, X, X) \
- ldd [%o0 + 0x160], %f12; \
- ldd [%o0 + 0x168], %f14; \
- DES_ROUND(48, 50, X, X) \
- DES_ROUND(52, 54, X, X) \
- DES_ROUND(56, 58, X, X) \
- DES_ROUND(16, 18, X, X) \
- ldd [%o0 + 0x170], %f16; \
- ldd [%o0 + 0x178], %f18; \
- DES_IIP(X, X) \
- DES_IP(X, X) \
- DES_ROUND(20, 22, X, X) \
- ldd [%o0 + 0x50], %f20; \
- ldd [%o0 + 0x58], %f22; \
- DES_ROUND(24, 26, X, X) \
- ldd [%o0 + 0x60], %f24; \
- ldd [%o0 + 0x68], %f26; \
- DES_ROUND(28, 30, X, X) \
- ldd [%o0 + 0x70], %f28; \
- ldd [%o0 + 0x78], %f30; \
- DES_ROUND(0, 2, X, X) \
- ldd [%o0 + 0x00], %f0; \
- ldd [%o0 + 0x08], %f2; \
- DES_ROUND(4, 6, X, X) \
- ldd [%o0 + 0x10], %f4; \
- ldd [%o0 + 0x18], %f6; \
- DES_ROUND(8, 10, X, X) \
- ldd [%o0 + 0x20], %f8; \
- ldd [%o0 + 0x28], %f10; \
- DES_ROUND(12, 14, X, X) \
- ldd [%o0 + 0x30], %f12; \
- ldd [%o0 + 0x38], %f14; \
- DES_ROUND(16, 18, X, X) \
- ldd [%o0 + 0x40], %f16; \
- ldd [%o0 + 0x48], %f18; \
- DES_IIP(X, X)
-
- .align 32
-ENTRY(des3_ede_sparc64_ecb_crypt)
- /* %o0=key, %o1=input, %o2=output, %o3=len */
-1: ldd [%o1 + 0x00], %f60
- DES3_LOOP_BODY(60)
- std %f60, [%o2 + 0x00]
- add %o1, 0x08, %o1
- subcc %o3, 0x08, %o3
- bne,pt %icc, 1b
- add %o2, 0x08, %o2
- retl
- nop
-ENDPROC(des3_ede_sparc64_ecb_crypt)
-
- .align 32
-ENTRY(des3_ede_sparc64_cbc_encrypt)
- /* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
- ldd [%o4 + 0x00], %f60
-1: ldd [%o1 + 0x00], %f62
- fxor %f60, %f62, %f60
- DES3_LOOP_BODY(60)
- std %f60, [%o2 + 0x00]
- add %o1, 0x08, %o1
- subcc %o3, 0x08, %o3
- bne,pt %icc, 1b
- add %o2, 0x08, %o2
- retl
- std %f60, [%o4 + 0x00]
-ENDPROC(des3_ede_sparc64_cbc_encrypt)
-
- .align 32
-ENTRY(des3_ede_sparc64_cbc_decrypt)
- /* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
- ldd [%o4 + 0x00], %f62
-1: ldx [%o1 + 0x00], %g1
- MOVXTOD_G1_F60
- DES3_LOOP_BODY(60)
- fxor %f62, %f60, %f60
- MOVXTOD_G1_F62
- std %f60, [%o2 + 0x00]
- add %o1, 0x08, %o1
- subcc %o3, 0x08, %o3
- bne,pt %icc, 1b
- add %o2, 0x08, %o2
- retl
- stx %g1, [%o4 + 0x00]
-ENDPROC(des3_ede_sparc64_cbc_decrypt)
diff --git a/arch/sparc/crypto/des_glue.c b/arch/sparc/crypto/des_glue.c
deleted file mode 100644
index e50ec4cd57cd..000000000000
--- a/arch/sparc/crypto/des_glue.c
+++ /dev/null
@@ -1,482 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/* Glue code for DES encryption optimized for sparc64 crypto opcodes.
- *
- * Copyright (C) 2012 David S. Miller <davem@davemloft.net>
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/crypto.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/mm.h>
-#include <linux/types.h>
-#include <crypto/algapi.h>
-#include <crypto/internal/des.h>
-#include <crypto/internal/skcipher.h>
-
-#include <asm/fpumacro.h>
-#include <asm/opcodes.h>
-#include <asm/pstate.h>
-#include <asm/elf.h>
-
-struct des_sparc64_ctx {
- u64 encrypt_expkey[DES_EXPKEY_WORDS / 2];
- u64 decrypt_expkey[DES_EXPKEY_WORDS / 2];
-};
-
-struct des3_ede_sparc64_ctx {
- u64 encrypt_expkey[DES3_EDE_EXPKEY_WORDS / 2];
- u64 decrypt_expkey[DES3_EDE_EXPKEY_WORDS / 2];
-};
-
-static void encrypt_to_decrypt(u64 *d, const u64 *e)
-{
- const u64 *s = e + (DES_EXPKEY_WORDS / 2) - 1;
- int i;
-
- for (i = 0; i < DES_EXPKEY_WORDS / 2; i++)
- *d++ = *s--;
-}
-
-extern void des_sparc64_key_expand(const u32 *input_key, u64 *key);
-
-static int des_set_key(struct crypto_tfm *tfm, const u8 *key,
- unsigned int keylen)
-{
- struct des_sparc64_ctx *dctx = crypto_tfm_ctx(tfm);
- int err;
-
- /* Even though we have special instructions for key expansion,
- * we call des_verify_key() so that we don't have to write our own
- * weak key detection code.
- */
- err = crypto_des_verify_key(tfm, key);
- if (err)
- return err;
-
- des_sparc64_key_expand((const u32 *) key, &dctx->encrypt_expkey[0]);
- encrypt_to_decrypt(&dctx->decrypt_expkey[0], &dctx->encrypt_expkey[0]);
-
- return 0;
-}
-
-static int des_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *key,
- unsigned int keylen)
-{
- return des_set_key(crypto_skcipher_tfm(tfm), key, keylen);
-}
-
-extern void des_sparc64_crypt(const u64 *key, const u64 *input,
- u64 *output);
-
-static void sparc_des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
-{
- struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
- const u64 *K = ctx->encrypt_expkey;
-
- des_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
-}
-
-static void sparc_des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
-{
- struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
- const u64 *K = ctx->decrypt_expkey;
-
- des_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
-}
-
-extern void des_sparc64_load_keys(const u64 *key);
-
-extern void des_sparc64_ecb_crypt(const u64 *input, u64 *output,
- unsigned int len);
-
-static int __ecb_crypt(struct skcipher_request *req, bool encrypt)
-{
- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
- const struct des_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
- struct skcipher_walk walk;
- unsigned int nbytes;
- int err;
-
- err = skcipher_walk_virt(&walk, req, true);
- if (err)
- return err;
-
- if (encrypt)
- des_sparc64_load_keys(&ctx->encrypt_expkey[0]);
- else
- des_sparc64_load_keys(&ctx->decrypt_expkey[0]);
- while ((nbytes = walk.nbytes) != 0) {
- des_sparc64_ecb_crypt(walk.src.virt.addr, walk.dst.virt.addr,
- round_down(nbytes, DES_BLOCK_SIZE));
- err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
- }
- fprs_write(0);
- return err;
-}
-
-static int ecb_encrypt(struct skcipher_request *req)
-{
- return __ecb_crypt(req, true);
-}
-
-static int ecb_decrypt(struct skcipher_request *req)
-{
- return __ecb_crypt(req, false);
-}
-
-extern void des_sparc64_cbc_encrypt(const u64 *input, u64 *output,
- unsigned int len, u64 *iv);
-
-extern void des_sparc64_cbc_decrypt(const u64 *input, u64 *output,
- unsigned int len, u64 *iv);
-
-static int __cbc_crypt(struct skcipher_request *req, bool encrypt)
-{
- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
- const struct des_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
- struct skcipher_walk walk;
- unsigned int nbytes;
- int err;
-
- err = skcipher_walk_virt(&walk, req, true);
- if (err)
- return err;
-
- if (encrypt)
- des_sparc64_load_keys(&ctx->encrypt_expkey[0]);
- else
- des_sparc64_load_keys(&ctx->decrypt_expkey[0]);
- while ((nbytes = walk.nbytes) != 0) {
- if (encrypt)
- des_sparc64_cbc_encrypt(walk.src.virt.addr,
- walk.dst.virt.addr,
- round_down(nbytes,
- DES_BLOCK_SIZE),
- walk.iv);
- else
- des_sparc64_cbc_decrypt(walk.src.virt.addr,
- walk.dst.virt.addr,
- round_down(nbytes,
- DES_BLOCK_SIZE),
- walk.iv);
- err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
- }
- fprs_write(0);
- return err;
-}
-
-static int cbc_encrypt(struct skcipher_request *req)
-{
- return __cbc_crypt(req, true);
-}
-
-static int cbc_decrypt(struct skcipher_request *req)
-{
- return __cbc_crypt(req, false);
-}
-
-static int des3_ede_set_key(struct crypto_tfm *tfm, const u8 *key,
- unsigned int keylen)
-{
- struct des3_ede_sparc64_ctx *dctx = crypto_tfm_ctx(tfm);
- u64 k1[DES_EXPKEY_WORDS / 2];
- u64 k2[DES_EXPKEY_WORDS / 2];
- u64 k3[DES_EXPKEY_WORDS / 2];
- int err;
-
- err = crypto_des3_ede_verify_key(tfm, key);
- if (err)
- return err;
-
- des_sparc64_key_expand((const u32 *)key, k1);
- key += DES_KEY_SIZE;
- des_sparc64_key_expand((const u32 *)key, k2);
- key += DES_KEY_SIZE;
- des_sparc64_key_expand((const u32 *)key, k3);
-
- memcpy(&dctx->encrypt_expkey[0], &k1[0], sizeof(k1));
- encrypt_to_decrypt(&dctx->encrypt_expkey[DES_EXPKEY_WORDS / 2], &k2[0]);
- memcpy(&dctx->encrypt_expkey[(DES_EXPKEY_WORDS / 2) * 2],
- &k3[0], sizeof(k3));
-
- encrypt_to_decrypt(&dctx->decrypt_expkey[0], &k3[0]);
- memcpy(&dctx->decrypt_expkey[DES_EXPKEY_WORDS / 2],
- &k2[0], sizeof(k2));
- encrypt_to_decrypt(&dctx->decrypt_expkey[(DES_EXPKEY_WORDS / 2) * 2],
- &k1[0]);
-
- return 0;
-}
-
-static int des3_ede_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *key,
- unsigned int keylen)
-{
- return des3_ede_set_key(crypto_skcipher_tfm(tfm), key, keylen);
-}
-
-extern void des3_ede_sparc64_crypt(const u64 *key, const u64 *input,
- u64 *output);
-
-static void sparc_des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
-{
- struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
- const u64 *K = ctx->encrypt_expkey;
-
- des3_ede_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
-}
-
-static void sparc_des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
-{
- struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
- const u64 *K = ctx->decrypt_expkey;
-
- des3_ede_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
-}
-
-extern void des3_ede_sparc64_load_keys(const u64 *key);
-
-extern void des3_ede_sparc64_ecb_crypt(const u64 *expkey, const u64 *input,
- u64 *output, unsigned int len);
-
-static int __ecb3_crypt(struct skcipher_request *req, bool encrypt)
-{
- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
- const struct des3_ede_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
- struct skcipher_walk walk;
- const u64 *K;
- unsigned int nbytes;
- int err;
-
- err = skcipher_walk_virt(&walk, req, true);
- if (err)
- return err;
-
- if (encrypt)
- K = &ctx->encrypt_expkey[0];
- else
- K = &ctx->decrypt_expkey[0];
- des3_ede_sparc64_load_keys(K);
- while ((nbytes = walk.nbytes) != 0) {
- des3_ede_sparc64_ecb_crypt(K, walk.src.virt.addr,
- walk.dst.virt.addr,
- round_down(nbytes, DES_BLOCK_SIZE));
- err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
- }
- fprs_write(0);
- return err;
-}
-
-static int ecb3_encrypt(struct skcipher_request *req)
-{
- return __ecb3_crypt(req, true);
-}
-
-static int ecb3_decrypt(struct skcipher_request *req)
-{
- return __ecb3_crypt(req, false);
-}
-
-extern void des3_ede_sparc64_cbc_encrypt(const u64 *expkey, const u64 *input,
- u64 *output, unsigned int len,
- u64 *iv);
-
-extern void des3_ede_sparc64_cbc_decrypt(const u64 *expkey, const u64 *input,
- u64 *output, unsigned int len,
- u64 *iv);
-
-static int __cbc3_crypt(struct skcipher_request *req, bool encrypt)
-{
- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
- const struct des3_ede_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
- struct skcipher_walk walk;
- const u64 *K;
- unsigned int nbytes;
- int err;
-
- err = skcipher_walk_virt(&walk, req, true);
- if (err)
- return err;
-
- if (encrypt)
- K = &ctx->encrypt_expkey[0];
- else
- K = &ctx->decrypt_expkey[0];
- des3_ede_sparc64_load_keys(K);
- while ((nbytes = walk.nbytes) != 0) {
- if (encrypt)
- des3_ede_sparc64_cbc_encrypt(K, walk.src.virt.addr,
- walk.dst.virt.addr,
- round_down(nbytes,
- DES_BLOCK_SIZE),
- walk.iv);
- else
- des3_ede_sparc64_cbc_decrypt(K, walk.src.virt.addr,
- walk.dst.virt.addr,
- round_down(nbytes,
- DES_BLOCK_SIZE),
- walk.iv);
- err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
- }
- fprs_write(0);
- return err;
-}
-
-static int cbc3_encrypt(struct skcipher_request *req)
-{
- return __cbc3_crypt(req, true);
-}
-
-static int cbc3_decrypt(struct skcipher_request *req)
-{
- return __cbc3_crypt(req, false);
-}
-
-static struct crypto_alg cipher_algs[] = {
- {
- .cra_name = "des",
- .cra_driver_name = "des-sparc64",
- .cra_priority = SPARC_CR_OPCODE_PRIORITY,
- .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
- .cra_blocksize = DES_BLOCK_SIZE,
- .cra_ctxsize = sizeof(struct des_sparc64_ctx),
- .cra_alignmask = 7,
- .cra_module = THIS_MODULE,
- .cra_u = {
- .cipher = {
- .cia_min_keysize = DES_KEY_SIZE,
- .cia_max_keysize = DES_KEY_SIZE,
- .cia_setkey = des_set_key,
- .cia_encrypt = sparc_des_encrypt,
- .cia_decrypt = sparc_des_decrypt
- }
- }
- }, {
- .cra_name = "des3_ede",
- .cra_driver_name = "des3_ede-sparc64",
- .cra_priority = SPARC_CR_OPCODE_PRIORITY,
- .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
- .cra_blocksize = DES3_EDE_BLOCK_SIZE,
- .cra_ctxsize = sizeof(struct des3_ede_sparc64_ctx),
- .cra_alignmask = 7,
- .cra_module = THIS_MODULE,
- .cra_u = {
- .cipher = {
- .cia_min_keysize = DES3_EDE_KEY_SIZE,
- .cia_max_keysize = DES3_EDE_KEY_SIZE,
- .cia_setkey = des3_ede_set_key,
- .cia_encrypt = sparc_des3_ede_encrypt,
- .cia_decrypt = sparc_des3_ede_decrypt
- }
- }
- }
-};
-
-static struct skcipher_alg skcipher_algs[] = {
- {
- .base.cra_name = "ecb(des)",
- .base.cra_driver_name = "ecb-des-sparc64",
- .base.cra_priority = SPARC_CR_OPCODE_PRIORITY,
- .base.cra_blocksize = DES_BLOCK_SIZE,
- .base.cra_ctxsize = sizeof(struct des_sparc64_ctx),
- .base.cra_alignmask = 7,
- .base.cra_module = THIS_MODULE,
- .min_keysize = DES_KEY_SIZE,
- .max_keysize = DES_KEY_SIZE,
- .setkey = des_set_key_skcipher,
- .encrypt = ecb_encrypt,
- .decrypt = ecb_decrypt,
- }, {
- .base.cra_name = "cbc(des)",
- .base.cra_driver_name = "cbc-des-sparc64",
- .base.cra_priority = SPARC_CR_OPCODE_PRIORITY,
- .base.cra_blocksize = DES_BLOCK_SIZE,
- .base.cra_ctxsize = sizeof(struct des_sparc64_ctx),
- .base.cra_alignmask = 7,
- .base.cra_module = THIS_MODULE,
- .min_keysize = DES_KEY_SIZE,
- .max_keysize = DES_KEY_SIZE,
- .ivsize = DES_BLOCK_SIZE,
- .setkey = des_set_key_skcipher,
- .encrypt = cbc_encrypt,
- .decrypt = cbc_decrypt,
- }, {
- .base.cra_name = "ecb(des3_ede)",
- .base.cra_driver_name = "ecb-des3_ede-sparc64",
- .base.cra_priority = SPARC_CR_OPCODE_PRIORITY,
- .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
- .base.cra_ctxsize = sizeof(struct des3_ede_sparc64_ctx),
- .base.cra_alignmask = 7,
- .base.cra_module = THIS_MODULE,
- .min_keysize = DES3_EDE_KEY_SIZE,
- .max_keysize = DES3_EDE_KEY_SIZE,
- .setkey = des3_ede_set_key_skcipher,
- .encrypt = ecb3_encrypt,
- .decrypt = ecb3_decrypt,
- }, {
- .base.cra_name = "cbc(des3_ede)",
- .base.cra_driver_name = "cbc-des3_ede-sparc64",
- .base.cra_priority = SPARC_CR_OPCODE_PRIORITY,
- .base.cra_blocksize = DES3_EDE_BLOCK_SIZE,
- .base.cra_ctxsize = sizeof(struct des3_ede_sparc64_ctx),
- .base.cra_alignmask = 7,
- .base.cra_module = THIS_MODULE,
- .min_keysize = DES3_EDE_KEY_SIZE,
- .max_keysize = DES3_EDE_KEY_SIZE,
- .ivsize = DES3_EDE_BLOCK_SIZE,
- .setkey = des3_ede_set_key_skcipher,
- .encrypt = cbc3_encrypt,
- .decrypt = cbc3_decrypt,
- }
-};
-
-static bool __init sparc64_has_des_opcode(void)
-{
- unsigned long cfr;
-
- if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO))
- return false;
-
- __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr));
- if (!(cfr & CFR_DES))
- return false;
-
- return true;
-}
-
-static int __init des_sparc64_mod_init(void)
-{
- int err;
-
- if (!sparc64_has_des_opcode()) {
- pr_info("sparc64 des opcodes not available.\n");
- return -ENODEV;
- }
- pr_info("Using sparc64 des opcodes optimized DES implementation\n");
- err = crypto_register_algs(cipher_algs, ARRAY_SIZE(cipher_algs));
- if (err)
- return err;
- err = crypto_register_skciphers(skcipher_algs,
- ARRAY_SIZE(skcipher_algs));
- if (err)
- crypto_unregister_algs(cipher_algs, ARRAY_SIZE(cipher_algs));
- return err;
-}
-
-static void __exit des_sparc64_mod_fini(void)
-{
- crypto_unregister_algs(cipher_algs, ARRAY_SIZE(cipher_algs));
- crypto_unregister_skciphers(skcipher_algs, ARRAY_SIZE(skcipher_algs));
-}
-
-module_init(des_sparc64_mod_init);
-module_exit(des_sparc64_mod_fini);
-
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms, sparc64 des opcode accelerated");
-
-MODULE_ALIAS_CRYPTO("des");
-MODULE_ALIAS_CRYPTO("des3_ede");
-
-#include "crop_devid.c"
--
2.53.0
next prev parent reply other threads:[~2026-03-26 20:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 20:12 [PATCH 0/3] crypto: Remove arch-optimized des and des3_ede code Eric Biggers
2026-03-26 20:12 ` [PATCH 1/3] crypto: s390 - Remove " Eric Biggers
2026-03-27 8:52 ` Holger Dengler
2026-03-27 17:32 ` Eric Biggers
2026-03-26 20:12 ` Eric Biggers [this message]
2026-03-26 20:12 ` [PATCH 3/3] crypto: x86 " Eric Biggers
2026-03-26 20:20 ` [PATCH 0/3] crypto: Remove arch-optimized " John Paul Adrian Glaubitz
2026-03-26 20:27 ` Eric Biggers
2026-03-26 21:07 ` Eric Biggers
2026-03-27 9:59 ` Simon Richter
2026-03-27 17:24 ` 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=20260326201246.57544-3-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=dengler@linux.ibm.com \
--cc=freude@linux.ibm.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=sparclinux@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