Add ROTATE inline asm support for SM3

And move ROTATE inline asm to header.

Now this benefits SM3, SHA (when with Zbb only and no Zknh)
and other hash functions

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 17:18:27 +08:00 committed by Tomas Mraz
parent 7ae2bc9df6
commit eea820f3e2
2 changed files with 30 additions and 8 deletions

View File

@ -57,14 +57,14 @@ void ossl_sm3_transform(SM3_CTX *c, const unsigned char *data);
# 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; })
# 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

View File

@ -99,6 +99,28 @@
# define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
#ifndef PEDANTIC
# if defined(__GNUC__) && __GNUC__>=2 && \
!defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
# if defined(__riscv_zbb) || defined(__riscv_zbkb)
# if __riscv_xlen == 64
# undef ROTATE
# define ROTATE(x, n) ({ MD32_REG_T ret; \
asm ("roriw %0, %1, %2" \
: "=r"(ret) \
: "r"(x), "i"(32 - (n))); ret;})
# endif
# if __riscv_xlen == 32
# undef ROTATE
# define ROTATE(x, n) ({ MD32_REG_T ret; \
asm ("rori %0, %1, %2" \
: "=r"(ret) \
: "r"(x), "i"(32 - (n))); ret;})
# endif
# endif
# endif
#endif
# if defined(DATA_ORDER_IS_BIG_ENDIAN)
# define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \