]> Cypherpunks.ru repositories - gogost.git/commitdiff
gost3410.Curve.Contains v5.11.0
authorSergey Matveev <stargrave@stargrave.org>
Mon, 12 Jun 2023 12:41:15 +0000 (15:41 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 13 Jun 2023 14:18:31 +0000 (17:18 +0300)
gogost.go
gost3410/curve.go
news.texi

index 2aad3a2be8067e59e5731b8a2ac73ee3bbce3384..d34624ffb4ab67443be1698961f08593c77895d2 100644 (file)
--- 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"
index 6cc113548e3d6fff5a0d851408ad4a70dd8f434d..50d00719df9d2ac22c372efca96dfa9d31a9b081 100644 (file)
@@ -63,17 +63,7 @@ func NewCurve(p, q, a, b, x, y, e, d, co *big.Int) (*Curve, error) {
                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 {
@@ -88,6 +78,21 @@ func NewCurve(p, q, a, b, x, y, e, d, co *big.Int) (*Curve, error) {
        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.
 // 32 for 256-bit curves, 64 for 512-bit ones.
 func (c *Curve) PointSize() int {
index 92f34a1141351eccbe103f171e99a90cd51f925c..3b0a8af2ecc236fae1c31f5a4bef90ef5451f957 100644 (file)
--- a/news.texi
+++ b/news.texi
@@ -3,6 +3,11 @@
 
 @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