FiloSottile / edwards25519

filippo.io/edwards25519 — A safer, faster, and more powerful low-level edwards25519 Go implementation.
https://filippo.io/edwards25519
BSD 3-Clause "New" or "Revised" License
137 stars 30 forks source link

Save a multiply on invert #32

Closed Sc00bz closed 11 months ago

Sc00bz commented 2 years ago

Instead of using table[1/2] which is t use tt which is t**2.

FiloSottile commented 11 months ago

Thank you for the PR and sorry about the delay!

The change is correct and has a bit of performance effect on the micro-benchmark, but in my opinion not enough to justify diverting from the comment above the code, for readability reasons.

go: go1.21.4
goos: darwin
goarch: arm64
pkg: filippo.io/edwards25519
                  │   v1.1.0    │       v1.1.0-1-gbd55154c304        │
                  │   sec/op    │   sec/op     vs base               │
ScalarInversion-8   11.77µ ± 0%   11.73µ ± 0%  -0.37% (p=0.000 n=25)
Sc00bz commented 11 months ago

Yeah, no problem.