[PATCH 02/11] sm4-aarch64-sve: clear volatile vectors registers

Jussi Kivilinna jussi.kivilinna at iki.fi
Sun Nov 3 20:56:46 CET 2024


* cipher/asm-common-aarch64.h (CLEAR_ALL_REGS): New.
* cipher/sm4-armv9-aarch64-sve-ce.S
(_gcry_sm4_armv9_sve_ce_cbc_dec, _gcry_sm4_armv9_sve_ce_cfb_dec)
(_gcry_sm4_armv9_sve_ce_ctr_enc): Add CLEAR_ALL_REGS.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 cipher/asm-common-aarch64.h       | 9 +++++++++
 cipher/sm4-armv9-aarch64-sve-ce.S | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/cipher/asm-common-aarch64.h b/cipher/asm-common-aarch64.h
index ff65ea6a..dde7366c 100644
--- a/cipher/asm-common-aarch64.h
+++ b/cipher/asm-common-aarch64.h
@@ -125,6 +125,15 @@
 
 #define CLEAR_REG(reg) movi reg.16b, #0;
 
+#define CLEAR_ALL_REGS() \
+	CLEAR_REG(v0); CLEAR_REG(v1); CLEAR_REG(v2); CLEAR_REG(v3); \
+	CLEAR_REG(v4); CLEAR_REG(v5); CLEAR_REG(v6); \
+	/* v8-v15 are ABI callee saved. */ \
+	CLEAR_REG(v16); CLEAR_REG(v17); CLEAR_REG(v18); CLEAR_REG(v19); \
+	CLEAR_REG(v20); CLEAR_REG(v21); CLEAR_REG(v22); CLEAR_REG(v23); \
+	CLEAR_REG(v24); CLEAR_REG(v25); CLEAR_REG(v26); CLEAR_REG(v27); \
+	CLEAR_REG(v28); CLEAR_REG(v29); CLEAR_REG(v30); CLEAR_REG(v31);
+
 #define VPUSH_ABI \
 	stp d8, d9, [sp, #-16]!; \
 	CFI_ADJUST_CFA_OFFSET(16); \
diff --git a/cipher/sm4-armv9-aarch64-sve-ce.S b/cipher/sm4-armv9-aarch64-sve-ce.S
index cdf20719..7367cd28 100644
--- a/cipher/sm4-armv9-aarch64-sve-ce.S
+++ b/cipher/sm4-armv9-aarch64-sve-ce.S
@@ -618,6 +618,7 @@ _gcry_sm4_armv9_sve_ce_cbc_dec:
     st1         {RIVv.16b}, [x3];
 
     VPOP_ABI;
+    CLEAR_ALL_REGS();
     ret_spec_stop;
     CFI_ENDPROC();
 ELF(.size _gcry_sm4_armv9_sve_ce_cbc_dec,.-_gcry_sm4_armv9_sve_ce_cbc_dec;)
@@ -792,6 +793,7 @@ _gcry_sm4_armv9_sve_ce_cfb_dec:
     st1         {RIVv.16b}, [x3];
 
     VPOP_ABI;
+    CLEAR_ALL_REGS();
     ret_spec_stop;
     CFI_ENDPROC();
 ELF(.size _gcry_sm4_armv9_sve_ce_cfb_dec,.-_gcry_sm4_armv9_sve_ce_cfb_dec;)
@@ -948,6 +950,7 @@ _gcry_sm4_armv9_sve_ce_ctr_enc:
     rev x8, x8;
     stp x7, x8, [x3];
 
+    CLEAR_ALL_REGS();
     ret_spec_stop;
     CFI_ENDPROC();
 ELF(.size _gcry_sm4_armv9_sve_ce_ctr_enc,.-_gcry_sm4_armv9_sve_ce_ctr_enc;)
-- 
2.45.2




More information about the Gcrypt-devel mailing list