]> Cypherpunks.ru repositories - pygost.git/blobdiff - pygost/test_gost3410.py
pygost.gost3410.sign rand argument and more 34.10-2012 test vectors
[pygost.git] / pygost / test_gost3410.py
index 02e44edcb8775695414a5a4530869092d07c337d..9d0b686f4874590212f19afed95708165acd6305 100644 (file)
@@ -26,6 +26,7 @@ from pygost.gost3410 import verify
 from pygost.gost3410 import xy2uv
 from pygost.utils import bytes2long
 from pygost.utils import hexdec
+from pygost.utils import hexenc
 from pygost.utils import long2bytes
 
 
@@ -89,6 +90,37 @@ class Test341001(TestCase):
 
 
 class Test34102012(TestCase):
+    def test_1(self):
+        """Test vector from 34.10-2012 standard itself
+        """
+        curve = CURVES["id-GostR3410-2001-TestParamSet"]
+        prv = bytes2long(hexdec("7A929ADE789BB9BE10ED359DD39A72C11B60961F49397EEE1D19CE9891EC3B28"))
+        digest = hexdec("2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5")
+        rand = hexdec("77105C9B20BCD3122823C8CF6FCC7B956DE33814E95B7FE64FED924594DCEAB3")
+        signature = sign(curve, prv, digest, rand)
+        r = "41aa28d2f1ab148280cd9ed56feda41974053554a42767b83ad043fd39dc0493"
+        s = "01456c64ba4642a1653c235a98a60249bcd6d3f746b631df928014f6c5bf9c40"
+        self.assertSequenceEqual(hexenc(signature), s + r)
+
+    def test_2(self):
+        """Test vector from 34.10-2012 standard itself
+        """
+        curve = GOST3410Curve(
+            p=3623986102229003635907788753683874306021320925534678605086546150450856166624002482588482022271496854025090823603058735163734263822371964987228582907372403,
+            q=3623986102229003635907788753683874306021320925534678605086546150450856166623969164898305032863068499961404079437936585455865192212970734808812618120619743,
+            a=7,
+            b=1518655069210828534508950034714043154928747527740206436194018823352809982443793732829756914785974674866041605397883677596626326413990136959047435811826396,
+            x=1928356944067022849399309401243137598997786635459507974357075491307766592685835441065557681003184874819658004903212332884252335830250729527632383493573274,
+            y=2288728693371972859970012155529478416353562327329506180314497425931102860301572814141997072271708807066593850650334152381857347798885864807605098724013854,
+        )
+        prv = bytes2long(hexdec("0BA6048AADAE241BA40936D47756D7C93091A0E8514669700EE7508E508B102072E8123B2200A0563322DAD2827E2714A2636B7BFD18AADFC62967821FA18DD4"))
+        digest = hexdec("3754F3CFACC9E0615C4F4A7C4D8DAB531B09B6F9C170C533A71D147035B0C5917184EE536593F4414339976C647C5D5A407ADEDB1D560C4FC6777D2972075B8C")
+        rand = hexdec("0359E7F4B1410FEACC570456C6801496946312120B39D019D455986E364F365886748ED7A44B3E794434006011842286212273A6D14CF70EA3AF71BB1AE679F1")
+        signature = sign(curve, prv, digest, rand, mode=2012)
+        r = "2f86fa60a081091a23dd795e1e3c689ee512a3c82ee0dcc2643c78eea8fcacd35492558486b20f1c9ec197c90699850260c93bcbcd9c5c3317e19344e173ae36"
+        s = "1081b394696ffe8e6585e7a9362d26b6325f56778aadbc081c0bfbe933d52ff5823ce288e8c4f362526080df7f70ce406a6eeb1f56919cb92a9853bde73e5b4a"
+        self.assertSequenceEqual(hexenc(signature), s + r)
+
     def test_gcl3(self):
         """ Test vector from libgcl3
         """