Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package edwards25519

import (
"errors"
"slices"

"filippo.io/edwards25519/field"
)
Expand Down Expand Up @@ -252,12 +253,14 @@ func (v *Point) MultiScalarMult(scalars []*Scalar, points []*Point) *Point {
// between each point in the multiscalar equation.

// Build lookup tables for each point
tables := make([]projLookupTable, len(points))
tables := make([]projLookupTable, 0, 2) // avoid allocation for small sizes
tables = slices.Grow(tables, len(points))[:len(points)]
for i := range tables {
tables[i].FromP3(points[i])
}
// Compute signed radix-16 digits for each scalar
digits := make([][64]int8, len(scalars))
digits := make([][64]int8, 0, 2) // avoid allocation for small sizes
digits = slices.Grow(digits, len(scalars))[:len(scalars)]
for i := range digits {
digits[i] = scalars[i].signedRadix16()
}
Expand Down
9 changes: 9 additions & 0 deletions extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ func TestVarTimeMultiScalarMultMatchesBaseMult(t *testing.T) {
}
}

func TestMultiScalarMult2NoAllocs(t *testing.T) {
p := NewIdentityPoint()
if allocs := testing.AllocsPerRun(100, func() {
p.MultiScalarMult([]*Scalar{dalekScalar, dalekScalar}, []*Point{B, B})
}); allocs != 0 {
t.Errorf("MultiScalarMult allocated %v times, expected 0", allocs)
}
}

func TestScalarMultSlowMatchesMult(t *testing.T) {
scalarMultSlowMatchesMult := func(x, y Scalar) bool {
p := NewGeneratorPoint()
Expand Down