Skip to contentSkip to conversation

Migrate SPARC64 accelerated AES modes into library

PATCH Applied Eric Biggers 2 participants 7 messages Nov 18 – Nov 21

Subsystems (3)
lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

cover Migrate SPARC64 accelerated AES modes into library

This series is targeting libcrypto-next. It can also be retrieved from:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git aes-sparc-v1

This series migrates the SPARC64 crypto opcodes accelerated implementations of AES-ECB, AES-CBC, and AES-CTR into lib/crypto/.

This makes the AES-ECB, AES-CBC, and AES-CTR library APIs be properly accelerated on SPARC64, while still being available in the crypto_skcipher API via crypto/aes.c. As usual, the longstanding issue of acceleration being disabled by default is also fixed.

After this, the only thing left in arch/sparc/crypto/ is Camellia.

Tested in QEMU (specifically commit 97c88c61d45d, which has Stian Halseth's recent changes that added support for the AES, CRC32C, SHA1, SHA256, and SHA512 opcodes) with the new ECB, CBC, and CTR KUnit tests
(https://lore.kernel.org/r/[email protected]/)
and CONFIG_CRYPTO_SELFTESTS_FULL=y, using Stian Halseth's patch that makes the SPARC kernel detect QEMU's support for the crypto opcodes
(https://lore.kernel.org/r/[email protected]/).

Eric Biggers (4):
lib/crypto: sparc/aes: Add and use round key load helper lib/crypto: sparc/aes-ctr: Migrate optimized code into library lib/crypto: sparc/aes-ecb: Migrate optimized code into library lib/crypto: sparc/aes-cbc: Migrate optimized code into library

 arch/sparc/crypto/Kconfig    |  10 -
 arch/sparc/crypto/Makefile   |   2 -
 arch/sparc/crypto/aes_glue.c | 344 ----------------------------------
 crypto/aes.c                 |  13 +-
 include/crypto/aes.h         |  39 ----
 lib/crypto/sparc/aes.h       | 348 +++++++++++++++++++++++++++++++----
 lib/crypto/sparc/aes_asm.S   |  24 ++-
 7 files changed, 334 insertions(+), 446 deletions(-)
 delete mode 100644 arch/sparc/crypto/aes_glue.c

base-commit: 30e5781e2cd0aeffd80d524bbdac176579a3235f

Signature · 1 line
2.56.1
author maintainer
#1 lore raw

PATCH 1/4 lib/crypto: sparc/aes: Add and use round key load helper

In preparation for migrating more SPARC-optimized AES modes into libaes, add a helper function aes_sparc64_load_round_keys() that loads either the encryption or decryption round keys.

Make aes_xts_crypt_sparc64() call it. (The AES-192 support is not used yet, but the other modes will use it.)

---
 lib/crypto/sparc/aes.h | 44 +++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
lib/crypto/sparc/aes.h +31 -13
index e1a060cf49539..8b8ab0820bb3e 100644
@@ -133,6 +133,29 @@ static void aes_decrypt_arch(const struct aes_key *key,
 	}
 }
 
+static __always_inline void aes_sparc64_load_round_keys(aes_encrypt_arg key_arg,
+							bool enc)
+{
+	const struct aes_enckey *key = key_arg.enc_key;
+	const u64 *rk = key->k.sparc_rndkeys;
+
+	if (enc) {
+		if (key->len == AES_KEYSIZE_128)
+			aes_sparc64_load_encrypt_keys_128(rk);
+		else if (key->len == AES_KEYSIZE_192)
+			aes_sparc64_load_encrypt_keys_192(rk);
+		else
+			aes_sparc64_load_encrypt_keys_256(rk);
+	} else {
+		if (key->len == AES_KEYSIZE_128)
+			aes_sparc64_load_decrypt_keys_128(rk);
+		else if (key->len == AES_KEYSIZE_192)
+			aes_sparc64_load_decrypt_keys_192(rk);
+		else
+			aes_sparc64_load_decrypt_keys_256(rk);
+	}
+}
+
 #if IS_ENABLED(CONFIG_CRYPTO_LIB_AES_XTS)
 void aes_sparc64_xts_encrypt_128(const u64 *key, const u64 *input, u64 *output,
 				 size_t len, u64 tweak[2]);
@@ -167,22 +190,17 @@ aes_xts_crypt_sparc64(u8 *dst, const u8 *src, size_t len,
 	else
 		aes_encrypt_arch(&key->tweak_key, (u8 *)t, tweak);
 
-	if (k->len == AES_KEYSIZE_128) {
-		if (enc) {
-			aes_sparc64_load_encrypt_keys_128(rk);
+	aes_sparc64_load_round_keys(k, enc);
+	if (enc) {
+		if (k->len == AES_KEYSIZE_128)
 			aes_sparc64_xts_encrypt_128(rk, in, out, len, t);
-		} else {
-			aes_sparc64_load_decrypt_keys_128(rk);
-			aes_sparc64_xts_decrypt_128(rk_end, in, out, len, t);
-		}
-	} else {
-		if (enc) {
-			aes_sparc64_load_encrypt_keys_256(rk);
+		else
 			aes_sparc64_xts_encrypt_256(rk, in, out, len, t);
-		} else {
-			aes_sparc64_load_decrypt_keys_256(rk);
+	} else {
+		if (k->len == AES_KEYSIZE_128)
+			aes_sparc64_xts_decrypt_128(rk_end, in, out, len, t);
+		else
 			aes_sparc64_xts_decrypt_256(rk_end, in, out, len, t);
-		}
 	}
 	fprs_write(0);
 
Signature · 1 line
2.56.1
author maintainer
#2 lore raw

PATCH 2/4 lib/crypto: sparc/aes-ctr: Migrate optimized code into library

In reply to Eric Biggers

Instead of exposing the sparc64-optimized AES-CTR code via a sparc64-specific crypto_skcipher algorithm, implement the AES-CTR library function. This is simpler, makes the AES-CTR library function sparc64-optimized, and fixes the longstanding issue where the sparc64-optimized AES-CTR code was disabled by default. AES-CTR support remains available through crypto_skcipher via crypto/aes.c.

The library functions take size_t lengths, so update the CTR assembly functions to match.

Handle the CTR assembly code's data alignment requirement by explicitly using an on-stack bounce buffer when the data is misaligned. (Note that bounce buffering was used in the old code too; it was just hidden in the skcipher_walk_* functions via the configured cra_alignmask=7.) Also use a bounce buffer to handle any partial block at the end of the message.

Now that ctr-aes-sparc64 is removed, also increase the priority of ctr-aes-lib on SPARC, and re-enable ccm-aes-lib, gcm-aes-lib, and rfc4106-gcm-aes-lib.

Tested in QEMU (commit 97c88c61d45d) with aes_ctr_kunit
(https://lore.kernel.org/r/[email protected]/)
and CONFIG_CRYPTO_SELFTESTS_FULL=y, using the patch that makes the SPARC kernel detect QEMU's support for the SPARC crypto opcodes
(https://lore.kernel.org/r/[email protected]/).

---
 arch/sparc/crypto/Kconfig    |  4 +-
 arch/sparc/crypto/aes_glue.c | 63 ------------------------
 crypto/aes.c                 |  7 ++-
 include/crypto/aes.h         |  6 ---
 lib/crypto/sparc/aes.h       | 92 ++++++++++++++++++++++++++++++++++--
 lib/crypto/sparc/aes_asm.S   |  8 ++--
 6 files changed, 99 insertions(+), 81 deletions(-)
arch/sparc/crypto/Kconfig +2 -2
index 8db3f6eea5dc3..b7edee0da73e6 100644
@@ -3,12 +3,12 @@
 menu "Accelerated Cryptographic Algorithms for CPU (sparc64)"
 
 config CRYPTO_AES_SPARC64
-	tristate "Ciphers: AES, modes: ECB, CBC, CTR"
+	tristate "Ciphers: AES, modes: ECB, CBC"
 	depends on SPARC64
 	select CRYPTO_LIB_AES
 	select CRYPTO_SKCIPHER
 	help
-	  Length-preseving ciphers: AES with ECB, CBC, and CTR modes
+	  Length-preserving ciphers: AES with ECB and CBC modes
 
 	  Architecture: sparc64 using crypto instructions
 
arch/sparc/crypto/aes_glue.c +0 -63

99 lines not on this page · raw message

crypto/aes.c +3 -4
index 9508a975d8eaf..96639c96b0497 100644
@@ -672,6 +672,7 @@ static struct skcipher_alg skcipher_algs[] = {
 		.base.cra_name = "ctr(aes)",
 		.base.cra_driver_name = "ctr-aes-lib",
 		.base.cra_priority = (IS_ENABLED(CONFIG_RISCV) ||
+				      IS_ENABLED(CONFIG_SPARC) ||
 				      IS_ENABLED(CONFIG_X86)) ? 500 : 110,
 		.base.cra_blocksize = 1,
 		.base.cra_ctxsize = sizeof(struct aes_enckey),
@@ -1008,8 +1009,7 @@ static struct aead_alg aead_algs[] = {
 	!(IS_ENABLED(CONFIG_ARM) || \
 	  IS_ENABLED(CONFIG_ARM64) || \
 	  IS_ENABLED(CONFIG_PPC) || \
-	  IS_ENABLED(CONFIG_S390) || \
-	  IS_ENABLED(CONFIG_SPARC))
+	  IS_ENABLED(CONFIG_S390))
 	{
 		.base.cra_name = "gcm(aes)",
 		.base.cra_driver_name = "gcm-aes-lib",
@@ -1051,8 +1051,7 @@ static struct aead_alg aead_algs[] = {
 	!(IS_ENABLED(CONFIG_ARM) || \
 	  IS_ENABLED(CONFIG_ARM64) || \
 	  IS_ENABLED(CONFIG_PPC) || \
-	  IS_ENABLED(CONFIG_S390) || \
-	  IS_ENABLED(CONFIG_SPARC))
+	  IS_ENABLED(CONFIG_S390))
 	{
 		.base.cra_name = "ccm(aes)",
 		.base.cra_driver_name = "ccm-aes-lib",
include/crypto/aes.h +0 -6
index fa5c3d363ac9b..6dd6d394235cc 100644
@@ -332,12 +332,6 @@ void aes_sparc64_cbc_decrypt_192(const u64 *key, const u64 *input, u64 *output,
 				 unsigned int len, u64 *iv);
 void aes_sparc64_cbc_decrypt_256(const u64 *key, const u64 *input, u64 *output,
 				 unsigned int len, u64 *iv);
-void aes_sparc64_ctr_crypt_128(const u64 *key, const u64 *input, u64 *output,
-			       unsigned int len, u64 *iv);
-void aes_sparc64_ctr_crypt_192(const u64 *key, const u64 *input, u64 *output,
-			       unsigned int len, u64 *iv);
-void aes_sparc64_ctr_crypt_256(const u64 *key, const u64 *input, u64 *output,
-			       unsigned int len, u64 *iv);
 #endif
 
 /**
lib/crypto/sparc/aes.h +89 -3

104 lines not on this page · raw message

lib/crypto/sparc/aes_asm.S +5 -3
index fd90b129972fb..c95a86462b776 100644
@@ -1356,6 +1356,7 @@ ENTRY(aes_sparc64_cbc_decrypt_256)
 	 nop
 ENDPROC(aes_sparc64_cbc_decrypt_256)
 
+#if IS_ENABLED(CONFIG_CRYPTO_LIB_AES_CTR)
 	.align		32
 ENTRY(aes_sparc64_ctr_crypt_128)
 	/* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
@@ -1363,7 +1364,7 @@ ENTRY(aes_sparc64_ctr_crypt_128)
 	ldx		[%o4 + 0x08], %g7
 	subcc		%o3, 0x10, %o3
 	ldx		[%o0 + 0x00], %g1
-	be		10f
+	be,pn		%xcc, 10f
 	 ldx		[%o0 + 0x08], %g2
 1:	xor		%g1, %g3, %o5
 	MOVXTOD_O5_F0
@@ -1424,7 +1425,7 @@ ENTRY(aes_sparc64_ctr_crypt_192)
 	ldx		[%o4 + 0x08], %g7
 	subcc		%o3, 0x10, %o3
 	ldx		[%o0 + 0x00], %g1
-	be		10f
+	be,pn		%xcc, 10f
 	 ldx		[%o0 + 0x08], %g2
 1:	xor		%g1, %g3, %o5
 	MOVXTOD_O5_F0
@@ -1485,7 +1486,7 @@ ENTRY(aes_sparc64_ctr_crypt_256)
 	ldx		[%o4 + 0x08], %g7
 	subcc		%o3, 0x10, %o3
 	ldx		[%o0 + 0x00], %g1
-	be		10f
+	be,pn		%xcc, 10f
 	 ldx		[%o0 + 0x08], %g2
 1:	xor		%g1, %g3, %o5
 	MOVXTOD_O5_F0
@@ -1542,6 +1543,7 @@ ENTRY(aes_sparc64_ctr_crypt_256)
 	retl
 	 stx		%g7, [%o4 + 0x08]
 ENDPROC(aes_sparc64_ctr_crypt_256)
+#endif /* CONFIG_CRYPTO_LIB_AES_CTR */
 
 #if IS_ENABLED(CONFIG_CRYPTO_LIB_AES_XTS)
 	/* XTS.  The tweak is kept in %l0/%l1 as little-endian words, so that
Signature · 1 line
2.56.1
author maintainer
#3 lore raw

PATCH 3/4 lib/crypto: sparc/aes-ecb: Migrate optimized code into library

In reply to Eric Biggers

Instead of exposing the sparc64-optimized AES-ECB code via a sparc64-specific crypto_skcipher algorithm, implement the AES-ECB library functions. This is simpler, makes the AES-ECB library functions sparc64-optimized, and fixes the longstanding issue where the sparc64-optimized AES-ECB code was disabled by default. AES-ECB support remains available through crypto_skcipher via crypto/aes.c.

The library functions take size_t lengths, so update the ECB assembly functions to match.

Handle the ECB assembly code's data alignment requirement by explicitly using an on-stack bounce buffer when the data is misaligned. (Note that bounce buffering was used in the old code too; it was just hidden in the skcipher_walk_* functions via the configured cra_alignmask=7.)

Now that ecb-aes-sparc64 is removed, also increase the priority of ecb-aes-lib on SPARC.

Tested in QEMU (commit 97c88c61d45d) with aes_ecb_kunit
(https://lore.kernel.org/r/[email protected]/)
and CONFIG_CRYPTO_SELFTESTS_FULL=y, using the patch that makes the SPARC kernel detect QEMU's support for the SPARC crypto opcodes
(https://lore.kernel.org/r/[email protected]/).

---
 arch/sparc/crypto/Kconfig    |  4 +-
 arch/sparc/crypto/aes_glue.c | 72 ---------------------------
 crypto/aes.c                 |  1 +
 include/crypto/aes.h         | 12 -----
 lib/crypto/sparc/aes.h       | 94 +++++++++++++++++++++++++++++++++---
 lib/crypto/sparc/aes_asm.S   | 14 +++---
 6 files changed, 99 insertions(+), 98 deletions(-)
arch/sparc/crypto/Kconfig +2 -2
index b7edee0da73e6..783b057aeebfb 100644
@@ -3,12 +3,12 @@
 menu "Accelerated Cryptographic Algorithms for CPU (sparc64)"
 
 config CRYPTO_AES_SPARC64
-	tristate "Ciphers: AES, modes: ECB, CBC"
+	tristate "Ciphers: AES, modes: CBC"
 	depends on SPARC64
 	select CRYPTO_LIB_AES
 	select CRYPTO_SKCIPHER
 	help
-	  Length-preserving ciphers: AES with ECB and CBC modes
+	  Length-preserving ciphers: AES with CBC mode
 
 	  Architecture: sparc64 using crypto instructions
 
arch/sparc/crypto/aes_glue.c +0 -72

108 lines not on this page · raw message

crypto/aes.c +1 -0
index 96639c96b0497..2e4ea9d7a74d8 100644
@@ -611,6 +611,7 @@ static struct skcipher_alg skcipher_algs[] = {
 		.base.cra_name = "ecb(aes)",
 		.base.cra_driver_name = "ecb-aes-lib",
 		.base.cra_priority = (IS_ENABLED(CONFIG_RISCV) ||
+				      IS_ENABLED(CONFIG_SPARC) ||
 				      IS_ENABLED(CONFIG_X86)) ? 500 : 110,
 		.base.cra_blocksize = AES_BLOCK_SIZE,
 		.base.cra_ctxsize = sizeof(struct aes_key),
include/crypto/aes.h +0 -12
index 6dd6d394235cc..e77e8660f347e 100644
@@ -308,18 +308,6 @@ void aes_sparc64_load_encrypt_keys_256(const u64 *key);
 void aes_sparc64_load_decrypt_keys_128(const u64 *key);
 void aes_sparc64_load_decrypt_keys_192(const u64 *key);
 void aes_sparc64_load_decrypt_keys_256(const u64 *key);
-void aes_sparc64_ecb_encrypt_128(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len);
-void aes_sparc64_ecb_encrypt_192(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len);
-void aes_sparc64_ecb_encrypt_256(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len);
-void aes_sparc64_ecb_decrypt_128(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len);
-void aes_sparc64_ecb_decrypt_192(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len);
-void aes_sparc64_ecb_decrypt_256(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len);
 void aes_sparc64_cbc_encrypt_128(const u64 *key, const u64 *input, u64 *output,
 				 unsigned int len, u64 *iv);
 void aes_sparc64_cbc_encrypt_192(const u64 *key, const u64 *input, u64 *output,
lib/crypto/sparc/aes.h +88 -6

106 lines not on this page · raw message

lib/crypto/sparc/aes_asm.S +8 -6
index c95a86462b776..fc63f3233ca23 100644
@@ -909,12 +909,13 @@ ENTRY(aes_sparc64_load_decrypt_keys_256)
 	 ldd		[%o0 + 0x00], %f62
 ENDPROC(aes_sparc64_load_decrypt_keys_256)
 
+#if IS_ENABLED(CONFIG_CRYPTO_LIB_AES_ECB)
 	.align		32
 ENTRY(aes_sparc64_ecb_encrypt_128)
 	/* %o0=key, %o1=input, %o2=output, %o3=len */
 	ldx		[%o0 + 0x00], %g1
 	subcc		%o3, 0x10, %o3
-	be		10f
+	be,pn		%xcc, 10f
 	 ldx		[%o0 + 0x08], %g2
 1:	ldx		[%o1 + 0x00], %g3
 	ldx		[%o1 + 0x08], %g7
@@ -957,7 +958,7 @@ ENTRY(aes_sparc64_ecb_encrypt_192)
 	/* %o0=key, %o1=input, %o2=output, %o3=len */
 	ldx		[%o0 + 0x00], %g1
 	subcc		%o3, 0x10, %o3
-	be		10f
+	be,pn		%xcc, 10f
 	 ldx		[%o0 + 0x08], %g2
 1:	ldx		[%o1 + 0x00], %g3
 	ldx		[%o1 + 0x08], %g7
@@ -1000,7 +1001,7 @@ ENTRY(aes_sparc64_ecb_encrypt_256)
 	/* %o0=key, %o1=input, %o2=output, %o3=len */
 	ldx		[%o0 + 0x00], %g1
 	subcc		%o3, 0x10, %o3
-	be		10f
+	be,pn		%xcc, 10f
 	 ldx		[%o0 + 0x08], %g2
 1:	ldx		[%o1 + 0x00], %g3
 	ldx		[%o1 + 0x08], %g7
@@ -1047,7 +1048,7 @@ ENTRY(aes_sparc64_ecb_decrypt_128)
 	/* %o0=&key[key_len], %o1=input, %o2=output, %o3=len */
 	ldx		[%o0 - 0x10], %g1
 	subcc		%o3, 0x10, %o3
-	be		10f
+	be,pn		%xcc, 10f
 	 ldx		[%o0 - 0x08], %g2
 1:	ldx		[%o1 + 0x00], %g3
 	ldx		[%o1 + 0x08], %g7
@@ -1090,7 +1091,7 @@ ENTRY(aes_sparc64_ecb_decrypt_192)
 	/* %o0=&key[key_len], %o1=input, %o2=output, %o3=len */
 	ldx		[%o0 - 0x10], %g1
 	subcc		%o3, 0x10, %o3
-	be		10f
+	be,pn		%xcc, 10f
 	 ldx		[%o0 - 0x08], %g2
 1:	ldx		[%o1 + 0x00], %g3
 	ldx		[%o1 + 0x08], %g7
@@ -1134,7 +1135,7 @@ ENTRY(aes_sparc64_ecb_decrypt_256)
 	ldx		[%o0 - 0x10], %g1
 	subcc		%o3, 0x10, %o3
 	ldx		[%o0 - 0x08], %g2
-	be		10f
+	be,pn		%xcc, 10f
 	 sub		%o0, 0xf0, %o0
 1:	ldx		[%o1 + 0x00], %g3
 	ldx		[%o1 + 0x08], %g7
@@ -1175,6 +1176,7 @@ ENTRY(aes_sparc64_ecb_decrypt_256)
 11:	retl
 	 nop
 ENDPROC(aes_sparc64_ecb_decrypt_256)
+#endif /* CONFIG_CRYPTO_LIB_AES_ECB */
 
 	.align		32
 ENTRY(aes_sparc64_cbc_encrypt_128)
Signature · 1 line
2.56.1
author maintainer
#4 lore raw

PATCH 4/4 lib/crypto: sparc/aes-cbc: Migrate optimized code into library

In reply to Eric Biggers

Instead of exposing the sparc64-optimized AES-CBC code via a sparc64-specific crypto_skcipher algorithm, implement the AES-CBC library functions. This is simpler, makes the AES-CBC and AES-CBC-CTS library functions sparc64-optimized, and fixes the longstanding issue where the sparc64-optimized AES-CBC code was disabled by default. AES-CBC and AES-CBC-CTS support remains available through crypto_skcipher via crypto/aes.c.

The library functions take size_t lengths, so update the prototypes of the CBC assembly functions to match. The assembly code actually already treated the length argument as 64-bit.

Handle the CBC assembly code's data alignment requirement by explicitly using an on-stack bounce buffer when the data is misaligned. (Note that bounce buffering was used in the old code too; it was just hidden in the skcipher_walk_* functions via the configured cra_alignmask=7.)

Now that cbc-aes-sparc64 is removed, also increase the priority of cbc-aes-lib on SPARC, and re-enable cts-cbc-aes-lib.

Tested in QEMU (commit 97c88c61d45d) with aes_cbc_kunit
(https://lore.kernel.org/r/[email protected]/)
and CONFIG_CRYPTO_SELFTESTS_FULL=y, using the patch that makes the SPARC kernel detect QEMU's support for the SPARC crypto opcodes
(https://lore.kernel.org/r/[email protected]/).

---
 arch/sparc/crypto/Kconfig    |  10 --
 arch/sparc/crypto/Makefile   |   2 -
 arch/sparc/crypto/aes_glue.c | 209 -----------------------------------
 crypto/aes.c                 |   5 +-
 include/crypto/aes.h         |  21 ----
 lib/crypto/sparc/aes.h       | 118 +++++++++++++++++---
 lib/crypto/sparc/aes_asm.S   |   2 +
 7 files changed, 109 insertions(+), 258 deletions(-)
 delete mode 100644 arch/sparc/crypto/aes_glue.c
arch/sparc/crypto/Kconfig +0 -10
index 783b057aeebfb..5cff41005241c 100644
@@ -2,16 +2,6 @@
 
 menu "Accelerated Cryptographic Algorithms for CPU (sparc64)"
 
-config CRYPTO_AES_SPARC64
-	tristate "Ciphers: AES, modes: CBC"
-	depends on SPARC64
-	select CRYPTO_LIB_AES
-	select CRYPTO_SKCIPHER
-	help
-	  Length-preserving ciphers: AES with CBC mode
-
-	  Architecture: sparc64 using crypto instructions
-
 config CRYPTO_CAMELLIA_SPARC64
 	tristate "Ciphers: Camellia, modes: ECB, CBC"
 	depends on SPARC64
arch/sparc/crypto/Makefile +0 -2
index ab4a7765babf5..b95c66c2f81cc 100644
@@ -3,8 +3,6 @@
 # Arch-specific CryptoAPI modules.
 #
 
-obj-$(CONFIG_CRYPTO_AES_SPARC64) += aes-sparc64.o
 obj-$(CONFIG_CRYPTO_CAMELLIA_SPARC64) += camellia-sparc64.o
 
-aes-sparc64-y := aes_glue.o
 camellia-sparc64-y := camellia_asm.o camellia_glue.o
arch/sparc/crypto/aes_glue.c deleted +0 -209

209 lines not on this page · raw message

crypto/aes.c +3 -2
index 2e4ea9d7a74d8..a2db6351feefa 100644
@@ -628,6 +628,7 @@ static struct skcipher_alg skcipher_algs[] = {
 		.base.cra_name = "cbc(aes)",
 		.base.cra_driver_name = "cbc-aes-lib",
 		.base.cra_priority = (IS_ENABLED(CONFIG_RISCV) ||
+				      IS_ENABLED(CONFIG_SPARC) ||
 				      IS_ENABLED(CONFIG_X86)) ? 500 : 110,
 		.base.cra_blocksize = AES_BLOCK_SIZE,
 		.base.cra_ctxsize = sizeof(struct aes_key),
@@ -650,12 +651,12 @@ static struct skcipher_alg skcipher_algs[] = {
 	!(IS_ENABLED(CONFIG_ARM) || \
 	  IS_ENABLED(CONFIG_ARM64) || \
 	  IS_ENABLED(CONFIG_PPC) || \
-	  IS_ENABLED(CONFIG_S390) || \
-	  IS_ENABLED(CONFIG_SPARC))
+	  IS_ENABLED(CONFIG_S390))
 	{
 		.base.cra_name = "cts(cbc(aes))",
 		.base.cra_driver_name = "cts-cbc-aes-lib",
 		.base.cra_priority = (IS_ENABLED(CONFIG_RISCV) ||
+				      IS_ENABLED(CONFIG_SPARC) ||
 				      IS_ENABLED(CONFIG_X86)) ? 500 : 110,
 		.base.cra_blocksize = AES_BLOCK_SIZE,
 		.base.cra_ctxsize = sizeof(struct aes_key),
include/crypto/aes.h +0 -21
index e77e8660f347e..a62cf6ef96c99 100644
@@ -299,27 +299,6 @@ void aes_p8_xts_encrypt(const u8 *in, u8 *out, size_t len,
 void aes_p8_xts_decrypt(const u8 *in, u8 *out, size_t len,
 			const struct p8_aes_key *key1,
 			const struct p8_aes_key *key2, u8 *iv);
-#elif defined(CONFIG_SPARC64)
-void aes_sparc64_key_expand(const u32 *in_key, u64 *output_key,
-			    unsigned int key_len);
-void aes_sparc64_load_encrypt_keys_128(const u64 *key);
-void aes_sparc64_load_encrypt_keys_192(const u64 *key);
-void aes_sparc64_load_encrypt_keys_256(const u64 *key);
-void aes_sparc64_load_decrypt_keys_128(const u64 *key);
-void aes_sparc64_load_decrypt_keys_192(const u64 *key);
-void aes_sparc64_load_decrypt_keys_256(const u64 *key);
-void aes_sparc64_cbc_encrypt_128(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len, u64 *iv);
-void aes_sparc64_cbc_encrypt_192(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len, u64 *iv);
-void aes_sparc64_cbc_encrypt_256(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len, u64 *iv);
-void aes_sparc64_cbc_decrypt_128(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len, u64 *iv);
-void aes_sparc64_cbc_decrypt_192(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len, u64 *iv);
-void aes_sparc64_cbc_decrypt_256(const u64 *key, const u64 *input, u64 *output,
-				 unsigned int len, u64 *iv);
 #endif
 
 /**
lib/crypto/sparc/aes.h +104 -14

140 lines not on this page · raw message

lib/crypto/sparc/aes_asm.S +2 -0
index fc63f3233ca23..35c3c29769bad 100644
@@ -1178,6 +1178,7 @@ ENTRY(aes_sparc64_ecb_decrypt_256)
 ENDPROC(aes_sparc64_ecb_decrypt_256)
 #endif /* CONFIG_CRYPTO_LIB_AES_ECB */
 
+#if IS_ENABLED(CONFIG_CRYPTO_LIB_AES_CBC)
 	.align		32
 ENTRY(aes_sparc64_cbc_encrypt_128)
 	/* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */
@@ -1357,6 +1358,7 @@ ENTRY(aes_sparc64_cbc_decrypt_256)
 	retl
 	 nop
 ENDPROC(aes_sparc64_cbc_decrypt_256)
+#endif /* CONFIG_CRYPTO_LIB_AES_CBC */
 
 #if IS_ENABLED(CONFIG_CRYPTO_LIB_AES_CTR)
 	.align		32
Signature · 1 line
2.56.1
Tested-by on the v1 series
#5 lore raw
In reply to Eric Biggers

Hi Eric,

Quoted 4 lines · Eric Biggers

This series migrates the SPARC64 crypto opcodes accelerated implementations of AES-ECB, AES-CBC, and AES-CTR into lib/crypto/.

The self-tests (CONFIG_CRYPTO_SELFTESTS_FULL=y) and AES KUnit suites pass on SPARC T4 and M7. I also compared ecb, cbc and ctr(aes) through AF_ALG against openssl, with random keys, IVs and lengths. They all match.

Through the crypto API, the speed is the same as before. On the T4, tcrypt mode=200 gives the same throughput from 1024 bytes up, and is within a few percent below that. The library ECB, CBC and CTR are now ~10 times faster on 4096 bytes.

/Stian

author maintainer Applied
#6 lore raw
In reply to Eric Biggers
Quoted 28 lines · Eric Biggers

This series is targeting libcrypto-next. It can also be retrieved from:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git aes-sparc-v1

This series migrates the SPARC64 crypto opcodes accelerated implementations of AES-ECB, AES-CBC, and AES-CTR into lib/crypto/.

This makes the AES-ECB, AES-CBC, and AES-CTR library APIs be properly accelerated on SPARC64, while still being available in the crypto_skcipher API via crypto/aes.c. As usual, the longstanding issue of acceleration being disabled by default is also fixed.

After this, the only thing left in arch/sparc/crypto/ is Camellia.

Tested in QEMU (specifically commit 97c88c61d45d, which has Stian Halseth's recent changes that added support for the AES, CRC32C, SHA1, SHA256, and SHA512 opcodes) with the new ECB, CBC, and CTR KUnit tests
(https://lore.kernel.org/r/[email protected]/)
and CONFIG_CRYPTO_SELFTESTS_FULL=y, using Stian Halseth's patch that makes the SPARC kernel detect QEMU's support for the crypto opcodes
(https://lore.kernel.org/r/[email protected]/).

Eric Biggers (4):
lib/crypto: sparc/aes: Add and use round key load helper lib/crypto: sparc/aes-ctr: Migrate optimized code into library lib/crypto: sparc/aes-ecb: Migrate optimized code into library lib/crypto: sparc/aes-cbc: Migrate optimized code into library

Quoted 9 lines
 arch/sparc/crypto/Kconfig    |  10 -
 arch/sparc/crypto/Makefile   |   2 -
 arch/sparc/crypto/aes_glue.c | 344 ----------------------------------
 crypto/aes.c                 |  13 +-
 include/crypto/aes.h         |  39 ----
 lib/crypto/sparc/aes.h       | 348 +++++++++++++++++++++++++++++++----
 lib/crypto/sparc/aes_asm.S   |  24 ++-
 7 files changed, 334 insertions(+), 446 deletions(-)
 delete mode 100644 arch/sparc/crypto/aes_glue.c

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next

- Eric