Skip to contentSkip to conversation

Remove per-architecture poly1305 shash glue code

PATCH In review Eric Biggers 2 participants 11 messages Apr 13, 2025 – Apr 16, 2025

Subsystems (8)
Arm (32-bit) x86 PowerPC MIPS +4 more subsystems
lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

cover Remove per-architecture poly1305 shash glue code

This series removes the per-architecture poly1305 shash glue code and re-implements the poly1305 shashes on top of the Poly1305 library functions. This ends up being much simpler, and it is how it should have been done originally. This follows similar changes to crc32, crc32c, and chacha20.

This series also makes the Poly1305 library be optimized on PowerPC. Previously the PowerPC-optimized Poly1305 code only supported shash.

Eric Biggers (9):
crypto: powerpc/poly1305 - implement library instead of shash
crypto: poly1305 - centralize the shash wrappers for arch code
crypto: arm/poly1305 - remove redundant shash algorithm
crypto: arm64/poly1305 - remove redundant shash algorithm
crypto: mips/poly1305 - drop redundant dependency on CONFIG_MIPS
crypto: mips/poly1305 - remove redundant shash algorithm
crypto: x86/poly1305 - remove redundant shash algorithm
crypto: x86/poly1305 - don't select CRYPTO_LIB_POLY1305_GENERIC
crypto: poly1305 - remove rset and sset fields of poly1305_desc_ctx

 arch/arm/crypto/Kconfig                 |   6 -
 arch/arm/crypto/poly1305-glue.c         | 170 ++----------------------
 arch/arm64/crypto/Kconfig               |   6 -
 arch/arm64/crypto/poly1305-glue.c       | 143 ++------------------
 arch/mips/crypto/Kconfig                |   6 -
 arch/mips/crypto/poly1305-glue.c        | 120 +----------------
 arch/powerpc/crypto/Kconfig             |  11 +-
 arch/powerpc/crypto/poly1305-p10-glue.c | 134 ++++++-------------
 arch/x86/crypto/Kconfig                 |   8 --
 arch/x86/crypto/poly1305_glue.c         |  99 ++------------
 crypto/Makefile                         |   3 +-
 crypto/poly1305.c                       | 153 +++++++++++++++++++++
 crypto/poly1305_generic.c               | 149 ---------------------
 include/crypto/poly1305.h               |  13 +-
 lib/crypto/poly1305.c                   |   2 -
 15 files changed, 242 insertions(+), 781 deletions(-)
 create mode 100644 crypto/poly1305.c
 delete mode 100644 crypto/poly1305_generic.c

base-commit: 3be3f70ee95da03a87d94c4a714ee679a5c7b34d

Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 1/9 crypto: powerpc/poly1305 - implement library instead of shash

From: Eric Biggers <[email protected]>

Currently the Power10 optimized Poly1305 is only wired up to the crypto_shash API, which makes it unavailable to users of the library API. The crypto_shash API for Poly1305 is going to change to be implemented on top of the library API, so the library API needs to be supported. And of course it's needed anyway to serve the library users.

Therefore, change the Power10 optimized Poly1305 code to implement the library API instead of the crypto_shash API.

---
 arch/powerpc/crypto/Kconfig             |  11 +-
 arch/powerpc/crypto/poly1305-p10-glue.c | 132 +++++++-----------------
 2 files changed, 39 insertions(+), 104 deletions(-)
arch/powerpc/crypto/Kconfig +3 -8
index 47dccdd49637..cbcf76953d83 100644
@@ -98,20 +98,15 @@ config CRYPTO_CHACHA20_P10
 	select CRYPTO_LIB_CHACHA_GENERIC
 	select CRYPTO_ARCH_HAVE_LIB_CHACHA
 	default CRYPTO_LIB_CHACHA_INTERNAL
 
 config CRYPTO_POLY1305_P10
-	tristate "Hash functions: Poly1305 (P10 or later)"
+	tristate
 	depends on PPC64 && CPU_LITTLE_ENDIAN && VSX
-	select CRYPTO_HASH
+	select CRYPTO_ARCH_HAVE_LIB_POLY1305
 	select CRYPTO_LIB_POLY1305_GENERIC
-	help
-	  Poly1305 authenticator algorithm (RFC7539)
-
-	  Architecture: PowerPC64
-	  - Power10 or later
-	  - Little-endian
+	default CRYPTO_LIB_POLY1305_INTERNAL
 
 config CRYPTO_DEV_VMX
         bool "Support for VMX cryptographic acceleration instructions"
         depends on PPC64 && VSX
         help
arch/powerpc/crypto/poly1305-p10-glue.c +36 -96

209 lines not on this page · raw message

base-commit: 3be3f70ee95da03a87d94c4a714ee679a5c7b34d

Signature · 1 line
2.49.0
author maintainer
#2 lore raw

PATCH 2/9 crypto: poly1305 - centralize the shash wrappers for arch code

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

Following the example of the crc32, crc32c, and chacha code, make the crypto subsystem register both generic and architecture-optimized poly1305 shash algorithms, both implemented on top of the appropriate library functions. This eliminates the need for every architecture to implement the same shash glue code.

Note that the poly1305 shash requires that the key be prepended to the data, which differs from the library functions where the key is simply a parameter to poly1305_init(). Previously this was handled at a fairly low level, polluting the library code with shash-specific code. Reorganize things so that the shash code handles this quirk itself.

Also, to register the architecture-optimized shashes only when architecture-optimized code is actually being used, add a function poly1305_is_arch_optimized() and make each arch implement it. Change each architecture's Poly1305 module_init function to arch_initcall so that the CPU feature detection is guaranteed to run before poly1305_is_arch_optimized() gets called by crypto/poly1305.c. (In cases where poly1305_is_arch_optimized() just returns true unconditionally, using arch_initcall is not strictly needed, but it's still good to be consistent across architectures.)

---
 arch/arm/crypto/poly1305-glue.c         |  11 +-
 arch/arm64/crypto/poly1305-glue.c       |   9 +-
 arch/mips/crypto/poly1305-glue.c        |  10 +-
 arch/powerpc/crypto/poly1305-p10-glue.c |   6 +
 arch/x86/crypto/poly1305_glue.c         |   8 +-
 crypto/Makefile                         |   3 +-
 crypto/poly1305.c                       | 152 ++++++++++++++++++++++++
 crypto/poly1305_generic.c               | 149 -----------------------
 include/crypto/poly1305.h               |   9 ++
 9 files changed, 201 insertions(+), 156 deletions(-)
 create mode 100644 crypto/poly1305.c
 delete mode 100644 crypto/poly1305_generic.c
arch/arm/crypto/poly1305-glue.c +9 -2
index 4464ffbf8fd1..238dbf50d05d 100644
@@ -216,11 +216,11 @@ static struct shash_alg arm_poly1305_algs[] = {{
 	.final			= arm_poly1305_final,
 	.digestsize		= POLY1305_DIGEST_SIZE,
 	.descsize		= sizeof(struct poly1305_desc_ctx),
 
 	.base.cra_name		= "poly1305",
-	.base.cra_driver_name	= "poly1305-arm",
+	.base.cra_driver_name	= "poly1305-arm-old",
 	.base.cra_priority	= 150,
 	.base.cra_blocksize	= POLY1305_BLOCK_SIZE,
 	.base.cra_module	= THIS_MODULE,
 #ifdef CONFIG_KERNEL_MODE_NEON
 }, {
@@ -236,10 +236,17 @@ static struct shash_alg arm_poly1305_algs[] = {{
 	.base.cra_blocksize	= POLY1305_BLOCK_SIZE,
 	.base.cra_module	= THIS_MODULE,
 #endif
 }};
 
+bool poly1305_is_arch_optimized(void)
+{
+	/* We always can use at least the ARM scalar implementation. */
+	return true;
+}
+EXPORT_SYMBOL(poly1305_is_arch_optimized);
+
 static int __init arm_poly1305_mod_init(void)
 {
 	if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) &&
 	    (elf_hwcap & HWCAP_NEON))
 		static_branch_enable(&have_neon);
@@ -262,11 +269,11 @@ static void __exit arm_poly1305_mod_exit(void)
 	}
 	crypto_unregister_shashes(arm_poly1305_algs,
 				  ARRAY_SIZE(arm_poly1305_algs));
 }
 
-module_init(arm_poly1305_mod_init);
+arch_initcall(arm_poly1305_mod_init);
 module_exit(arm_poly1305_mod_exit);
 
 MODULE_DESCRIPTION("Accelerated Poly1305 transform for ARM");
 MODULE_LICENSE("GPL v2");
 MODULE_ALIAS_CRYPTO("poly1305");
arch/arm64/crypto/poly1305-glue.c +8 -1
index 18883ea438f3..89415731d9be 100644
@@ -204,10 +204,17 @@ static struct shash_alg neon_poly1305_alg = {
 	.base.cra_priority	= 200,
 	.base.cra_blocksize	= POLY1305_BLOCK_SIZE,
 	.base.cra_module	= THIS_MODULE,
 };
 
+bool poly1305_is_arch_optimized(void)
+{
+	/* We always can use at least the ARM64 scalar implementation. */
+	return true;
+}
+EXPORT_SYMBOL(poly1305_is_arch_optimized);
+
 static int __init neon_poly1305_mod_init(void)
 {
 	if (!cpu_have_named_feature(ASIMD))
 		return 0;
 
@@ -221,11 +228,11 @@ static void __exit neon_poly1305_mod_exit(void)
 {
 	if (IS_REACHABLE(CONFIG_CRYPTO_HASH) && cpu_have_named_feature(ASIMD))
 		crypto_unregister_shash(&neon_poly1305_alg);
 }
 
-module_init(neon_poly1305_mod_init);
+arch_initcall(neon_poly1305_mod_init);
 module_exit(neon_poly1305_mod_exit);
 
 MODULE_DESCRIPTION("Poly1305 transform using NEON instructions");
 MODULE_LICENSE("GPL v2");
 MODULE_ALIAS_CRYPTO("poly1305");
arch/mips/crypto/poly1305-glue.c +8 -2
index c03ad0bbe69c..9eee71dc0b99 100644
@@ -163,16 +163,22 @@ static struct shash_alg mips_poly1305_alg = {
 	.final			= mips_poly1305_final,
 	.digestsize		= POLY1305_DIGEST_SIZE,
 	.descsize		= sizeof(struct poly1305_desc_ctx),
 
 	.base.cra_name		= "poly1305",
-	.base.cra_driver_name	= "poly1305-mips",
+	.base.cra_driver_name	= "poly1305-mips-old",
 	.base.cra_priority	= 200,
 	.base.cra_blocksize	= POLY1305_BLOCK_SIZE,
 	.base.cra_module	= THIS_MODULE,
 };
 
+bool poly1305_is_arch_optimized(void)
+{
+	return true;
+}
+EXPORT_SYMBOL(poly1305_is_arch_optimized);
+
 static int __init mips_poly1305_mod_init(void)
 {
 	return IS_REACHABLE(CONFIG_CRYPTO_HASH) ?
 		crypto_register_shash(&mips_poly1305_alg) : 0;
 }
@@ -181,11 +187,11 @@ static void __exit mips_poly1305_mod_exit(void)
 {
 	if (IS_REACHABLE(CONFIG_CRYPTO_HASH))
 		crypto_unregister_shash(&mips_poly1305_alg);
 }
 
-module_init(mips_poly1305_mod_init);
+arch_initcall(mips_poly1305_mod_init);
 module_exit(mips_poly1305_mod_exit);
 
 MODULE_DESCRIPTION("Poly1305 transform (MIPS accelerated");
 MODULE_LICENSE("GPL v2");
 MODULE_ALIAS_CRYPTO("poly1305");
arch/powerpc/crypto/poly1305-p10-glue.c +6 -0
index 87bd5eba4497..40d296d52c23 100644
@@ -111,10 +111,16 @@ void poly1305_final_arch(struct poly1305_desc_ctx *dctx, u8 *dst)
 
 	poly1305_emit_64(&dctx->h, &dctx->s, dst);
 }
 EXPORT_SYMBOL(poly1305_final_arch);
 
+bool poly1305_is_arch_optimized(void)
+{
+	return static_key_enabled(&have_p10);
+}
+EXPORT_SYMBOL(poly1305_is_arch_optimized);
+
 static int __init poly1305_p10_init(void)
 {
 	if (cpu_has_feature(CPU_FTR_ARCH_31))
 		static_branch_enable(&have_p10);
 	return 0;
arch/x86/crypto/poly1305_glue.c +7 -1
index 8b5593c46da7..40d03a9a4fb5 100644
@@ -255,10 +255,16 @@ static struct shash_alg alg = {
 		.cra_blocksize		= POLY1305_BLOCK_SIZE,
 		.cra_module		= THIS_MODULE,
 	},
 };
 
+bool poly1305_is_arch_optimized(void)
+{
+	return static_key_enabled(&poly1305_use_avx);
+}
+EXPORT_SYMBOL(poly1305_is_arch_optimized);
+
 static int __init poly1305_simd_mod_init(void)
 {
 	if (boot_cpu_has(X86_FEATURE_AVX) &&
 	    cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL))
 		static_branch_enable(&poly1305_use_avx);
@@ -278,11 +284,11 @@ static void __exit poly1305_simd_mod_exit(void)
 {
 	if (IS_REACHABLE(CONFIG_CRYPTO_HASH))
 		crypto_unregister_shash(&alg);
 }
 
-module_init(poly1305_simd_mod_init);
+arch_initcall(poly1305_simd_mod_init);
 module_exit(poly1305_simd_mod_exit);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Jason A. Donenfeld <[email protected]>");
 MODULE_DESCRIPTION("Poly1305 authenticator");
crypto/Makefile +2 -1
index 98510a2aa0b1..53f5db5f1105 100644
@@ -148,11 +148,12 @@ obj-$(CONFIG_CRYPTO_KHAZAD) += khazad.o
 obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o
 obj-$(CONFIG_CRYPTO_SEED) += seed.o
 obj-$(CONFIG_CRYPTO_ARIA) += aria_generic.o
 obj-$(CONFIG_CRYPTO_CHACHA20) += chacha.o
 CFLAGS_chacha.o += -DARCH=$(ARCH)
-obj-$(CONFIG_CRYPTO_POLY1305) += poly1305_generic.o
+obj-$(CONFIG_CRYPTO_POLY1305) += poly1305.o
+CFLAGS_poly1305.o += -DARCH=$(ARCH)
 obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
 obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
 obj-$(CONFIG_CRYPTO_CRC32C) += crc32c_generic.o
 obj-$(CONFIG_CRYPTO_CRC32) += crc32_generic.o
 CFLAGS_crc32c_generic.o += -DARCH=$(ARCH)
crypto/poly1305.c new file +152 -0

152 lines not on this page · raw message

crypto/poly1305_generic.c deleted +0 -149

149 lines not on this page · raw message

include/crypto/poly1305.h +9 -0
index 090692ec3bc7..91444965772a 100644
@@ -94,6 +94,15 @@ static inline void poly1305_final(struct poly1305_desc_ctx *desc, u8 *digest)
 		poly1305_final_arch(desc, digest);
 	else
 		poly1305_final_generic(desc, digest);
 }
 
+#if IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_POLY1305)
+bool poly1305_is_arch_optimized(void);
+#else
+static inline bool poly1305_is_arch_optimized(void)
+{
+	return false;
+}
+#endif
+
 #endif
Signature · 1 line
2.49.0
author maintainer
#3 lore raw

PATCH 3/9 crypto: arm/poly1305 - remove redundant shash algorithm

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

Since crypto/poly1305.c now registers a poly1305-$(ARCH) shash algorithm that uses the architecture's Poly1305 library functions, individual architectures no longer need to do the same. Therefore, remove the redundant shash algorithm from the arch-specific code and leave just the library functions there.

---
 arch/arm/crypto/Kconfig         |   6 --
 arch/arm/crypto/poly1305-glue.c | 167 +-------------------------------
 2 files changed, 3 insertions(+), 170 deletions(-)
arch/arm/crypto/Kconfig +0 -6
index 332f2430beec..3530e7c80793 100644
@@ -46,18 +46,12 @@ config CRYPTO_NHPOLY1305_NEON
 	  Architecture: arm using:
 	  - NEON (Advanced SIMD) extensions
 
 config CRYPTO_POLY1305_ARM
 	tristate
-	select CRYPTO_HASH
 	select CRYPTO_ARCH_HAVE_LIB_POLY1305
 	default CRYPTO_LIB_POLY1305_INTERNAL
-	help
-	  Poly1305 authenticator algorithm (RFC7539)
-
-	  Architecture: arm optionally using
-	  - NEON (Advanced SIMD) extensions
 
 config CRYPTO_BLAKE2S_ARM
 	bool "Hash functions: BLAKE2s"
 	select CRYPTO_ARCH_HAVE_LIB_BLAKE2S
 	help
arch/arm/crypto/poly1305-glue.c +3 -164

211 lines not on this page · raw message

Signature · 1 line
2.49.0
author maintainer
#4 lore raw

PATCH 4/9 crypto: arm64/poly1305 - remove redundant shash algorithm

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

Since crypto/poly1305.c now registers a poly1305-$(ARCH) shash algorithm that uses the architecture's Poly1305 library functions, individual architectures no longer need to do the same. Therefore, remove the redundant shash algorithm from the arch-specific code and leave just the library functions there.

---
 arch/arm64/crypto/Kconfig         |   6 --
 arch/arm64/crypto/poly1305-glue.c | 140 ++----------------------------
 2 files changed, 6 insertions(+), 140 deletions(-)
arch/arm64/crypto/Kconfig +0 -6
index ce655da0fbee..c47a7649a241 100644
@@ -26,18 +26,12 @@ config CRYPTO_NHPOLY1305_NEON
 	  - NEON (Advanced SIMD) extensions
 
 config CRYPTO_POLY1305_NEON
 	tristate
 	depends on KERNEL_MODE_NEON
-	select CRYPTO_HASH
 	select CRYPTO_ARCH_HAVE_LIB_POLY1305
 	default CRYPTO_LIB_POLY1305_INTERNAL
-	help
-	  Poly1305 authenticator algorithm (RFC7539)
-
-	  Architecture: arm64 using:
-	  - NEON (Advanced SIMD) extensions
 
 config CRYPTO_SHA1_ARM64_CE
 	tristate "Hash functions: SHA-1 (ARMv8 Crypto Extensions)"
 	depends on KERNEL_MODE_NEON
 	select CRYPTO_HASH
arch/arm64/crypto/poly1305-glue.c +6 -134

182 lines not on this page · raw message

Signature · 1 line
2.49.0
author maintainer
#5 lore raw

PATCH 5/9 crypto: mips/poly1305 - drop redundant dependency on CONFIG_MIPS

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

arch/mips/crypto/Kconfig is sourced only when CONFIG_MIPS is enabled, so there is no need for options defined in that file to depend on it.

---
 arch/mips/crypto/Kconfig | 1 -
 1 file changed, 1 deletion(-)
arch/mips/crypto/Kconfig +0 -1
index 0189686de3a1..9892391f74ac 100644
@@ -2,11 +2,10 @@
 
 menu "Accelerated Cryptographic Algorithms for CPU (mips)"
 
 config CRYPTO_POLY1305_MIPS
 	tristate
-	depends on MIPS
 	select CRYPTO_HASH
 	select CRYPTO_ARCH_HAVE_LIB_POLY1305
 	default CRYPTO_LIB_POLY1305_INTERNAL
 	help
 	  Poly1305 authenticator algorithm (RFC7539)
Signature · 1 line
2.49.0
author maintainer
#6 lore raw

PATCH 6/9 crypto: mips/poly1305 - remove redundant shash algorithm

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

Since crypto/poly1305.c now registers a poly1305-$(ARCH) shash algorithm that uses the architecture's Poly1305 library functions, individual architectures no longer need to do the same. Therefore, remove the redundant shash algorithm from the arch-specific code and leave just the library functions there.

---
 arch/mips/crypto/Kconfig         |   5 --
 arch/mips/crypto/poly1305-glue.c | 120 +------------------------------
 2 files changed, 2 insertions(+), 123 deletions(-)
arch/mips/crypto/Kconfig +0 -5
index 9892391f74ac..8283664a1f24 100644
@@ -2,17 +2,12 @@
 
 menu "Accelerated Cryptographic Algorithms for CPU (mips)"
 
 config CRYPTO_POLY1305_MIPS
 	tristate
-	select CRYPTO_HASH
 	select CRYPTO_ARCH_HAVE_LIB_POLY1305
 	default CRYPTO_LIB_POLY1305_INTERNAL
-	help
-	  Poly1305 authenticator algorithm (RFC7539)
-
-	  Architecture: mips
 
 config CRYPTO_MD5_OCTEON
 	tristate "Digests: MD5 (OCTEON)"
 	depends on CPU_CAVIUM_OCTEON
 	select CRYPTO_MD5
arch/mips/crypto/poly1305-glue.c +2 -118

155 lines not on this page · raw message

Signature · 1 line
2.49.0
author maintainer
#7 lore raw

PATCH 7/9 crypto: x86/poly1305 - remove redundant shash algorithm

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

Since crypto/poly1305.c now registers a poly1305-$(ARCH) shash algorithm that uses the architecture's Poly1305 library functions, individual architectures no longer need to do the same. Therefore, remove the redundant shash algorithm from the arch-specific code and leave just the library functions there.

---
 arch/x86/crypto/Kconfig         |  7 ---
 arch/x86/crypto/poly1305_glue.c | 97 +++------------------------------
 2 files changed, 7 insertions(+), 97 deletions(-)
arch/x86/crypto/Kconfig +0 -7
index 0cec75926380..31804dacf9a4 100644
@@ -397,20 +397,13 @@ config CRYPTO_POLYVAL_CLMUL_NI
 	  - CLMUL-NI (carry-less multiplication new instructions)
 
 config CRYPTO_POLY1305_X86_64
 	tristate
 	depends on X86 && 64BIT
-	select CRYPTO_HASH
 	select CRYPTO_LIB_POLY1305_GENERIC
 	select CRYPTO_ARCH_HAVE_LIB_POLY1305
 	default CRYPTO_LIB_POLY1305_INTERNAL
-	help
-	  Poly1305 authenticator algorithm (RFC7539)
-
-	  Architecture: x86_64 using:
-	  - SSE2 (Streaming SIMD Extensions 2)
-	  - AVX2 (Advanced Vector Extensions 2)
 
 config CRYPTO_SHA1_SSSE3
 	tristate "Hash functions: SHA-1 (SSSE3/AVX/AVX2/SHA-NI)"
 	depends on X86 && 64BIT
 	select CRYPTO_SHA1
arch/x86/crypto/poly1305_glue.c +7 -90

165 lines not on this page · raw message

Signature · 1 line
2.49.0
author maintainer
#8 lore raw

PATCH 8/9 crypto: x86/poly1305 - don't select CRYPTO_LIB_POLY1305_GENERIC

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

The x86 Poly1305 code never falls back to the generic code, so selecting CRYPTO_LIB_POLY1305_GENERIC is unnecessary.

---
 arch/x86/crypto/Kconfig | 1 -
 1 file changed, 1 deletion(-)
arch/x86/crypto/Kconfig +0 -1
index 31804dacf9a4..a25765186ba3 100644
@@ -397,11 +397,10 @@ config CRYPTO_POLYVAL_CLMUL_NI
 	  - CLMUL-NI (carry-less multiplication new instructions)
 
 config CRYPTO_POLY1305_X86_64
 	tristate
 	depends on X86 && 64BIT
-	select CRYPTO_LIB_POLY1305_GENERIC
 	select CRYPTO_ARCH_HAVE_LIB_POLY1305
 	default CRYPTO_LIB_POLY1305_INTERNAL
 
 config CRYPTO_SHA1_SSSE3
 	tristate "Hash functions: SHA-1 (SSSE3/AVX/AVX2/SHA-NI)"
Signature · 1 line
2.49.0
author maintainer
#9 lore raw

PATCH 9/9 crypto: poly1305 - remove rset and sset fields of poly1305_desc_ctx

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

These fields are no longer needed, so remove them.

---
 include/crypto/poly1305.h | 4 ----
 lib/crypto/poly1305.c     | 2 --
 2 files changed, 6 deletions(-)
include/crypto/poly1305.h +0 -4
index 91444965772a..6e21ec2d1dc2 100644
@@ -41,14 +41,10 @@ struct poly1305_state {
 struct poly1305_desc_ctx {
 	/* partial buffer */
 	u8 buf[POLY1305_BLOCK_SIZE];
 	/* bytes used in partial buffer */
 	unsigned int buflen;
-	/* how many keys have been set in r[] */
-	unsigned short rset;
-	/* whether s[] has been set */
-	bool sset;
 	/* finalize key */
 	u32 s[4];
 	/* accumulator */
 	struct poly1305_state h;
 	/* key */
lib/crypto/poly1305.c +0 -2
index 6e80214ebad8..b633b043f0f6 100644
@@ -20,12 +20,10 @@ void poly1305_init_generic(struct poly1305_desc_ctx *desc,
 	desc->s[1] = get_unaligned_le32(key + 20);
 	desc->s[2] = get_unaligned_le32(key + 24);
 	desc->s[3] = get_unaligned_le32(key + 28);
 	poly1305_core_init(&desc->h);
 	desc->buflen = 0;
-	desc->sset = true;
-	desc->rset = 2;
 }
 EXPORT_SYMBOL_GPL(poly1305_init_generic);
 
 void poly1305_update_generic(struct poly1305_desc_ctx *desc, const u8 *src,
 			     unsigned int nbytes)
Signature · 1 line
2.49.0
maintainer
#10 lore raw
In reply to Eric Biggers
Quoted 36 lines · Eric Biggers

This series removes the per-architecture poly1305 shash glue code and re-implements the poly1305 shashes on top of the Poly1305 library functions. This ends up being much simpler, and it is how it should have been done originally. This follows similar changes to crc32, crc32c, and chacha20.

This series also makes the Poly1305 library be optimized on PowerPC. Previously the PowerPC-optimized Poly1305 code only supported shash.

Eric Biggers (9):
crypto: powerpc/poly1305 - implement library instead of shash
crypto: poly1305 - centralize the shash wrappers for arch code
crypto: arm/poly1305 - remove redundant shash algorithm
crypto: arm64/poly1305 - remove redundant shash algorithm
crypto: mips/poly1305 - drop redundant dependency on CONFIG_MIPS
crypto: mips/poly1305 - remove redundant shash algorithm
crypto: x86/poly1305 - remove redundant shash algorithm
crypto: x86/poly1305 - don't select CRYPTO_LIB_POLY1305_GENERIC
crypto: poly1305 - remove rset and sset fields of poly1305_desc_ctx

arch/arm/crypto/Kconfig                 |   6 -
arch/arm/crypto/poly1305-glue.c         | 170 ++----------------------
arch/arm64/crypto/Kconfig               |   6 -
arch/arm64/crypto/poly1305-glue.c       | 143 ++------------------
arch/mips/crypto/Kconfig                |   6 -
arch/mips/crypto/poly1305-glue.c        | 120 +----------------
arch/powerpc/crypto/Kconfig             |  11 +-
arch/powerpc/crypto/poly1305-p10-glue.c | 134 ++++++-------------
arch/x86/crypto/Kconfig                 |   8 --
arch/x86/crypto/poly1305_glue.c         |  99 ++------------
crypto/Makefile                         |   3 +-
crypto/poly1305.c                       | 153 +++++++++++++++++++++
crypto/poly1305_generic.c               | 149 ---------------------
include/crypto/poly1305.h               |  13 +-
lib/crypto/poly1305.c                   |   2 -
15 files changed, 242 insertions(+), 781 deletions(-)
Quoted 5 lines

create mode 100644 crypto/poly1305.c
delete mode 100644 crypto/poly1305_generic.c

base-commit: 3be3f70ee95da03a87d94c4a714ee679a5c7b34d

All applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt