* [PATCH] lib/crypto: arm64/sm3: Use assembler for sm3 instructions
@ 2026-11-14 21:10 Eric Biggers
0 siblings, 0 replies; only message in thread
From: Eric Biggers @ 2026-11-14 21:10 UTC (permalink / raw)
To: linux-crypto
Cc: Ard Biesheuvel, Jason A . Donenfeld, Herbert Xu, linux-arm-kernel,
Emanuele Rocca, Eric Biggers
All supported assemblers (binutils 2.30 and later, and clang 17.0.1 and
later) support the sm3 instructions now.
Therefore, drop the use of '.inst' in sm3-ce-core.S and just have the
assembler generate the instructions.
This requires adding '.arch armv8.2-a+sm4'. (Yes, the assemblers want
sm4, not sm3.) I also tried just '.arch_extension sm4', but that
doesn't work with binutils 2.40 and earlier because they consider sm3 to
depend on armv8.2-a or later (and this file isn't built with
-march=armv8.2-a or later). This was fixed in binutils 2.41 commit
205e4380c800, but the kernel currently supports binutils 2.30 and later.
No change in the resulting .text section with either binutils or clang.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
This patch is intended to be taken through libcrypto-next
lib/crypto/arm64/sm3-ce-core.S | 41 +++++++---------------------------
1 file changed, 8 insertions(+), 33 deletions(-)
diff --git a/lib/crypto/arm64/sm3-ce-core.S b/lib/crypto/arm64/sm3-ce-core.S
index ee7f900d7cff7..91eee7d760f93 100644
--- a/lib/crypto/arm64/sm3-ce-core.S
+++ b/lib/crypto/arm64/sm3-ce-core.S
@@ -8,44 +8,19 @@
#include <linux/linkage.h>
#include <asm/assembler.h>
- .irp b, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
- .set .Lv\b\().4s, \b
- .endr
-
- .macro sm3partw1, rd, rn, rm
- .inst 0xce60c000 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
- .endm
-
- .macro sm3partw2, rd, rn, rm
- .inst 0xce60c400 | .L\rd | (.L\rn << 5) | (.L\rm << 16)
- .endm
-
- .macro sm3ss1, rd, rn, rm, ra
- .inst 0xce400000 | .L\rd | (.L\rn << 5) | (.L\ra << 10) | (.L\rm << 16)
- .endm
-
- .macro sm3tt1a, rd, rn, rm, imm2
- .inst 0xce408000 | .L\rd | (.L\rn << 5) | ((\imm2) << 12) | (.L\rm << 16)
- .endm
-
- .macro sm3tt1b, rd, rn, rm, imm2
- .inst 0xce408400 | .L\rd | (.L\rn << 5) | ((\imm2) << 12) | (.L\rm << 16)
- .endm
-
- .macro sm3tt2a, rd, rn, rm, imm2
- .inst 0xce408800 | .L\rd | (.L\rn << 5) | ((\imm2) << 12) | (.L\rm << 16)
- .endm
-
- .macro sm3tt2b, rd, rn, rm, imm2
- .inst 0xce408c00 | .L\rd | (.L\rn << 5) | ((\imm2) << 12) | (.L\rm << 16)
- .endm
+ /*
+ * The assemblers group the sm3 and sm4 instructions under the sm4
+ * feature. So we need to request sm4, despite this file being sm3.
+ * In binutils 2.40 and earlier, armv8.2 or later is also required.
+ */
+ .arch armv8.2-a+sm4
.macro round, ab, s0, t0, t1, i
sm3ss1 v5.4s, v8.4s, \t0\().4s, v9.4s
shl \t1\().4s, \t0\().4s, #1
sri \t1\().4s, \t0\().4s, #31
- sm3tt1\ab v8.4s, v5.4s, v10.4s, \i
- sm3tt2\ab v9.4s, v5.4s, \s0\().4s, \i
+ sm3tt1\ab v8.4s, v5.4s, v10.s[\i]
+ sm3tt2\ab v9.4s, v5.4s, \s0\().s[\i]
.endm
.macro qround, ab, s0, s1, s2, s3, s4
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.56.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-14 21:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-14 21:10 [PATCH] lib/crypto: arm64/sm3: Use assembler for sm3 instructions Eric Biggers
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.