lib/crypto: powerpc/md5: Drop powerpc optimized MD5 code
Subsystems (2)
Eric Biggers
maintainerPATCH v2 1/1 lib/crypto: powerpc/md5: Drop powerpc optimized MD5 code
MD5 is obsolete, is vulnerable to collision attacks, and is being replaced by SHA-256 in new systems. It doesn't make sense to continue to maintain architecture-optimized implementations of MD5. Effort should be spent on modern algorithms.
Indeed, architecture-optimized MD5 code remains only for powerpc. It was already removed from mips and sparc, and it never existed for any other architecture (e.g. x86, arm, or arm64) in the first place. Earlier the decision was made to keep the powerpc MD5 code for a while anyway because of someone using it via AF_ALG via libkcapi-hasher
(https://lore.kernel.org/r/[email protected]/)
However, with AF_ALG itself now being on its way out due to its continuous stream of security vulnerabilities
(https://lore.kernel.org/r/[email protected]/),
it's also time to be a bit more forceful with nudging people towards userspace crypto code. It's always been the better solution anyway, and it's much more efficient if properly optimized code is used.
Note that the md5-asm.S file contains no privileged instructions and could be run in userspace just fine.
Thus, we now have two factors going against keeping the powerpc MD5 code. Different people might weigh these two factors differently, but I think the two of them together make the removal the clear choice.
Let's remove it.
---
This patch is intended to be taken via libcrypto-next
v2: reworked commit message
lib/crypto/Kconfig | 5 - lib/crypto/Makefile | 4 - lib/crypto/md5.c | 20 ++- lib/crypto/powerpc/md5-asm.S | 235 ----------------------------------- lib/crypto/powerpc/md5.h | 12 -- 5 files changed, 7 insertions(+), 269 deletions(-) delete mode 100644 lib/crypto/powerpc/md5-asm.S delete mode 100644 lib/crypto/powerpc/md5.h
lib/crypto/Kconfig +0 -5
@@ -129,15 +129,10 @@ config CRYPTO_LIB_MD5 tristate help The MD5 and HMAC-MD5 library functions. Select this if your module uses any of the functions from <crypto/md5.h>. -config CRYPTO_LIB_MD5_ARCH - bool - depends on CRYPTO_LIB_MD5 && !UML - default y if PPC - config CRYPTO_LIB_MLDSA tristate select CRYPTO_LIB_SHA3 help The ML-DSA library functions. Select this if your module uses any of
lib/crypto/Makefile +0 -4
@@ -185,14 +185,10 @@ clean-files += powerpc/ghashp8-ppc.S ################################################################################ obj-$(CONFIG_CRYPTO_LIB_MD5) += libmd5.o libmd5-y := md5.o -ifeq ($(CONFIG_CRYPTO_LIB_MD5_ARCH),y) -CFLAGS_md5.o += -I$(src)/$(SRCARCH) -libmd5-$(CONFIG_PPC) += powerpc/md5-asm.o -endif # CONFIG_CRYPTO_LIB_MD5_ARCH ################################################################################ obj-$(CONFIG_CRYPTO_LIB_MLDSA) += libmldsa.o libmldsa-y := mldsa.o
lib/crypto/md5.c +7 -13
@@ -1,11 +1,11 @@// SPDX-License-Identifier: GPL-2.0-or-later /* * MD5 and HMAC-MD5 library functions * -* md5_block_generic() is derived from cryptoapi implementation, originally -* based on the public domain implementation written by Colin Plumb in 1993. +* md5_block() is derived from cryptoapi implementation, originally based on the +* public domain implementation written by Colin Plumb in 1993. * * Copyright (c) Cryptoapi developers. * Copyright (c) 2002 James Morris <[email protected]> * Copyright 2025 Google LLC */
@@ -29,12 +29,12 @@ static const struct md5_block_state md5_iv = {#define F4 (x, y, z) (y ^ (x | ~z))#define MD5STEP (f, w, x, y, z, in, s) \ (w += f(x, y, z) + in, w = rol32(w, s) + x) -static void md5_block_generic (struct md5_block_state *state, -const u8 data[MD5_BLOCK_SIZE ]) +static void md5_block (struct md5_block_state *state, +const u8 data[MD5_BLOCK_SIZE ]) {u32 in[MD5_BLOCK_WORDS ];u32 a, b, c, d;memcpy (in, data,MD5_BLOCK_SIZE );
@@ -117,25 +117,19 @@ static void md5_block_generic(struct md5_block_state *state, state->h[1 ] += b; state->h[2 ] += c; state->h[3 ] += d; } -static void __maybe_unused md5_blocks_generic (struct md5_block_state *state, -const u8 *data,size_t nblocks) +static void md5_blocks (struct md5_block_state *state, +const u8 *data,size_t nblocks) {do { -md5_block_generic (state, data); +md5_block (state, data); data +=MD5_BLOCK_SIZE ; }while (--nblocks); } -#ifdef CONFIG_CRYPTO_LIB_MD5_ARCH -#include "md5.h" /* $(SRCARCH)/md5.h */ -#else -#define md5_blocks md5_blocks_generic -#endif -void md5_init (struct md5_ctx *ctx) { ctx->state = md5_iv; ctx->bytecount =0 ; }
lib/crypto/powerpc/md5-asm.S deleted +0 -235
235 lines not on this page · raw message
lib/crypto/powerpc/md5.h deleted +0 -12
@@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* MD5 optimized for PowerPC -*/ - -void ppc_md5_transform (u32 *state,const u8 *data,size_t nblocks); - -static void md5_blocks (struct md5_block_state *state, -const u8 *data,size_t nblocks) -{ -ppc_md5_transform (state->h, data, nblocks); -}
base-commit: 74fe02ce122a6103f207d29fafc8b3a53de6abaf
Signature · 1 line
2.54.0
Quoted 26 lines · Eric Biggers
MD5 is obsolete, is vulnerable to collision attacks, and is being replaced by SHA-256 in new systems. It doesn't make sense to continue to maintain architecture-optimized implementations of MD5. Effort should be spent on modern algorithms.
Indeed, architecture-optimized MD5 code remains only for powerpc. It was already removed from mips and sparc, and it never existed for any other architecture (e.g. x86, arm, or arm64) in the first place. Earlier the decision was made to keep the powerpc MD5 code for a while anyway because of someone using it via
AF_ALGvia libkcapi-hasher
(https://lore.kernel.org/r/[email protected]/)However, with
AF_ALGitself now being on its way out due to its continuous stream of security vulnerabilities
(https://lore.kernel.org/r/[email protected]/),
it's also time to be a bit more forceful with nudging people towards userspace crypto code. It's always been the better solution anyway, and it's much more efficient if properly optimized code is used.Note that the
md5-asm.Sfile contains no privileged instructions and could be run in userspace just fine.Thus, we now have two factors going against keeping the powerpc MD5 code. Different people might weigh these two factors differently, but I think the two of them together make the removal the clear choice.
Quoted 8 lines
Let's remove it.
Acked-by Ard Biesheuvel <[email protected]>Signed-off-by Eric Biggers <[email protected]>---
This patch is intended to be taken via libcrypto-next
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next
- Eric