//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
+// the Free Software Foundation, version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
)
type Curve struct {
+ Name string // Just simple identifier
+
P *big.Int // Characteristic of the underlying prime field
Q *big.Int // Elliptic curve subgroup order
A *big.Int
B *big.Int
+ // Equation coefficients of the elliptic curve in twisted Edwards form
+ E *big.Int
+ D *big.Int
+
// Basic point X and Y coordinates
X *big.Int
Y *big.Int
t *big.Int
tx *big.Int
ty *big.Int
+
+ // Cached s/t parameters for Edwards curve points conversion
+ edS *big.Int
+ edT *big.Int
}
-func NewCurve(p, q, a, b, x, y *big.Int) (*Curve, error) {
+func NewCurve(p, q, a, b, x, y, e, d *big.Int) (*Curve, error) {
c := Curve{
- P: p,
- Q: q,
- A: a,
- B: b,
- X: x,
- Y: y,
- t: big.NewInt(0),
- tx: big.NewInt(0),
- ty: big.NewInt(0),
+ Name: "unknown",
+ P: p,
+ Q: q,
+ A: a,
+ B: b,
+ X: x,
+ Y: y,
+ t: big.NewInt(0),
+ tx: big.NewInt(0),
+ ty: big.NewInt(0),
}
r1 := big.NewInt(0)
r2 := big.NewInt(0)
if r1.Cmp(r2) != 0 {
return nil, errors.New("Invalid curve parameters")
}
+ if e != nil && d != nil {
+ c.E = e
+ c.D = d
}
return &c, nil
}