Skip to content

Commit 27033c2

Browse files
committed
Thumb-2 ChaCha, Poly1305: implemention in assembly
Implementation of ChaCha algorithm for ARM Thumb-2. Implementation of Poly1305 algorithm for ARM Thumb-2.
1 parent 5f40f9a commit 27033c2

9 files changed

Lines changed: 1017 additions & 50 deletions

File tree

src/include.am

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,12 @@ if !BUILD_FIPS_RAND
922922
if BUILD_POLY1305
923923
if BUILD_ARMASM
924924
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/armv8-poly1305.c
925+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-poly1305.c
926+
if BUILD_ARMASM_INLINE
927+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-poly1305-asm_c.c
928+
else
929+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/arm/thumb2-poly1305-asm.S
930+
endif !BUILD_ARMASM_INLINE
925931
endif
926932
if BUILD_RISCV_ASM
927933
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/riscv/riscv-64-poly1305.c

wolfcrypt/src/poly1305.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ extern void poly1305_final_avx2(Poly1305* ctx, byte* mac);
231231
p[7] = (byte)(v >> 56);
232232
}
233233
#endif/* !WOLFSSL_ARMASM && !WOLFSSL_RISCV_ASM */
234-
#else /* if not 64 bit then use 32 bit */
234+
/* if not 64 bit then use 32 bit */
235+
#elif !defined(WOLFSSL_ARMASM) || !defined(__thumb__)
235236

236237
static word32 U8TO32(const byte *p)
237238
{
@@ -268,8 +269,8 @@ static WC_INLINE void u32tole64(const word32 inLe32, byte outLe64[8])
268269
}
269270

270271

271-
#if (!defined(WOLFSSL_ARMASM) || !defined(__aarch64__)) && \
272-
!defined(WOLFSSL_RISCV_ASM)
272+
#if (!defined(WOLFSSL_ARMASM) || (!defined(__aarch64__) && \
273+
!defined(__thumb__))) && !defined(WOLFSSL_RISCV_ASM)
273274
/*
274275
This local function operates on a message with a given number of bytes
275276
with a given ctx pointer to a Poly1305 structure.
@@ -788,7 +789,8 @@ int wc_Poly1305Final(Poly1305* ctx, byte* mac)
788789

789790
return 0;
790791
}
791-
#endif /* (!WOLFSSL_ARMASM || !__aarch64__) && !WOLFSSL_RISCV_ASM */
792+
#endif /* (!WOLFSSL_ARMASM || (!__aarch64__ && !__thumb__)) &&
793+
* !WOLFSSL_RISCV_ASM */
792794

793795

794796
int wc_Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes)
@@ -883,8 +885,8 @@ int wc_Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes)
883885
/* process full blocks */
884886
if (bytes >= POLY1305_BLOCK_SIZE) {
885887
size_t want = ((size_t)bytes & ~((size_t)POLY1305_BLOCK_SIZE - 1));
886-
#if (!defined(WOLFSSL_ARMASM) || !defined(__aarch64__)) && \
887-
!defined(WOLFSSL_RISCV_ASM)
888+
#if (!defined(WOLFSSL_ARMASM) || (!defined(__aarch64__) && \
889+
!defined(__thumb__))) && !defined(WOLFSSL_RISCV_ASM)
888890
int ret;
889891
ret = poly1305_blocks(ctx, m, want);
890892
if (ret != 0)

wolfcrypt/src/port/arm/thumb2-chacha.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
#endif
5050

5151

52-
extern void wc_chacha_setiv(word32* x, const byte* iv, word32 counter);
53-
5452
/* Set the Initialization Vector (IV) and counter into ChaCha context.
5553
*
5654
* Set up iv(nonce). Earlier versions used 64 bits instead of 96, this version
@@ -92,8 +90,6 @@ int wc_Chacha_SetIV(ChaCha* ctx, const byte* iv, word32 counter)
9290
return ret;
9391
}
9492

95-
extern void wc_chacha_setkey(word32* x, const byte* key, word32 keySz);
96-
9793
/* Set the key into the ChaCha context.
9894
*
9995
* Key setup. 8 word iv (nonce)
@@ -141,11 +137,6 @@ int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz)
141137
return ret;
142138
}
143139

144-
extern void wc_chacha_use_over(byte* over, byte* output, const byte* input,
145-
word32 len);
146-
extern void wc_chacha_crypt_bytes(ChaCha* ctx, byte* c, const byte* m,
147-
word32 len);
148-
149140
/* API to encrypt/decrypt a message of any size.
150141
*
151142
* @param [in] ctx ChaCha context.

0 commit comments

Comments
 (0)