Commit graph

200 commits

Author SHA1 Message Date
Filippo Valsorda 700f4f4a67 edwards25519: panic if an uninitialized Point is used 2020-12-17 19:15:22 +01:00
Filippo Valsorda d791cf80f9 edwards25519: use testing.AllocsPerRun for TestAllocations 2020-12-13 18:17:45 +01:00
Filippo Valsorda 8cc8037b17 edwards25519: smooth a couple test coverage rough edges
Also, document the Pow22523 ladder. See also golang/go#39554.
2020-12-13 05:23:32 +01:00
Filippo Valsorda 9063a14176 edwards25519: test that operations cause zero heap allocations 2020-12-13 02:45:23 +01:00
Filippo Valsorda 6944ac7e84 edwards25519: relax the limb schedule slightly
By allowing all limbs to be up to 52 bits between operations, which was
already allowed by all out code, we can make the carry propagation more
parallelizable. Seems to help the compiler more than the handwritten asm.

name                    old time/op  new time/op  delta
Add-8                   7.77ns ±19%  6.43ns ± 1%  -17.16%  (p=0.000 n=10+8)
Mul-8                   26.3ns ± 0%  24.6ns ± 1%   -6.32%  (p=0.000 n=9+10)
Mul32-8                 5.86ns ± 1%  5.87ns ± 1%     ~     (p=0.171 n=10+10)
WideMultCall-8          2.54ns ± 0%  2.54ns ± 0%     ~     (p=0.965 n=9+8)
BasepointMul-8          18.6µs ± 1%  18.7µs ± 1%     ~     (p=0.095 n=9+10)
ScalarMul-8             65.6µs ± 3%  63.9µs ± 1%   -2.63%  (p=0.000 n=10+9)
VartimeDoubleBaseMul-8  61.1µs ± 1%  60.7µs ± 2%   -0.73%  (p=0.017 n=10+9)
MultiscalarMulSize8-8    224µs ± 1%   224µs ± 1%     ~     (p=0.182 n=10+9)
2020-12-12 08:36:08 -05:00
Filippo Valsorda 21ebdac884 edwards25519: rewrite carryPropagate in arm64 assembly
A lot of higher order operation time is spent in there, and the compiler
output is not great.

Not at all clear why Add doesn't benefit from the faster assembly, but
it might be small enough to be better off with inlining.

name                    old time/op  new time/op  delta
Add-8                   7.77ns ±19%  7.77ns ±19%     ~     (p=0.739 n=10+10)
Mul-8                   26.0ns ± 1%  26.3ns ± 0%   +0.94%  (p=0.000 n=9+9)
Mul32-8                 5.88ns ± 1%  5.86ns ± 1%     ~     (p=0.085 n=10+10)
WideMultCall-8          2.54ns ± 1%  2.54ns ± 0%     ~     (p=0.130 n=8+9)
BasepointMul-8          20.0µs ± 1%  18.6µs ± 1%   -6.90%  (p=0.000 n=8+9)
ScalarMul-8             71.7µs ± 0%  65.6µs ± 3%   -8.55%  (p=0.000 n=10+10)
VartimeDoubleBaseMul-8  68.6µs ± 1%  61.1µs ± 1%  -10.86%  (p=0.000 n=10+10)
MultiscalarMulSize8-8    248µs ± 2%   224µs ± 1%   -9.99%  (p=0.000 n=10+10)
2020-12-12 08:36:08 -05:00
Filippo Valsorda a260082072 edwards25519: merge carryPropagate[12]
Looks like the inliner heuristics have improved, and the function
inlines even if it's not horribly split in half.
2020-12-12 08:36:08 -05:00
Filippo Valsorda dbe1792d04 edwards25519: add TestScalarSetBytesWithClamping 2020-12-12 14:27:59 +01:00
Filippo Valsorda c1fe95af5a edwards25519: add MultByCofactor
The implementation is a bit of a hack, we can probably save some
operations by not doing the two projP2.FromP1xP1 conversions, but it's
unclear if the performance matters to anyone.

For hdevalence/ed25519consensus#5
2020-12-12 13:11:47 +01:00
Filippo Valsorda 132d95c169 edwards25519: sprinkle on-curve checks around tests 2020-12-12 12:01:36 +01:00
Filippo Valsorda ffb3e31d83 edwards25519: specify the behavior of Invert(0) and I.BytesMontgomery() 2020-12-05 02:30:18 +01:00
lukechampine 9e6a9310b2 edwards25519: add (*Scalar).MultiplyAdd 2020-12-03 17:32:03 -05:00
Luke Champine 3b045f3ef7
edwards25519: outline (*Point).Bytes (#6) 2020-11-28 21:48:34 +01:00
Filippo Valsorda ec6f8a6a18 edwards25519: make (*Scalar).SetCanonicalBytes return the receiver
Like all other SetBytes methods.
2020-11-28 04:38:15 +01:00
Filippo Valsorda 77d7b3141c edwards25519: add (*Point).BytesMontgomery 2020-11-28 04:38:15 +01:00
Filippo Valsorda 6e8d645c8b edwards25519: implement (*Point).Bytes and (*Point).SetBytes 2020-11-28 04:38:15 +01:00
Filippo Valsorda 812188a34f
README: add pkg.go.dev link 2020-11-23 14:39:08 +01:00
Filippo Valsorda a5954b249d all: add README 2020-11-23 14:37:14 +01:00
Filippo Valsorda 1c833da9b1 edwards25519: clarify ScalarBaseMult docs
Fixes #2
2020-11-23 14:21:07 +01:00
Filippo Valsorda 5352b67536
.github/workflows: add GitHub Actions tests (#1) 2020-11-23 05:40:35 +01:00
Filippo Valsorda 3a13cf15fb edwards25519: apply gc build tag 2020-11-23 05:28:02 +01:00
Filippo Valsorda 90c35a7f43 edwards25519: hide FieldElement and (*Point).ExtendedCoords
We'll need these for ristretto255, but we might want to expose them in a
separate package. Note how FieldElement was only exported for the
benefit of ExtendedCoords. For now, unexport FieldElement and delete
ExtendedCoords (since a proper FromExtendedCoords implementation would
check the curve equations anyway).
2020-11-23 05:27:48 +01:00
Filippo Valsorda 498fb1e96a edwards25519: replace FillBytes with Bytes, again
Since the sizes are fixed, we can use outlining to make Bytes almost as
efficient as FillBytes: a careful caller can avoid the allocation, and
copying 32 bytes is unlikely to show up on the profiles.
2020-11-23 05:10:24 +01:00
Filippo Valsorda 9c7303a0b2 edwards25519: remove (*Point).Identity and (*Point).Generator
I could not decide if they should be called SetIdentity/SetGenerator, so
instead I removed them. Turns out we only needed them in one place,
where Set(NewIdentityPoint()) inlines well enough that it should perform
the same.

Most the Identity calls were redundant as the value was overwritten
before being used next.
2020-11-23 04:58:26 +01:00
Filippo Valsorda 2e52ce252e edwards25519: drop unused (*Scalar).Zero 2020-11-23 04:41:53 +01:00
Filippo Valsorda 7c14a36a2a edwards25519: rename FromBytes to SetBytes
It's consistent with math/big, it follows the pattern of using verbs,
and is clearer in what it does.
2020-11-23 04:20:36 +01:00
Filippo Valsorda e3d0e456f3 edwards25519: ensure only test files import math/big 2020-11-23 03:52:04 +01:00
Filippo Valsorda daa250742f edwards25519: minor doc and string touch-ups 2020-11-23 03:51:42 +01:00
Filippo Valsorda e8698cda38 edwards25519: implement (*Scalar).FromBytesWithClamping 2020-11-23 03:46:06 +01:00
Filippo Valsorda f28d75ad5d edwards25519: change constructors
We now don't have a NewPoint which maybe helps imply there isn't a zero
value for a Point, and renamed Zero and One to Identity and Generator.
2020-11-23 02:57:28 +01:00
Filippo Valsorda 36d8598588 edwards25519: test the invariant that Scalars are always reduced 2020-11-23 00:08:28 +01:00
Filippo Valsorda feed48c532 edwards25519: cleanup the FieldElement API 2020-09-28 14:18:44 +02:00
Filippo Valsorda f6ee18761d edwards25519: make Point opaque 2020-09-28 14:18:44 +02:00
Filippo Valsorda 176388b1ad edwards25519: cleanup Scalar API to match ristretto255
Also, replaced Bytes (which appended, unlike big.Int.Bytes) with
FillBytes. ristretto255 has Encode/Decode instead of
FillBytes/FromCanonicalBytes in order to match Element, which is not
relevant here.
2020-09-28 14:18:44 +02:00
Filippo Valsorda c5c2e9e1ac edwards25519: rename ProjP3 to Point and unexport other point types 2020-09-28 14:18:44 +02:00
Filippo Valsorda 854207689b edwards25519: add Scalar aliasing test 2020-09-28 14:18:44 +02:00
Filippo Valsorda 1a86a9cb60 edwards25519: make Scalar opaque 2020-09-28 14:18:44 +02:00
Filippo Valsorda 07a7683e64 edwards25519: hide some more exposed symbols 2020-09-28 14:18:44 +02:00
Filippo Valsorda d3569cbbb3 all: flatten the package and make FieldElement opaque
For the license changes, see gtank/ristretto255-private#28 and
gtank/ristretto255#32, that contribute all code in those repositories to
the Go project under the Google CLA.
2020-09-28 14:18:44 +02:00
Filippo Valsorda 6f5f5828e1 all: expose edwards25519, base, and scalar packages 2020-08-27 00:35:09 -04:00
Filippo Valsorda 7ab4a688c3 all: ensure compatibility with older Go versions 2019-12-05 11:12:26 -05:00
Filippo Valsorda e9b8baa78f internal/radix51: implement (*FieldElement).Mul32
This pure Go implementation of Mul32 is more than twice as fast as the
assembly Mul implementation, and four times faster than the pure Go Mul.

Mul32          7.91ns ± 1%
Mul            18.6ns ± 1%
Mul [purego]   33.4ns ± 0%

Before Go 1.13, where we can't use math/bits because the fallbacks might
not be constant time, Mul32 is a little slower, but not nearly as much
as the pure Go Mul.

Mul32          9.74ns ± 0%
Mul [purego]   75.4ns ± 1%
2019-12-05 11:12:26 -05:00
Filippo Valsorda eac4de5f83 internal/radix51: restructure according to golang.org/wiki/TargetSpecific 2019-12-05 11:12:26 -05:00
Sunny Aggarwal 32506b5473 internal/radix51: fix !amd64 build (lightReduce -> carryPropagate) (#29) 2019-11-25 22:11:09 -05:00
Filippo Valsorda fb1f141b79 LICENSE: add Henry de Valence 2019-05-17 00:35:22 -04:00
Filippo Valsorda d64d989782 internal/scalar: fix FromUniformBytes 2019-05-16 15:08:48 -04:00
Filippo Valsorda 044bb444df internal/scalar: address review comments 2019-05-16 15:08:48 -04:00
Filippo Valsorda 7dba54fece all: apply suggestions from code review
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-05-16 15:08:48 -04:00
Filippo Valsorda 94bd1d933c ristretto255: expose scalar multiplication APIs
The names of the ScalarMults were picked to match elliptic.Curve.

The Scalar type is re-exposed as an opaque type, with an API that
matches the Element one.
2019-05-16 15:08:48 -04:00
Filippo Valsorda 5bd5476c22 internal/edwards25519: fix shadowing of B in TestAddSubNegOnBasePoint 2019-05-16 15:08:48 -04:00