Skip to content

Commit 10f0999

Browse files
committed
Poly1305 Aarch64 ASM: fix
r^2 may overflow after adding high bits - reduce again.
1 parent b38ab8a commit 10f0999

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

wolfcrypt/src/port/arm/armv8-poly1305.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,14 @@ int wc_Poly1305SetKey(Poly1305* ctx, const byte* key, word32 keySz)
931931
"ADDS x8, x8, x14\n\t"
932932
"ADCS x9, x9, x15\n\t"
933933
"ADC x10, x10, xzr\n\t"
934+
/* Get high bits from r^2[2]. */
935+
"AND x11, x10, -4\n\t"
936+
"AND x10, x10, 3\n\t"
937+
"ADD x11, x11, x11, LSR 2\n\t"
938+
/* Add top bits. */
939+
"ADDS x8, x8, x11\n\t"
940+
"ADCS x9, x9, xzr\n\t"
941+
"ADC x10, x10, xzr\n\t"
934942
/* 130-bits: Base 64 -> Base 26 */
935943
"EXTR x15, x10, x9, #40\n\t"
936944
"AND x14, x20, x9, LSR #14\n\t"

0 commit comments

Comments
 (0)