Skip to content

Commit

Permalink
Merge pull request #7873 from SparkiDev/riscv-poly1305-asm
Browse files Browse the repository at this point in the history
RISC-V 64 ASM: Add Poly1305 implementation
  • Loading branch information
dgarske authored Aug 15, 2024
2 parents ccd8b9a + 3ade7a8 commit 1190d1b
Show file tree
Hide file tree
Showing 6 changed files with 744 additions and 23 deletions.
28 changes: 16 additions & 12 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3066,12 +3066,6 @@ do
;;
no)
;;
zbkb)
# PACK, REV8
ENABLED_RISCV_ASM=yes
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_BIT_MANIPULATION"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_BASE_BIT_MANIPULATION"
;;
zbb)
# REV8
ENABLED_RISCV_ASM=yes
Expand All @@ -3082,6 +3076,16 @@ do
ENABLED_RISCV_ASM=yes
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_CARRYLESS"
;;
zbkb)
# PACK, REV8
ENABLED_RISCV_ASM=yes
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_BIT_MANIPULATION"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_BASE_BIT_MANIPULATION"
;;
zbt)
# FSL, FSR, FSRI, CMOV, CMIX - QEMU doesn't know about these instructions
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_BIT_MANIPULATION_TERNARY"
;;
zkn|zkned)
# AES encrypt/decrpyt, SHA-2
ENABLED_RISCV_ASM=yes
Expand All @@ -3091,20 +3095,20 @@ do
ENABLED_RISCV_ASM=yes
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR"
;;
zvkg)
# VGMUL, VHHSH
zvbb|zvkb)
# VBREV8
ENABLED_RISCV_ASM=yes
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR_GCM"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR_BASE_BIT_MANIPULATION"
;;
zvbc)
# VCLMUL, VCLMULH
ENABLED_RISCV_ASM=yes
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR_CARRYLESS"
;;
zvbb|zvkb)
# VBREV8
zvkg)
# VGMUL, VHHSH
ENABLED_RISCV_ASM=yes
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR_BASE_BIT_MANIPULATION"
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_RISCV_VECTOR_GCM"
;;
zvkned)
# Vector AES, SHA-2
Expand Down
3 changes: 3 additions & 0 deletions src/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,9 @@ if BUILD_POLY1305
if BUILD_ARMASM
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-poly1305.c
endif
if BUILD_RISCV_ASM
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/riscv/riscv-64-poly1305.c
endif
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/poly1305.c
if !BUILD_X86_ASM
if BUILD_INTELASM
Expand Down
14 changes: 7 additions & 7 deletions wolfcrypt/src/poly1305.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ extern void poly1305_final_avx2(Poly1305* ctx, byte* mac);
#endif

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

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


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

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

return 0;
}
#endif /* !defined(WOLFSSL_ARMASM) || !defined(__aarch64__) */
#endif /* (!WOLFSSL_ARMASM || !__aarch64__) && !WOLFSSL_RISCV_ASM */


int wc_Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes)
Expand Down Expand Up @@ -884,7 +883,8 @@ int wc_Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes)
/* process full blocks */
if (bytes >= POLY1305_BLOCK_SIZE) {
size_t want = ((size_t)bytes & ~((size_t)POLY1305_BLOCK_SIZE - 1));
#if !defined(WOLFSSL_ARMASM) || !defined(__aarch64__)
#if (!defined(WOLFSSL_ARMASM) || !defined(__aarch64__)) && \
!defined(WOLFSSL_RISCV_ASM)
int ret;
ret = poly1305_blocks(ctx, m, want);
if (ret != 0)
Expand Down
Loading

0 comments on commit 1190d1b

Please sign in to comment.