[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250621021549.105357-1-ebiggers@kernel.org>
Date: Fri, 20 Jun 2025 19:15:49 -0700
From: Eric Biggers <ebiggers@...nel.org>
To: linux-crypto@...r.kernel.org
Cc: linux-kernel@...r.kernel.org,
"Jason A . Donenfeld " <Jason@...c4.com>,
Ard Biesheuvel <ardb@...nel.org>,
x86@...nel.org,
Eric Biggers <ebiggers@...nel.org>
Subject: [PATCH] lib/crypto: x86/sha512: Remove unnecessary checks for nblocks==0
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@...nel.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
Powered by blists - more mailing lists