Skip to content

Add asm field kernels for X25519/Ed25519 - #171

Merged
Xor-el merged 2 commits into
masterfrom
feature/curve25519-field-asm
Aug 15, 2026
Merged

Add asm field kernels for X25519/Ed25519#171
Xor-el merged 2 commits into
masterfrom
feature/curve25519-field-asm

Conversation

@Xor-el

@Xor-el Xor-el commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Replace the Pascal radix-2^25.5 field arithmetic in the shared TX25519Field (serves X25519, Ed25519, and the Ed25519 signer) with asm kernels: Mul, Sqr, Add, Sub, Apm, CSwap, Carry and mul-by-word, on x86-64, i386 and aarch64.

Kernels are reached through a facade/backend (ClpCurveFieldSimd + ClpCurveField {X86,Arm}Backend) mirroring the existing FpKernel wiring; the Pascal path stays as the CRYPTOLIB_FORCE_SCALAR / unsupported-arch fallback.

Signed product-scanning schoolbook (imul/smull only) with the 2^255-19 reduction folded on the fly and one Int64 accumulator per column (proven < 2^63). i386 squares via X*X with an in-place carry; aarch64 keeps the ten columns register-resident.

Measured, same-thermal FORCE_SCALAR A/B: x86-64 X25519 scalar-mult 1.54x (Mul 1.33x, Sqr 1.50x, Apm 2.44x, CSwap 1.82x); i386 small ops 1.2-1.9x.

Set the package optimization back to -O1: with the hot field paths now in asm, curve performance no longer depends on the global opt level, so -O1 is used for safe ARM7 codegen without regressing the curves.

Xor-el added 2 commits August 15, 2026 12:39
Replace the Pascal radix-2^25.5 field arithmetic in the shared TX25519Field
(serves X25519, Ed25519, and the Ed25519 signer) with asm kernels: Mul, Sqr,
Add, Sub, Apm, CSwap, Carry and mul-by-word, on x86-64, i386 and aarch64.

Kernels are reached through a facade/backend (ClpCurveFieldSimd + ClpCurveField
{X86,Arm}Backend) mirroring the existing FpKernel wiring; the Pascal path stays
as the CRYPTOLIB_FORCE_SCALAR / unsupported-arch fallback.

Signed product-scanning schoolbook (imul/smull only) with the 2^255-19
reduction folded on the fly and one Int64 accumulator per column (proven
< 2^63). i386 squares via X*X with an in-place carry; aarch64 keeps the ten
columns register-resident.

Measured, same-thermal FORCE_SCALAR A/B: x86-64 X25519 scalar-mult 1.54x
(Mul 1.33x, Sqr 1.50x, Apm 2.44x, CSwap 1.82x); i386 small ops 1.2-1.9x.

Set the package optimization back to -O1: with the hot field paths now in asm,
curve performance no longer depends on the global opt level, so -O1 is used for
safe ARM7 codegen without regressing the curves.
@Xor-el
Xor-el merged commit de695f9 into master Aug 15, 2026
28 checks passed
@Xor-el
Xor-el deleted the feature/curve25519-field-asm branch August 15, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant