Skip to content

Commit 4062b94

Browse files
committed
RISC-V 64: Add assembly code for SHA-512
Cleanup RISC-V 64 SHA-256 by removing unused rev_idx.
1 parent 9aa0742 commit 4062b94

5 files changed

Lines changed: 1743 additions & 15 deletions

File tree

src/include.am

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/riscv/riscv-64-sha256
234234
endif BUILD_RISCV_ASM
235235

236236
if BUILD_SHA512
237+
if BUILD_RISCV_ASM
238+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/riscv/riscv-64-sha512.c
239+
else
237240
if BUILD_ARMASM_NEON
238241
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-sha512.c
239242
if BUILD_ARMASM_INLINE
@@ -262,6 +265,7 @@ endif BUILD_INTELASM
262265
endif !BUILD_X86_ASM
263266
endif !BUILD_ARMASM
264267
endif !BUILD_ARMASM_NEON
268+
endif !BUILD_RISCV_ASM
265269
endif BUILD_SHA512
266270

267271
if BUILD_SHA3
@@ -393,6 +397,9 @@ src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/riscv/riscv-64-sha256
393397
endif BUILD_RISCV_ASM
394398

395399
if BUILD_SHA512
400+
if BUILD_RISCV_ASM
401+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/riscv/riscv-64-sha512.c
402+
else
396403
if BUILD_ARMASM_NEON
397404
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-sha512.c
398405
if BUILD_ARMASM_INLINE
@@ -419,6 +426,7 @@ src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sha512_asm.S
419426
endif BUILD_INTELASM
420427
endif !BUILD_ARMASM
421428
endif !BUILD_ARMASM_NEON
429+
endif !BUILD_RISCV_ASM
422430
endif BUILD_SHA512
423431

424432
if BUILD_SHA3
@@ -738,6 +746,9 @@ endif !BUILD_FIPS_CURRENT
738746

739747
if !BUILD_FIPS_CURRENT
740748
if BUILD_SHA512
749+
if BUILD_RISCV_ASM
750+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/riscv/riscv-64-sha512.c
751+
else
741752
if BUILD_ARMASM_NEON
742753
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-sha512.c
743754
if BUILD_ARMASM_INLINE
@@ -766,6 +777,7 @@ endif BUILD_INTELASM
766777
endif !BUILD_X86_ASM
767778
endif !BUILD_ARMASM
768779
endif !BUILD_ARMASM_NEON
780+
endif !BUILD_RISCV_ASM
769781
endif BUILD_SHA512
770782
endif !BUILD_FIPS_CURRENT
771783

wolfcrypt/src/port/riscv/riscv-64-sha256.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,6 @@ static WC_INLINE void Sha256Transform(wc_Sha256* sha256, const byte* data,
600600
(0b010 << 12) | (0b1110111 << 0) | \
601601
(vd << 7) | (vs1 << 15) | (vs2 << 20))
602602

603-
#ifndef WOLFSSL_RISCV_VECTOR_BASE_BIT_MANIPULATION
604-
/* Indecies to use with gather vector instruction to reverse bytes. */
605-
static const word32 rev_idx[4] = {
606-
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f
607-
};
608-
#endif /* !WOLFSSL_RISCV_VECTOR_BASE_BIT_MANIPULATION */
609-
610603
#define RND4(w0, w1, w2, w3, k) \
611604
/* Four rounds of compression. */ \
612605
VADD_VV(REG_V7, w0, k) \
@@ -690,9 +683,6 @@ static void Sha256Transform(wc_Sha256* sha256, const byte* data,
690683

691684
: [blocks] "+r" (blocks), [data] "+r" (data), [k] "+r" (k)
692685
: [digest] "r" (sha256->digest)
693-
#ifndef WOLFSSL_RISCV_VECTOR_BASE_BIT_MANIPULATION
694-
, [rev_idx] "r" (rev_idx)
695-
#endif
696686
: "cc", "memory", "t0", "t1"
697687
);
698688
}
@@ -884,10 +874,6 @@ static WC_INLINE void Sha256Final(wc_Sha256* sha256, byte* hash)
884874
#endif
885875
:
886876
: [digest] "r" (sha256->digest), [hash] "r" (hash)
887-
#if defined(WOLFSSL_RISCV_VECTOR_CRYPTO_ASM) && \
888-
!defined(WOLFSSL_RISCV_VECTOR_BASE_BIT_MANIPULATION)
889-
, [rev_idx] "r" (rev_idx)
890-
#endif
891877
: "cc", "memory", "t0", "t1", "t2", "t3", "t4", "t5", "t6",
892878
"a4", "a5", "a6", "a7"
893879
);

0 commit comments

Comments
 (0)