summaryrefslogtreecommitdiffstats
path: root/crypto/sha
diff options
context:
space:
mode:
authorMark Fedorov <mark.fedorov@cloudbear.ru>2021-09-29 20:49:59 +0300
committerTomas Mraz <tomas@openssl.org>2022-11-21 10:49:52 +0100
commit45e16e9e45dee677e0daa9f6832b5ae605c1eab4 (patch)
tree72935ffda1735ade55f323e89a4882aa8306e032 /crypto/sha
parentc606775c4e402561aa037155fd1a1a3baf6b4318 (diff)
RISC-V support for the SHA256
Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/16710) (cherry picked from commit 657d1927c68bdc3fb0250d16df2a8439e8e043f1)
Diffstat (limited to 'crypto/sha')
-rw-r--r--crypto/sha/sha256.c59
1 files changed, 52 insertions, 7 deletions
diff --git a/crypto/sha/sha256.c b/crypto/sha/sha256.c
index 5845c38937..89beaf1479 100644
--- a/crypto/sha/sha256.c
+++ b/crypto/sha/sha256.c
@@ -129,18 +129,63 @@ static const SHA_LONG K256[64] = {
0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
};
+# ifndef PEDANTIC
+# if defined(__GNUC__) && __GNUC__>=2 && \
+ !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
+# if __riscv_zknh
+# define Sigma0(x) ({ MD32_REG_T ret; \
+ asm ("sha256sum0 %0, %1" \
+ : "=r"(ret) \
+ : "r"(x)); ret; })
+# define Sigma1(x) ({ MD32_REG_T ret; \
+ asm ("sha256sum1 %0, %1" \
+ : "=r"(ret) \
+ : "r"(x)); ret; })
+# define sigma0(x) ({ MD32_REG_T ret; \
+ asm ("sha256sig0 %0, %1" \
+ : "=r"(ret) \
+ : "r"(x)); ret; })
+# define sigma1(x) ({ MD32_REG_T ret; \
+ asm ("sha256sig1 %0, %1" \
+ : "=r"(ret) \
+ : "r"(x)); ret; })
+# endif
+# if __riscv_zbt || __riscv_zpn
+# define Ch(x,y,z) ({ MD32_REG_T ret; \
+ asm (".insn r4 0x33, 1, 0x3, %0, %2, %1, %3"\
+ : "=r"(ret) \
+ : "r"(x), "r"(y), "r"(z)); ret; })
+# define Maj(x,y,z) ({ MD32_REG_T ret; \
+ asm (".insn r4 0x33, 1, 0x3, %0, %2, %1, %3"\
+ : "=r"(ret) \
+ : "r"(x^z), "r"(y), "r"(x)); ret; })
+# endif
+# endif
+# endif
+
/*
* FIPS specification refers to right rotations, while our ROTATE macro
* is left one. This is why you might notice that rotation coefficients
* differ from those observed in FIPS document by 32-N...
*/
-# define Sigma0(x) (ROTATE((x),30) ^ ROTATE((x),19) ^ ROTATE((x),10))
-# define Sigma1(x) (ROTATE((x),26) ^ ROTATE((x),21) ^ ROTATE((x),7))
-# define sigma0(x) (ROTATE((x),25) ^ ROTATE((x),14) ^ ((x)>>3))
-# define sigma1(x) (ROTATE((x),15) ^ ROTATE((x),13) ^ ((x)>>10))
-
-# define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
-# define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+# ifndef Sigma0
+# define Sigma0(x) (ROTATE((x),30) ^ ROTATE((x),19) ^ ROTATE((x),10))
+# endif
+# ifndef Sigma1
+# define Sigma1(x) (ROTATE((x),26) ^ ROTATE((x),21) ^ ROTATE((x),7))
+# endif
+# ifndef sigma0
+# define sigma0(x) (ROTATE((x),25) ^ ROTATE((x),14) ^ ((x)>>3))
+# endif
+# ifndef sigma1
+# define sigma1(x) (ROTATE((x),15) ^ ROTATE((x),13) ^ ((x)>>10))
+# endif
+# ifndef Ch
+# define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
+# endif
+# ifndef Maj
+# define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+# endif
# ifdef OPENSSL_SMALL_FOOTPRINT