Add SM3 implementation in RISC-V Zksh asm

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)
This commit is contained in:
Hongren (Zenithal) Zheng 2022-05-11 16:11:18 +08:00 committed by Tomas Mraz
parent 5317b6ee1f
commit 7ae2bc9df6
1 changed files with 22 additions and 2 deletions

View 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)