From 7ae2bc9df6e0916a8f16183f07dfa1815dd4b66d Mon Sep 17 00:00:00 2001 From: "Hongren (Zenithal) Zheng" Date: Wed, 11 May 2022 16:11:18 +0800 Subject: [PATCH] Add SM3 implementation in RISC-V Zksh asm This works for both RV32 and RV64 Signed-off-by: Hongren (Zenithal) Zheng Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/18287) --- crypto/sm3/sm3_local.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/crypto/sm3/sm3_local.h b/crypto/sm3/sm3_local.h index c5e63bcf105..48ec9ae90bb 100644 --- a/crypto/sm3/sm3_local.h +++ b/crypto/sm3/sm3_local.h @@ -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) -- 2.47.2