]> Cypherpunks.ru repositories - pygost.git/commitdiff
GOST3410Curve.contains()
authorSergey Matveev <stargrave@stargrave.org>
Mon, 19 Oct 2020 09:56:31 +0000 (12:56 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 19 Oct 2020 10:54:13 +0000 (13:54 +0300)
news.texi
pygost/__init__.py
pygost/gost3410.py
pygost/stubs/pygost/gost3410.pyi

index c07e23f15fceb27bcaf3ae5d77f0d12caa276d85..b0c693384f7cd7c06dfd13eb61be0bd4435f42af 100644 (file)
--- a/news.texi
+++ b/news.texi
@@ -3,6 +3,13 @@
 
 @table @strong
 
 
 @table @strong
 
+@anchor{Release 5.2}
+@item 5.2
+    @itemize
+    @item @code{GOST3410Curve} has @code{.contains(point)} method for
+        checking if point is on the curve.
+    @end itemize
+
 @anchor{Release 5.1}
 @item 5.1
 Small typing stubs fixes.
 @anchor{Release 5.1}
 @item 5.1
 Small typing stubs fixes.
index 1ea51eaf126d56b883110f5027447e91216941d9..1c9a1ed8ff142867c330e80a023565548c72b2db 100644 (file)
@@ -3,4 +3,4 @@
 PyGOST is free software: see the file COPYING for copying conditions.
 """
 
 PyGOST is free software: see the file COPYING for copying conditions.
 """
 
-__version__ = "5.1"
+__version__ = "5.2"
index 433c8188f96144dd7457a308d1cf4c274b805376..a2cc7cef015507d4db84955cd4a9b9ea392adf29 100644 (file)
@@ -64,9 +64,7 @@ class GOST3410Curve(object):
         self.cofactor = cofactor
         self.e = e
         self.d = d
         self.cofactor = cofactor
         self.e = e
         self.d = d
-        r1 = self.y * self.y % self.p
-        r2 = ((self.x * self.x + self.a) * self.x + self.b) % self.p
-        if r1 != self.pos(r2):
+        if not self.contains((x, y)):
             raise ValueError("Invalid parameters")
         self._st = None
 
             raise ValueError("Invalid parameters")
         self._st = None
 
@@ -81,6 +79,16 @@ class GOST3410Curve(object):
             return v + self.p
         return v
 
             return v + self.p
         return v
 
+    def contains(self, point):
+        """Is point on the curve?
+
+        :type point: (long, long)
+        """
+        x, y = point
+        r1 = y * y % self.p
+        r2 = ((x * x + self.a) * x + self.b) % self.p
+        return r1 == self.pos(r2)
+
     def _add(self, p1x, p1y, p2x, p2y):
         if p1x == p2x and p1y == p2y:
             # double
     def _add(self, p1x, p1y, p2x, p2y):
         if p1x == p2x and p1y == p2y:
             # double
index 7f55fa9c2b9ba0fd83b1260ff516bd7e9ee89840..ee0e9b6de227720e3dbd784e47bf726ef3aac1b0 100644 (file)
@@ -40,6 +40,8 @@ class GOST3410Curve(object):
     @property
     def point_size(self) -> int: ...
 
     @property
     def point_size(self) -> int: ...
 
+    def contains(self, point: Tuple[int, int]) -> bool: ...
+
 
 def public_key(curve: GOST3410Curve, prv: int) -> PublicKey: ...
 
 
 def public_key(curve: GOST3410Curve, prv: int) -> PublicKey: ...