From: Hongren (Zenithal) Zheng Date: Wed, 11 May 2022 09:18:27 +0000 (+0800) Subject: Add ROTATE inline asm support for SM3 X-Git-Tag: openssl-3.2.0-alpha1~2494 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eea820f3e239a4c11d618741fd5d00a6bc877347;p=thirdparty%2Fopenssl.git 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 Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/18287) --- diff --git a/crypto/sm3/sm3_local.h b/crypto/sm3/sm3_local.h index 48ec9ae90bb..cb5a187a12f 100644 --- a/crypto/sm3/sm3_local.h +++ b/crypto/sm3/sm3_local.h @@ -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 diff --git a/include/crypto/md32_common.h b/include/crypto/md32_common.h index 262dc6503fc..46214f3237c 100644 --- a/include/crypto/md32_common.h +++ b/include/crypto/md32_common.h @@ -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), \