]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add SM3 implementation in RISC-V Zksh asm
authorHongren (Zenithal) Zheng <i@zenithal.me>
Wed, 11 May 2022 08:11:18 +0000 (16:11 +0800)
committerTomas Mraz <tomas@openssl.org>
Wed, 22 Jun 2022 10:44:57 +0000 (12:44 +0200)
This works for both RV32 and RV64

Signed-off-by: Hongren (Zenithal) Zheng <i@zenithal.me>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18287)

crypto/sm3/sm3_local.h

index c5e63bcf105aa8b547a877b954201dc8d4015e7e..48ec9ae90bb6f13485bdbcbab894b65b4073230a 100644 (file)
@@ -53,8 +53,28 @@ void ossl_sm3_transform(SM3_CTX *c, const unsigned char *data);
 
 #include "crypto/md32_common.h"
 
-#define P0(X) (X ^ ROTATE(X, 9) ^ ROTATE(X, 17))
-#define P1(X) (X ^ ROTATE(X, 15) ^ ROTATE(X, 23))
+#ifndef PEDANTIC
+# if defined(__GNUC__) && __GNUC__>=2 && \
+     !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
+#  if defined(__riscv_zksh)
+#   define P0(x) ({ MD32_REG_T ret;                \
+                       asm ("sm3p0 %0, %1"         \
+                       : "=r"(ret)                 \
+                       : "r"(x)); ret;             })
+#   define P1(x) ({ MD32_REG_T ret;                \
+                       asm ("sm3p1 %0, %1"         \
+                       : "=r"(ret)                 \
+                       : "r"(x)); ret;             })
+#  endif
+# endif
+#endif
+
+#ifndef P0
+# define P0(X) (X ^ ROTATE(X, 9) ^ ROTATE(X, 17))
+#endif
+#ifndef P1
+# define P1(X) (X ^ ROTATE(X, 15) ^ ROTATE(X, 23))
+#endif
 
 #define FF0(X,Y,Z) (X ^ Y ^ Z)
 #define GG0(X,Y,Z) (X ^ Y ^ Z)