]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/gost3410/curve.go
Coordinates conversion from/to twisted Edwards to Weierstass form
[gogost.git] / src / cypherpunks.ru / gogost / gost3410 / curve.go
index 0ad10c9ff747dcc4d3b3b5087f735d4bf2ee98a8..6b371a2bdc21fc28db22481fa3978cab9eb97d21 100644 (file)
@@ -36,6 +36,10 @@ type Curve struct {
        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
@@ -44,16 +48,20 @@ type Curve struct {
        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, bx, by []byte) (*Curve, error) {
+func NewCurve(p, q, a, b, x, y, e, d *big.Int) (*Curve, error) {
        c := Curve{
-               P:  bytes2big(p[:]),
-               Q:  bytes2big(q[:]),
-               A:  bytes2big(a[:]),
-               B:  bytes2big(b[:]),
-               Bx: bytes2big(bx[:]),
-               By: bytes2big(by[:]),
+               P:  p,
+               Q:  q,
+               A:  a,
+               B:  b,
+               X:  x,
+               Y:  y,
                t:  big.NewInt(0),
                tx: big.NewInt(0),
                ty: big.NewInt(0),
@@ -71,6 +79,9 @@ func NewCurve(p, q, a, b, bx, by []byte) (*Curve, error) {
        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
 }