X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcypherpunks.ru%2Fgogost%2Fgost3410%2Fcurve.go;h=b25131636f3605fdea75c2adeef6dfc3a88219ea;hb=64f9decbd53306c271661bf70a232963f75365a3;hp=d253d8eea61adea237e7f7dfb63ad249cdd80c4b;hpb=014be6ab0719643d1e2996a360ab0619124b7e0e;p=gogost.git diff --git a/src/cypherpunks.ru/gogost/gost3410/curve.go b/src/cypherpunks.ru/gogost/gost3410/curve.go index d253d8e..b251316 100644 --- a/src/cypherpunks.ru/gogost/gost3410/curve.go +++ b/src/cypherpunks.ru/gogost/gost3410/curve.go @@ -1,5 +1,5 @@ // GoGOST -- Pure Go GOST cryptographic functions library -// Copyright (C) 2015-2017 Sergey Matveev +// Copyright (C) 2015-2019 Sergey Matveev // // 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 @@ -29,14 +29,16 @@ var ( ) type Curve struct { - P *big.Int - Q *big.Int + 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 // 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 @@ -44,33 +46,32 @@ type Curve struct { ty *big.Int } -func NewCurve(p, q, a, b, bx, by []byte) (*Curve, error) { +func NewCurve(p, q, a, b, x, y *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), } 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") } + } return &c, nil }