]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/gost3410/curve.go
Correct curve names
[gogost.git] / src / cypherpunks.ru / gogost / gost3410 / curve.go
index a8efdcca49a66c556e97f73b7b5a6a2965ca20be..973b04ac582be6fec95fd20ebcf32d130943a92c 100644 (file)
@@ -29,48 +29,63 @@ var (
 )
 
 type Curve struct {
-       P *big.Int
-       Q *big.Int
+       Name string // Just simple identifier
+
+       P *big.Int // Characteristic of the underlying prime field
+       Q *big.Int // Elliptic curve subgroup order
+
+       // Equation coefficients of the elliptic curve in canonical form
        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
-       Bx *big.Int
-       By *big.Int
+       X *big.Int
+       Y *big.Int
 
        // Temporary variable for the add method
        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[:]),
-               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)
-       r1.Mul(c.By, c.By)
+       r1.Mul(c.Y, c.Y)
        r1.Mod(r1, c.P)
-       r2.Mul(c.Bx, c.Bx)
+       r2.Mul(c.X, c.X)
        r2.Add(r2, c.A)
-       r2.Mul(r2, c.Bx)
+       r2.Mul(r2, c.X)
        r2.Add(r2, c.B)
        r2.Mod(r2, c.P)
-       if r2.Cmp(big.NewInt(0)) == -1 {
-               r2.Add(r2, c.P)
-       }
+       c.pos(r2)
        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
 }