summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorHongren (Zenithal) Zheng <i@zenithal.me>2022-05-11 17:18:27 +0800
committerTomas Mraz <tomas@openssl.org>2022-06-22 12:46:50 +0200
commiteea820f3e239a4c11d618741fd5d00a6bc877347 (patch)
tree91927cfddc327b5ad6f52924c06c62adf5a48c43 /include
parent7ae2bc9df6e0916a8f16183f07dfa1815dd4b66d (diff)
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)
Diffstat (limited to 'include')
-rw-r--r--include/crypto/md32_common.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/crypto/md32_common.h b/include/crypto/md32_common.h
index 262dc6503f..46214f3237 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), \