]> Cypherpunks.ru repositories - pygost.git/commitdiff
gost3410_vko checks if pub is on the curve
authorSergey Matveev <stargrave@stargrave.org>
Mon, 19 Oct 2020 09:57:49 +0000 (12:57 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 19 Oct 2020 10:54:13 +0000 (13:54 +0300)
news.texi
pygost/gost3410_vko.py
pygost/test_gost3410_vko.py

index b0c693384f7cd7c06dfd13eb61be0bd4435f42af..6ff2525f2d1f751757517e033a8b96f4970f5422 100644 (file)
--- a/news.texi
+++ b/news.texi
@@ -8,6 +8,8 @@
     @itemize
     @item @code{GOST3410Curve} has @code{.contains(point)} method for
         checking if point is on the curve.
+    @item @code{gost3410_vko} functions check if remote peer's public
+        key is on the curve.
     @end itemize
 
 @anchor{Release 5.1}
index 0d49838b49c602e8492715f8d4e84461714ebe58..6c52f6d11b451eb9bc4e9186589bc0ebbe812cc3 100644 (file)
@@ -33,6 +33,8 @@ def ukm_unmarshal(ukm):
 
 
 def kek(curve, prv, pub, ukm):
+    if not curve.contains(pub):
+        raise ValueError("pub is not on the curve")
     key = curve.exp(prv, pub[0], pub[1])
     key = curve.exp(curve.cofactor * ukm, key[0], key[1])
     return pub_marshal(key)
index 83053500cd38bd8d5dedfe042a75d46663954c26..1b48e2ea0badf96a64e032de86f615fff74e7e8f 100644 (file)
@@ -72,7 +72,7 @@ class TestVKO34102012256(TestCase):
         self.assertSequenceEqual(kek_34102012256(curve, prvB, pubA, ukm), vko)
 
     def test_sequence(self):
-        curve = CURVES["id-tc26-gost-3410-12-512-paramSetA"]
+        curve = CURVES["id-tc26-gost-3410-2012-256-paramSetA"]
         for _ in range(10):
             ukm = ukm_unmarshal(urandom(8))
             prv1 = bytes2long(urandom(32))
@@ -86,6 +86,14 @@ class TestVKO34102012256(TestCase):
             kek2 = kek_34102012256(curve, prv2, pub2, ukm)
             self.assertNotEqual(kek1, kek2)
 
+    def test_pub_is_not_on_curve(self):
+        with self.assertRaises(ValueError):
+            kek_34102012256(
+                CURVES["id-tc26-gost-3410-2012-256-paramSetA"],
+                bytes2long(urandom(32)),
+                pub_unmarshal(urandom(64)),
+            )
+
 
 class TestVKO34102012512(TestCase):
     """RFC 7836