# coding: utf-8
# PyGOST -- Pure Python GOST cryptographic functions library
-# Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
+# Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
#
# 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
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
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`
"""