Skip to content

Commit 1190d1b

Browse files
authored
Merge pull request #7873 from SparkiDev/riscv-poly1305-asm
RISC-V 64 ASM: Add Poly1305 implementation
2 parents ccd8b9a + 3ade7a8 commit 1190d1b

6 files changed

Lines changed: 744 additions & 23 deletions

File tree

configure.ac

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,12 +3066,6 @@ do
30663066
;;
30673067
no)
30683068
;;
3069-
zbkb)
3070-
# PACK, REV8
3071-
ENABLED_RISCV_ASM=yes
3072-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_BIT_MANIPULATION"
3073-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_BASE_BIT_MANIPULATION"
3074-
;;
30753069
zbb)
30763070
# REV8
30773071
ENABLED_RISCV_ASM=yes
@@ -3082,6 +3076,16 @@ do
30823076
ENABLED_RISCV_ASM=yes
30833077
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_CARRYLESS"
30843078
;;
3079+
zbkb)
3080+
# PACK, REV8
3081+
ENABLED_RISCV_ASM=yes
3082+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_BIT_MANIPULATION"
3083+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_BASE_BIT_MANIPULATION"
3084+
;;
3085+
zbt)
3086+
# FSL, FSR, FSRI, CMOV, CMIX - QEMU doesn't know about these instructions
3087+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_BIT_MANIPULATION_TERNARY"
3088+
;;
30853089
zkn|zkned)
30863090
# AES encrypt/decrpyt, SHA-2
30873091
ENABLED_RISCV_ASM=yes
@@ -3091,20 +3095,20 @@ do
30913095
ENABLED_RISCV_ASM=yes
30923096
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR"
30933097
;;
3094-
zvkg)
3095-
# VGMUL, VHHSH
3098+
zvbb|zvkb)
3099+
# VBREV8
30963100
ENABLED_RISCV_ASM=yes
3097-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR_GCM"
3101+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR_BASE_BIT_MANIPULATION"
30983102
;;
30993103
zvbc)
31003104
# VCLMUL, VCLMULH
31013105
ENABLED_RISCV_ASM=yes
31023106
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR_CARRYLESS"
31033107
;;
3104-
zvbb|zvkb)
3105-
# VBREV8
3108+
zvkg)
3109+
# VGMUL, VHHSH
31063110
ENABLED_RISCV_ASM=yes
3107-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR_BASE_BIT_MANIPULATION"
3111+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR_GCM"
31083112
;;
31093113
zvkned)
31103114
# Vector AES, SHA-2

src/include.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,9 @@ if BUILD_POLY1305
914914
if BUILD_ARMASM
915915
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-poly1305.c
916916
endif
917+
if BUILD_RISCV_ASM
918+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/riscv/riscv-64-poly1305.c
919+
endif
917920
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/poly1305.c
918921
if !BUILD_X86_ASM
919922
if BUILD_INTELASM

wolfcrypt/src/poly1305.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ extern void poly1305_final_avx2(Poly1305* ctx, byte* mac);
206206
#endif
207207

208208
#elif defined(POLY130564)
209-
#ifndef WOLFSSL_ARMASM
209+
#if !defined(WOLFSSL_ARMASM) && !defined(WOLFSSL_RISCV_ASM)
210210
static word64 U8TO64(const byte* p)
211211
{
212212
return
@@ -230,7 +230,7 @@ extern void poly1305_final_avx2(Poly1305* ctx, byte* mac);
230230
p[6] = (byte)(v >> 48);
231231
p[7] = (byte)(v >> 56);
232232
}
233-
#endif/* WOLFSSL_ARMASM */
233+
#endif/* !WOLFSSL_ARMASM && !WOLFSSL_RISCV_ASM */
234234
#else /* if not 64 bit then use 32 bit */
235235

236236
static word32 U8TO32(const byte *p)
@@ -268,7 +268,8 @@ static WC_INLINE void u32tole64(const word32 inLe32, byte outLe64[8])
268268
}
269269

270270

271-
#if !defined(WOLFSSL_ARMASM) || !defined(__aarch64__)
271+
#if (!defined(WOLFSSL_ARMASM) || !defined(__aarch64__)) && \
272+
!defined(WOLFSSL_RISCV_ASM)
272273
/*
273274
This local function operates on a message with a given number of bytes
274275
with a given ctx pointer to a Poly1305 structure.
@@ -491,9 +492,7 @@ static int poly1305_block(Poly1305* ctx, const unsigned char *m)
491492
return poly1305_blocks(ctx, m, POLY1305_BLOCK_SIZE);
492493
#endif
493494
}
494-
#endif /* !defined(WOLFSSL_ARMASM) || !defined(__aarch64__) */
495495

496-
#if !defined(WOLFSSL_ARMASM) || !defined(__aarch64__)
497496
int wc_Poly1305SetKey(Poly1305* ctx, const byte* key, word32 keySz)
498497
{
499498
#if defined(POLY130564) && !defined(USE_INTEL_POLY1305_SPEEDUP)
@@ -789,7 +788,7 @@ int wc_Poly1305Final(Poly1305* ctx, byte* mac)
789788

790789
return 0;
791790
}
792-
#endif /* !defined(WOLFSSL_ARMASM) || !defined(__aarch64__) */
791+
#endif /* (!WOLFSSL_ARMASM || !__aarch64__) && !WOLFSSL_RISCV_ASM */
793792

794793

795794
int wc_Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes)
@@ -884,7 +883,8 @@ int wc_Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes)
884883
/* process full blocks */
885884
if (bytes >= POLY1305_BLOCK_SIZE) {
886885
size_t want = ((size_t)bytes & ~((size_t)POLY1305_BLOCK_SIZE - 1));
887-
#if !defined(WOLFSSL_ARMASM) || !defined(__aarch64__)
886+
#if (!defined(WOLFSSL_ARMASM) || !defined(__aarch64__)) && \
887+
!defined(WOLFSSL_RISCV_ASM)
888888
int ret;
889889
ret = poly1305_blocks(ctx, m, want);
890890
if (ret != 0)

0 commit comments

Comments
 (0)