]> Cypherpunks.ru repositories - pygost.git/blobdiff - pygost/test_gost3410.py
Forbid any later GNU GPL versions autousage
[pygost.git] / pygost / test_gost3410.py
index b69afae81cd13ffe8e5f15208e06bd5e95d68c8a..8404a355e1f2a6ab8d774d99ba2b1eec4d7c6e47 100644 (file)
@@ -4,8 +4,7 @@
 #
 # 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
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# the Free Software Foundation, version 3 of the License.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,7 +21,9 @@ from pygost.gost3410 import CURVES
 from pygost.gost3410 import GOST3410Curve
 from pygost.gost3410 import public_key
 from pygost.gost3410 import sign
+from pygost.gost3410 import uv2xy
 from pygost.gost3410 import verify
+from pygost.gost3410 import xy2uv
 from pygost.utils import bytes2long
 from pygost.utils import hexdec
 from pygost.utils import long2bytes
@@ -230,6 +231,22 @@ class Test34102012(TestCase):
             self.assertNotIn(b"\x00" * 8, s)
 
 
+class TestUVXYConversion(TestCase):
+    """Twisted Edwards to Weierstrass coordinates conversion and vice versa
+    """
+    def test_curve1(self):
+        c = CURVES["id-tc26-gost-3410-2012-256-paramSetA"]
+        u, v = (0x0D, bytes2long(hexdec("60CA1E32AA475B348488C38FAB07649CE7EF8DBE87F22E81F92B2592DBA300E7")))
+        self.assertEqual(uv2xy(c, u, v), (c.x, c.y))
+        self.assertEqual(xy2uv(c, c.x, c.y), (u, v))
+
+    def test_curve2(self):
+        c = CURVES["id-tc26-gost-3410-2012-512-paramSetC"]
+        u, v = (0x12, bytes2long(hexdec("469AF79D1FB1F5E16B99592B77A01E2A0FDFB0D01794368D9A56117F7B38669522DD4B650CF789EEBF068C5D139732F0905622C04B2BAAE7600303EE73001A3D")))
+        self.assertEqual(uv2xy(c, u, v), (c.x, c.y))
+        self.assertEqual(xy2uv(c, c.x, c.y), (u, v))
+
+
 class Test34102012SESPAKE(TestCase):
     """Test vectors for multiplication from :rfc:`8133`
     """