Skip to content

Commit

Permalink
Thumb-2 ChaCha, Poly1305: implemention in assembly
Browse files Browse the repository at this point in the history
Implementation of ChaCha algorithm for ARM Thumb-2.
Implementation of Poly1305 algorithm for ARM Thumb-2.
  • Loading branch information
SparkiDev committed Sep 12, 2024
1 parent 5f40f9a commit 27033c2
Show file tree
Hide file tree
Showing 9 changed files with 1,017 additions and 50 deletions.
6 changes: 6 additions & 0 deletions src/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,12 @@ if !BUILD_FIPS_RAND
if BUILD_POLY1305
if BUILD_ARMASM
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-poly1305.c
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-poly1305.c
if BUILD_ARMASM_INLINE
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-poly1305-asm_c.c
else
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-poly1305-asm.S
endif !BUILD_ARMASM_INLINE
endif
if BUILD_RISCV_ASM
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/riscv/riscv-64-poly1305.c
Expand Down
14 changes: 8 additions & 6 deletions wolfcrypt/src/poly1305.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ extern void poly1305_final_avx2(Poly1305* ctx, byte* mac);
p[7] = (byte)(v >> 56);
}
#endif/* !WOLFSSL_ARMASM && !WOLFSSL_RISCV_ASM */
#else /* if not 64 bit then use 32 bit */
/* if not 64 bit then use 32 bit */
#elif !defined(WOLFSSL_ARMASM) || !defined(__thumb__)

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


#if (!defined(WOLFSSL_ARMASM) || !defined(__aarch64__)) && \
!defined(WOLFSSL_RISCV_ASM)
#if (!defined(WOLFSSL_ARMASM) || (!defined(__aarch64__) && \
!defined(__thumb__))) && !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 @@ -788,7 +789,8 @@ int wc_Poly1305Final(Poly1305* ctx, byte* mac)

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


int wc_Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes)
Expand Down Expand Up @@ -883,8 +885,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__)) && \
!defined(WOLFSSL_RISCV_ASM)
#if (!defined(WOLFSSL_ARMASM) || (!defined(__aarch64__) && \
!defined(__thumb__))) && !defined(WOLFSSL_RISCV_ASM)
int ret;
ret = poly1305_blocks(ctx, m, want);
if (ret != 0)
Expand Down
9 changes: 0 additions & 9 deletions wolfcrypt/src/port/arm/thumb2-chacha.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
#endif


extern void wc_chacha_setiv(word32* x, const byte* iv, word32 counter);

/* Set the Initialization Vector (IV) and counter into ChaCha context.
*
* Set up iv(nonce). Earlier versions used 64 bits instead of 96, this version
Expand Down Expand Up @@ -92,8 +90,6 @@ int wc_Chacha_SetIV(ChaCha* ctx, const byte* iv, word32 counter)
return ret;
}

extern void wc_chacha_setkey(word32* x, const byte* key, word32 keySz);

/* Set the key into the ChaCha context.
*
* Key setup. 8 word iv (nonce)
Expand Down Expand Up @@ -141,11 +137,6 @@ int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz)
return ret;
}

extern void wc_chacha_use_over(byte* over, byte* output, const byte* input,
word32 len);
extern void wc_chacha_crypt_bytes(ChaCha* ctx, byte* c, const byte* m,
word32 len);

/* API to encrypt/decrypt a message of any size.
*
* @param [in] ctx ChaCha context.
Expand Down
Loading

0 comments on commit 27033c2

Please sign in to comment.