-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating interface for decaf and curve.
- Loading branch information
Showing
13 changed files
with
225 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,59 @@ | ||
package goldilocks | ||
|
||
import fp "github.com/cloudflare/circl/math/fp448" | ||
import ( | ||
fp "github.com/cloudflare/circl/math/fp448" | ||
) | ||
|
||
// Curve provides operations on the Goldilocks curve. | ||
// Curve is a zero-length datatype. | ||
type Curve struct{} | ||
|
||
// Identity returns the identity point. | ||
func (Curve) Identity() *Point { | ||
return &Point{ | ||
y: fp.One(), | ||
z: fp.One(), | ||
} | ||
} | ||
func (Curve) Identity() *Point { return &Point{y: fp.One(), z: fp.One()} } | ||
|
||
// Generator returns the generator point. | ||
func (Curve) Generator() *Point { | ||
return &Point{ | ||
x: genX, | ||
y: genY, | ||
z: fp.One(), | ||
ta: genX, | ||
tb: genY, | ||
} | ||
} | ||
func (Curve) Generator() *Point { return &Point{x: genX, y: genY, z: fp.One(), ta: genX, tb: genY} } | ||
|
||
// IsOnCurve returns true if the point lies on the curve. | ||
func (Curve) IsOnCurve(P *Point) bool { return isOnCurve(&P.x, &P.y, &P.ta, &P.tb, &P.z, false) } | ||
|
||
// Order returns the number of points in the prime subgroup. | ||
func (Curve) Order() Scalar { return order } | ||
|
||
// Double returns R = 2P. | ||
func (Curve) Double(R, P *Point) *Point { R := *P; R.Double(); return &R } | ||
// Double calculates R = 2P. | ||
func (Curve) Double(R, P *Point) { *R = *P; R.Double() } | ||
|
||
// Add returns P+Q. | ||
func (Curve) Add(P, Q *Point) *Point { R := *P; R.Add(Q); return &R } | ||
// Add calculates R = P+Q. | ||
func (Curve) Add(R, P, Q *Point) { S := *P; S.Add(Q); *R = S } | ||
|
||
// ScalarMult returns kP. This function runs in constant time. | ||
func (e Curve) ScalarMult(k *Scalar, P *Point) *Point { | ||
// ScalarMult calculates Q = kP. This function runs in constant time. | ||
func (Curve) ScalarMult(Q *Point, k *Scalar, P *Point) { | ||
var t twistCurve | ||
k4 := &Scalar{} | ||
k4.divBy4(k) | ||
return e.pull(twistCurve{}.ScalarMult(k4, e.push(P))) | ||
R := &twistPoint{} | ||
t.ScalarMult(R, k4, t.pull(P)) | ||
*Q = *t.push(R) | ||
} | ||
|
||
// ScalarBaseMult returns kG where G is the generator point. This function runs in constant time. | ||
func (e Curve) ScalarBaseMult(k *Scalar) *Point { | ||
// ScalarBaseMult calculates Q = kG, where G is the generator of the Goldilocks curve. This function runs in constant time. | ||
func (Curve) ScalarBaseMult(Q *Point, k *Scalar) { | ||
var t twistCurve | ||
k4 := &Scalar{} | ||
k4.divBy4(k) | ||
return e.pull(twistCurve{}.ScalarBaseMult(k4)) | ||
R := &twistPoint{} | ||
t.ScalarBaseMult(R, k4) | ||
*Q = *t.push(R) | ||
} | ||
|
||
// CombinedMult returns mG+nP, where G is the generator point. This function is non-constant time. | ||
func (e Curve) CombinedMult(m, n *Scalar, P *Point) *Point { | ||
// CombinedMult calculates Q = mG+nP, where G is the generator of the Goldilocks curve. This function does NOT run in constant time. | ||
func (Curve) CombinedMult(Q *Point, m, n *Scalar, P *Point) { | ||
var t twistCurve | ||
m4 := &Scalar{} | ||
n4 := &Scalar{} | ||
m4.divBy4(m) | ||
n4.divBy4(n) | ||
return e.pull(twistCurve{}.CombinedMult(m4, n4, twistCurve{}.pull(P))) | ||
R := &twistPoint{} | ||
t.CombinedMult(R, m4, n4, t.pull(P)) | ||
*Q = *t.push(R) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.