Skip to contentSkip to conversation

lib/crypto: arm64/sha512-ce: Drop compatibility macros for older binutils

PATCH In review Eric Biggers 2 participants 4 messages Jul 18, 2025 – Jul 21, 2025

Subsystems (2)
lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

PATCH 1/1 lib/crypto: arm64/sha512-ce: Drop compatibility macros for older binutils

Now that the oldest supported binutils version is 2.30, the macros that emit the SHA-512 instructions as '.inst' words are no longer needed. So drop them. No change in the generated machine code.

Changed from the original patch by Ard Biesheuvel:
(https://lore.kernel.org/r/[email protected]):
- Reduced scope to just SHA-512
- Added comment that explains why "sha3" is used instead of "sha2"

---

This patch is targeting libcrypto-next

 lib/crypto/arm64/sha512-ce-core.S | 27 +++++++--------------------
 1 file changed, 7 insertions(+), 20 deletions(-)
lib/crypto/arm64/sha512-ce-core.S +7 -20
index 7d870a435ea38..eaa485244af52 100644
@@ -10,30 +10,17 @@
  */
 
 #include <linux/linkage.h>
 #include <asm/assembler.h>
 
-	.irp		b,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
-	.set		.Lq\b, \b
-	.set		.Lv\b\().2d, \b
-	.endr
-
-	.macro		sha512h, rd, rn, rm
-	.inst		0xce608000 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-	.endm
-
-	.macro		sha512h2, rd, rn, rm
-	.inst		0xce608400 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-	.endm
-
-	.macro		sha512su0, rd, rn
-	.inst		0xcec08000 | .L\rd | (.L\rn << 5)
-	.endm
-
-	.macro		sha512su1, rd, rn, rm
-	.inst		0xce608800 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-	.endm
+	/*
+	 * While SHA-512 is part of the SHA-2 family of algorithms, the
+	 * corresponding arm64 instructions are actually part of the "sha3" CPU
+	 * feature.  (Except in binutils 2.30 through 2.42, which used "sha2".
+	 * But "sha3" implies "sha2", so "sha3" still works in those versions.)
+	 */
+	.arch		armv8-a+sha3
 
 	/*
 	 * The SHA-512 round constants
 	 */
 	.section	".rodata", "a"

base-commit: 66be847cc4c2e82fb50190b52b05b3bb0ef57999

Signature · 1 line
2.50.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Eric Biggers

Now that the oldest supported binutils version is 2.30, the macros that emit the SHA-512 instructions as '.inst' words are no longer needed. So drop them. No change in the generated machine code.

Changed from the original patch by Ard Biesheuvel:
(https://lore.kernel.org/r/[email protected]):
- Reduced scope to just SHA-512
- Added comment that explains why "sha3" is used instead of "sha2"

Nit below

Quoted 31 lines

---

This patch is targeting libcrypto-next

 lib/crypto/arm64/sha512-ce-core.S | 27 +++++++--------------------
 1 file changed, 7 insertions(+), 20 deletions(-)
lib/crypto/arm64/sha512-ce-core.S +0 -14
index 7d870a435ea38..eaa485244af52 100644
@@ -10,30 +10,17 @@
  */
 
 #include <linux/linkage.h>
 #include <asm/assembler.h>
 
-       .irp            b,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
-       .set            .Lq\b, \b
-       .set            .Lv\b\().2d, \b
-       .endr
-
-       .macro          sha512h, rd, rn, rm
-       .inst           0xce608000 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-       .endm
-
-       .macro          sha512h2, rd, rn, rm
-       .inst           0xce608400 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-       .endm
-
-       .macro          sha512su0, rd, rn

lib/crypto/arm64/sha512-ce-core.S line 18

Quoted 10 lines
lib/crypto/arm64/sha512-ce-core.S +4 -6
-       .inst           0xcec08000 | .L\rd | (.L\rn << 5)
-       .endm
-
-       .macro          sha512su1, rd, rn, rm
-       .inst           0xce608800 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-       .endm
+       /*
+        * While SHA-512 is part of the SHA-2 family of algorithms, the
+        * corresponding arm64 instructions are actually part of the "sha3" CPU
+        * feature.  (Except in binutils 2.30 through 2.42, which used "sha2".

Nit: the ARM ARM describes these features as FEAT_SHA256, FEAT_SHA512 and FEAT_SHA3, and the latter two happen to have appeared in the same architecture revision. So this is likely just the GCC/binutils devs getting confused, and assuming a) that SHA-3 implies SHA-2 (which is silly if you know the difference) and b) SHA512 has anything to do with SHA-3.

Quoted 13 lines
lib/crypto/arm64/sha512-ce-core.S +3 -0
+        * But "sha3" implies "sha2", so "sha3" still works in those versions.)
+        */
+       .arch           armv8-a+sha3
 
        /*
         * The SHA-512 round constants
         */
        .section        ".rodata", "a"

base-commit: 66be847cc4c2e82fb50190b52b05b3bb0ef57999 --
2.50.1

author maintainer
#2 lore raw
Quoted 57 lines · Ard Biesheuvel
Quoted 11 lines · Eric Biggers

Now that the oldest supported binutils version is 2.30, the macros that emit the SHA-512 instructions as '.inst' words are no longer needed. So drop them. No change in the generated machine code.

Changed from the original patch by Ard Biesheuvel:
(https://lore.kernel.org/r/[email protected]):
- Reduced scope to just SHA-512
- Added comment that explains why "sha3" is used instead of "sha2"

Nit below

Quoted 40 lines

---

This patch is targeting libcrypto-next

 lib/crypto/arm64/sha512-ce-core.S | 27 +++++++--------------------
 1 file changed, 7 insertions(+), 20 deletions(-)
lib/crypto/arm64/sha512-ce-core.S +3 -20
index 7d870a435ea38..eaa485244af52 100644
@@ -10,30 +10,17 @@
  */
 
 #include <linux/linkage.h>
 #include <asm/assembler.h>
 
-       .irp            b,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
-       .set            .Lq\b, \b
-       .set            .Lv\b\().2d, \b
-       .endr
-
-       .macro          sha512h, rd, rn, rm
-       .inst           0xce608000 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-       .endm
-
-       .macro          sha512h2, rd, rn, rm
-       .inst           0xce608400 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-       .endm
-
-       .macro          sha512su0, rd, rn
-       .inst           0xcec08000 | .L\rd | (.L\rn << 5)
-       .endm
-
-       .macro          sha512su1, rd, rn, rm
-       .inst           0xce608800 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-       .endm
+       /*
+        * While SHA-512 is part of the SHA-2 family of algorithms, the
+        * corresponding arm64 instructions are actually part of the "sha3" CPU
Quoted 8 lines

lib/crypto/arm64/sha512-ce-core.S line 18

Quoted 1 line
lib/crypto/arm64/sha512-ce-core.S +1 -0
+        * feature.  (Except in binutils 2.30 through 2.42, which used "sha2".

Nit: the ARM ARM describes these features as FEAT_SHA256, FEAT_SHA512 and FEAT_SHA3, and the latter two happen to have appeared in the same architecture revision. So this is likely just the GCC/binutils devs getting confused, and assuming a) that SHA-3 implies SHA-2 (which is silly if you know the difference) and b) SHA512 has anything to do with SHA-3.

How does the following look?

/*
* We have to specify the "sha3" feature here, since the GNU and clang
* assemblers both consider the SHA-512 instructions to be part of the
* "sha3" feature. (Except binutils 2.30 through 2.42, which used
* "sha2". But "sha3" implies "sha2", so "sha3" still works in those
* versions.) "sha3" doesn't make a lot of sense, since SHA-512 is part
* of the SHA-2 family of algorithms, and also the Arm Architecture
* Reference Manual defines FEAT_SHA512 and FEAT_SHA3 separately.
* Regardless, we must use "sha3" to be compatible with the assemblers. */

By the way, the ARM ARM does actually have the following:

If FEAT_SHA256 is implemented, then FEAT_SHA1 is implemented.
If FEAT_SHA512 is implemented, then FEAT_SHA256 and FEAT_SHA1 are implemented. If FEAT_SHA3 is implemented, then FEAT_SHA256 and FEAT_SHA1 are implemented.

So some of the SHAs do imply other ones. But notably absent is FEAT_SHA3 implying FEAT_SHA512...

- Eric

maintainer
#3 lore raw
Quoted 70 lines · Eric Biggers
Quoted 57 lines · Ard Biesheuvel
Quoted 11 lines · Eric Biggers

Now that the oldest supported binutils version is 2.30, the macros that emit the SHA-512 instructions as '.inst' words are no longer needed. So drop them. No change in the generated machine code.

Changed from the original patch by Ard Biesheuvel:
(https://lore.kernel.org/r/[email protected]):
- Reduced scope to just SHA-512
- Added comment that explains why "sha3" is used instead of "sha2"

Nit below

Quoted 40 lines

---

This patch is targeting libcrypto-next

 lib/crypto/arm64/sha512-ce-core.S | 27 +++++++--------------------
 1 file changed, 7 insertions(+), 20 deletions(-)
lib/crypto/arm64/sha512-ce-core.S +3 -20
index 7d870a435ea38..eaa485244af52 100644
@@ -10,30 +10,17 @@
  */
 
 #include <linux/linkage.h>
 #include <asm/assembler.h>
 
-       .irp            b,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
-       .set            .Lq\b, \b
-       .set            .Lv\b\().2d, \b
-       .endr
-
-       .macro          sha512h, rd, rn, rm
-       .inst           0xce608000 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-       .endm
-
-       .macro          sha512h2, rd, rn, rm
-       .inst           0xce608400 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-       .endm
-
-       .macro          sha512su0, rd, rn
-       .inst           0xcec08000 | .L\rd | (.L\rn << 5)
-       .endm
-
-       .macro          sha512su1, rd, rn, rm
-       .inst           0xce608800 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
-       .endm
+       /*
+        * While SHA-512 is part of the SHA-2 family of algorithms, the
+        * corresponding arm64 instructions are actually part of the "sha3" CPU
Quoted 8 lines

lib/crypto/arm64/sha512-ce-core.S line 18

Quoted 1 line
lib/crypto/arm64/sha512-ce-core.S +1 -0
+        * feature.  (Except in binutils 2.30 through 2.42, which used "sha2".

Nit: the ARM ARM describes these features as FEAT_SHA256, FEAT_SHA512 and FEAT_SHA3, and the latter two happen to have appeared in the same architecture revision. So this is likely just the GCC/binutils devs getting confused, and assuming a) that SHA-3 implies SHA-2 (which is silly if you know the difference) and b) SHA512 has anything to do with SHA-3.

How does the following look?

Quoted 11 lines

/*
* We have to specify the "sha3" feature here, since the GNU and clang
* assemblers both consider the SHA-512 instructions to be part of the
* "sha3" feature. (Except binutils 2.30 through 2.42, which used
* "sha2". But "sha3" implies "sha2", so "sha3" still works in those
* versions.) "sha3" doesn't make a lot of sense, since SHA-512 is part
* of the SHA-2 family of algorithms, and also the Arm Architecture
* Reference Manual defines FEAT_SHA512 and FEAT_SHA3 separately.
* Regardless, we must use "sha3" to be compatible with the assemblers. */

LGTM

Quoted 8 lines

By the way, the ARM ARM does actually have the following:

If FEAT_SHA256 is implemented, then FEAT_SHA1 is implemented.
If FEAT_SHA512 is implemented, then FEAT_SHA256 and FEAT_SHA1 are implemented. If FEAT_SHA3 is implemented, then FEAT_SHA256 and FEAT_SHA1 are implemented.

So some of the SHAs do imply other ones. But notably absent is FEAT_SHA3 implying FEAT_SHA512...

Yeah, and such policies usually evaporate into thin air as soon as Apple decides to implement something different, so they tend to be rather meaningless. (E.g, FEAT_SME used to imply FEAT_SVE but it no longer does)