gogost.go | 2 +- gost3410/curve.go | 27 ++++++++++++++++----------- news.texi | 5 +++++ diff --git a/gogost.go b/gogost.go index c09e1b2c0a8417590c6c3eed81dafd0abf073d490fa38ce74516c811ff738261..12cf6e8a0f9c91a0f8ee95060c8395d108b984f6caae3ba404b8fea439b28ac0 100644 --- a/gogost.go +++ b/gogost.go @@ -1,4 +1,4 @@ // Pure Go GOST cryptographic functions library. package gogost -const Version = "5.10.0" +const Version = "5.11.0" diff --git a/gost3410/curve.go b/gost3410/curve.go index 0bffe8ae0054efc36614dae7948452d2f09a16c6dfb158001700751d90244dc6..0713ad070d551a49c0e23d878dc7e7e725c32809f0ca62d9373f12a3005d2fce 100644 --- a/gost3410/curve.go +++ b/gost3410/curve.go @@ -63,17 +63,7 @@ B: b, X: x, Y: y, } - r1 := big.NewInt(0) - r2 := big.NewInt(0) - r1.Mul(c.Y, c.Y) - r1.Mod(r1, c.P) - r2.Mul(c.X, c.X) - r2.Add(r2, c.A) - r2.Mul(r2, c.X) - r2.Add(r2, c.B) - r2.Mod(r2, c.P) - c.pos(r2) - if r1.Cmp(r2) != 0 { + if !c.Contains(c.X, c.Y) { return nil, errors.New("gogost/gost3410: invalid curve parameters") } if e != nil && d != nil { @@ -86,6 +76,21 @@ } else { c.Co = co } return &c, nil +} + +// Is point on curve? +func (c *Curve) Contains(x, y *big.Int) bool { + r1 := big.NewInt(0) + r2 := big.NewInt(0) + r1.Mul(y, y) + r1.Mod(r1, c.P) + r2.Mul(x, x) + r2.Add(r2, c.A) + r2.Mul(r2, x) + r2.Add(r2, c.B) + r2.Mod(r2, c.P) + c.pos(r2) + return r1.Cmp(r2) == 0 } // Get the size of the point's coordinate in bytes. diff --git a/news.texi b/news.texi index 1c4fe8ed1b1646d9668d27915f3fe1243b008f08fd0321b5fcf9e60d8cc24fbd..735e1b3683be050e923857f98ef94278e217cb08053cc0b25938cb4b26b077ce 100644 --- a/news.texi +++ b/news.texi @@ -3,6 +3,11 @@ @unnumbered News @table @strong +@anchor{Release 5.11.0} +@item 5.11.0 +You can check if public key is on curve with +@code{gost3410.Curve.Contains} method now. + @anchor{Release 5.10.0} @item 5.10.0 @itemize