public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	"Jason A . Donenfeld " <Jason@zx2c4.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	x86@kernel.org, Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH] lib/crypto: x86/sha512: Remove unnecessary checks for nblocks==0
Date: Fri, 20 Jun 2025 19:15:49 -0700	[thread overview]
Message-ID: <20250621021549.105357-1-ebiggers@kernel.org> (raw)

Since sha512_blocks() is called only with nblocks >= 1, remove
unnecessary checks for nblocks == 0 from the x86 SHA-512 assembly code.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 lib/crypto/x86/sha512-avx-asm.S   | 6 +-----
 lib/crypto/x86/sha512-avx2-asm.S  | 5 +----
 lib/crypto/x86/sha512-ssse3-asm.S | 6 +-----
 3 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/lib/crypto/x86/sha512-avx-asm.S b/lib/crypto/x86/sha512-avx-asm.S
index 84291772ba385..af7ea311cc945 100644
--- a/lib/crypto/x86/sha512-avx-asm.S
+++ b/lib/crypto/x86/sha512-avx-asm.S
@@ -271,18 +271,15 @@ frame_size = frame_WK + WK_SIZE
 #			    const u8 *data, size_t nblocks);
 # Purpose: Updates the SHA512 digest stored at "state" with the message
 # stored in "data".
 # The size of the message pointed to by "data" must be an integer multiple
 # of SHA512 message blocks.
-# "nblocks" is the message length in SHA512 blocks
+# "nblocks" is the message length in SHA512 blocks.  Must be >= 1.
 ########################################################################
 SYM_FUNC_START(sha512_transform_avx)
 	ANNOTATE_NOENDBR	# since this is called only via static_call
 
-	test msglen, msglen
-	je .Lnowork
-
 	# Save GPRs
 	push	%rbx
 	push	%r12
 	push	%r13
 	push	%r14
@@ -362,11 +359,10 @@ SYM_FUNC_START(sha512_transform_avx)
 	pop	%r14
 	pop	%r13
 	pop	%r12
 	pop	%rbx
 
-.Lnowork:
 	RET
 SYM_FUNC_END(sha512_transform_avx)
 
 ########################################################################
 ### Binary Data
diff --git a/lib/crypto/x86/sha512-avx2-asm.S b/lib/crypto/x86/sha512-avx2-asm.S
index 2af6a4d7d1640..1302ddb5ec8cc 100644
--- a/lib/crypto/x86/sha512-avx2-asm.S
+++ b/lib/crypto/x86/sha512-avx2-asm.S
@@ -563,11 +563,11 @@ frame_size = frame_CTX + CTX_SIZE
 #			     const u8 *data, size_t nblocks);
 # Purpose: Updates the SHA512 digest stored at "state" with the message
 # stored in "data".
 # The size of the message pointed to by "data" must be an integer multiple
 # of SHA512 message blocks.
-# "nblocks" is the message length in SHA512 blocks
+# "nblocks" is the message length in SHA512 blocks.  Must be >= 1.
 ########################################################################
 SYM_FUNC_START(sha512_transform_rorx)
 	ANNOTATE_NOENDBR	# since this is called only via static_call
 
 	# Save GPRs
@@ -582,11 +582,10 @@ SYM_FUNC_START(sha512_transform_rorx)
 	mov	%rsp, %rbp
 	sub	$frame_size, %rsp
 	and	$~(0x20 - 1), %rsp
 
 	shl	$7, NUM_BLKS	# convert to bytes
-	jz	.Ldone_hash
 	add	INP, NUM_BLKS	# pointer to end of data
 	mov	NUM_BLKS, frame_INPEND(%rsp)
 
 	## load initial digest
 	mov	8*0(CTX1), a
@@ -668,12 +667,10 @@ SYM_FUNC_START(sha512_transform_rorx)
 	mov	frame_INP(%rsp), INP
 	add	$128, INP
 	cmp	frame_INPEND(%rsp), INP
 	jne	.Lloop0
 
-.Ldone_hash:
-
 	# Restore Stack Pointer
 	mov	%rbp, %rsp
 	pop	%rbp
 
 	# Restore GPRs
diff --git a/lib/crypto/x86/sha512-ssse3-asm.S b/lib/crypto/x86/sha512-ssse3-asm.S
index a7544beb59d38..108f1accc6bc7 100644
--- a/lib/crypto/x86/sha512-ssse3-asm.S
+++ b/lib/crypto/x86/sha512-ssse3-asm.S
@@ -270,18 +270,15 @@ frame_size = frame_WK + WK_SIZE
 #			      const u8 *data, size_t nblocks);
 # Purpose: Updates the SHA512 digest stored at "state" with the message
 # stored in "data".
 # The size of the message pointed to by "data" must be an integer multiple
 # of SHA512 message blocks.
-# "nblocks" is the message length in SHA512 blocks
+# "nblocks" is the message length in SHA512 blocks.  Must be >= 1.
 ########################################################################
 SYM_FUNC_START(sha512_transform_ssse3)
 	ANNOTATE_NOENDBR	# since this is called only via static_call
 
-	test msglen, msglen
-	je .Lnowork
-
 	# Save GPRs
 	push	%rbx
 	push	%r12
 	push	%r13
 	push	%r14
@@ -361,11 +358,10 @@ SYM_FUNC_START(sha512_transform_ssse3)
 	pop	%r14
 	pop	%r13
 	pop	%r12
 	pop	%rbx
 
-.Lnowork:
 	RET
 SYM_FUNC_END(sha512_transform_ssse3)
 
 ########################################################################
 ### Binary Data

base-commit: 662bd3f5ee337b68c51e24593010e15ff26dabf0
-- 
2.50.0


             reply	other threads:[~2025-06-21  2:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-21  2:15 Eric Biggers [this message]
2025-06-24  2:45 ` [PATCH] lib/crypto: x86/sha512: Remove unnecessary checks for nblocks==0 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=20250621021549.105357-1-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=ardb@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@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