Skip to content

Commit

Permalink
scalar: use unsigned radix 32
Browse files Browse the repository at this point in the history
Improves performance of all scalar operations; in particular adding,
subtraction, negating and unpacking.

Closes #11
See #13
  • Loading branch information
bwesterb committed Jan 4, 2019
1 parent d132eb7 commit 0995efa
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 190 deletions.
16 changes: 12 additions & 4 deletions ristretto.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@ func (p *Point) SetElligator(buf *[32]byte) *Point {
// Sets p to s * q, where q is the point for which the table t was
// computed. Returns p.
func (p *Point) ScalarMultTable(t *ScalarMultTable, s *Scalar) *Point {
t.t().ScalarMult(p.e(), (*[32]uint8)(s))
var buf [32]byte
s.SetBytes(&buf)
t.t().ScalarMult(p.e(), &buf)
return p
}

// Sets p to s * q. Returns p.
func (p *Point) ScalarMult(q *Point, s *Scalar) *Point {
p.e().ScalarMult(q.e(), (*[32]uint8)(s))
var buf [32]byte
s.SetBytes(&buf)
p.e().ScalarMult(q.e(), &buf)
return p
}

Expand All @@ -127,13 +131,17 @@ func (p *Point) ScalarMult(q *Point, s *Scalar) *Point {
// Warning: this method uses a non-constant time inmplementation and thus leaks
// information about s. Use this function only if s is public knowledge.
func (p *Point) PublicScalarMult(q *Point, s *Scalar) *Point {
p.e().VarTimeScalarMult(q.e(), (*[32]uint8)(s))
var buf [32]byte
s.SetBytes(&buf)
p.e().VarTimeScalarMult(q.e(), &buf)
return p
}

// Sets p to s * B, where B is the edwards25519 basepoint. Returns p.
func (p *Point) ScalarMultBase(s *Scalar) *Point {
edwards25519.BaseScalarMultTable.ScalarMult(p.e(), (*[32]uint8)(s))
var buf [32]byte
s.SetBytes(&buf)
edwards25519.BaseScalarMultTable.ScalarMult(p.e(), &buf)
return p
}

Expand Down

0 comments on commit 0995efa

Please sign in to comment.