X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pygost%2Ftest_gost3410.py;h=736968bf4a56d4e1995980eba2e019971f6d6976;hb=21a30721c31912c296e1faced73e2fd0db191be9;hp=9704320dafd24c8114454990e07e1c2de9681f56;hpb=282cb5e23df11f9d5e3c29185f0e6c72f038f731;p=pygost.git diff --git a/pygost/test_gost3410.py b/pygost/test_gost3410.py index 9704320..736968b 100644 --- a/pygost/test_gost3410.py +++ b/pygost/test_gost3410.py @@ -1,6 +1,6 @@ # coding: utf-8 # PyGOST -- Pure Python GOST cryptographic functions library -# Copyright (C) 2015-2016 Sergey Matveev +# Copyright (C) 2015-2019 Sergey Matveev # # 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 @@ -22,8 +22,6 @@ from pygost.gost3410 import CURVE_PARAMS from pygost.gost3410 import GOST3410Curve from pygost.gost3410 import public_key from pygost.gost3410 import sign -from pygost.gost3410 import SIZE_3410_2001 -from pygost.gost3410 import SIZE_3410_2012 from pygost.gost3410 import verify from pygost.utils import bytes2long from pygost.utils import long2bytes @@ -33,19 +31,19 @@ class Test341001(TestCase): def test_rfc(self): """ Test vector from :rfc:`5832` """ - private_key = bytes(bytearray(( + prv = bytes(bytearray(( 0x7A, 0x92, 0x9A, 0xDE, 0x78, 0x9B, 0xB9, 0xBE, 0x10, 0xED, 0x35, 0x9D, 0xD3, 0x9A, 0x72, 0xC1, 0x1B, 0x60, 0x96, 0x1F, 0x49, 0x39, 0x7E, 0xEE, 0x1D, 0x19, 0xCE, 0x98, 0x91, 0xEC, 0x3B, 0x28 ))) - public_key_x = bytes(bytearray(( + pub_x = bytes(bytearray(( 0x7F, 0x2B, 0x49, 0xE2, 0x70, 0xDB, 0x6D, 0x90, 0xD8, 0x59, 0x5B, 0xEC, 0x45, 0x8B, 0x50, 0xC5, 0x85, 0x85, 0xBA, 0x1D, 0x4E, 0x9B, 0x78, 0x8F, 0x66, 0x89, 0xDB, 0xD8, 0xE5, 0x6F, 0xD8, 0x0B ))) - public_key_y = bytes(bytearray(( + pub_y = bytes(bytearray(( 0x26, 0xF1, 0xB4, 0x89, 0xD6, 0x70, 0x1D, 0xD1, 0x85, 0xC8, 0x41, 0x3A, 0x97, 0x7B, 0x3C, 0xBB, 0xAF, 0x64, 0xD1, 0xC5, 0x93, 0xD2, 0x66, 0x27, @@ -67,25 +65,25 @@ class Test341001(TestCase): 0xBC, 0xD6, 0xD3, 0xF7, 0x46, 0xB6, 0x31, 0xDF, 0x92, 0x80, 0x14, 0xF6, 0xC5, 0xBF, 0x9C, 0x40 ))) - private_key = bytes2long(private_key) + prv = bytes2long(prv) signature = signature[32:] + signature[:32] c = GOST3410Curve(*CURVE_PARAMS["GostR3410_2001_TestParamSet"]) - pubX, pubY = public_key(c, private_key) - self.assertEqual(long2bytes(pubX), public_key_x) - self.assertEqual(long2bytes(pubY), public_key_y) - s = sign(c, private_key, digest) - self.assertTrue(verify(c, pubX, pubY, digest, s)) - self.assertTrue(verify(c, pubX, pubY, digest, signature)) + pubX, pubY = public_key(c, prv) + self.assertEqual(long2bytes(pubX), pub_x) + self.assertEqual(long2bytes(pubY), pub_y) + s = sign(c, prv, digest) + self.assertTrue(verify(c, (pubX, pubY), digest, s)) + self.assertTrue(verify(c, (pubX, pubY), digest, signature)) def test_sequence(self): c = GOST3410Curve(*CURVE_PARAMS["GostR3410_2001_TestParamSet"]) - private_key = bytes2long(urandom(32)) - pubX, pubY = public_key(c, private_key) + prv = bytes2long(urandom(32)) + pubX, pubY = public_key(c, prv) for _ in range(20): digest = urandom(32) - s = sign(c, private_key, digest, size=SIZE_3410_2001) - self.assertTrue(verify(c, pubX, pubY, digest, s, size=SIZE_3410_2001)) + s = sign(c, prv, digest, mode=2001) + self.assertTrue(verify(c, (pubX, pubY), digest, s, mode=2001)) class Test34102012(TestCase): @@ -152,7 +150,7 @@ class Test34102012(TestCase): 0xDC, 0x1A, 0x18, 0xB9, 0x1B, 0x24, 0x64, 0x0B, 0x6D, 0xBB, 0x92, 0xCB, 0x1A, 0xDD, 0x37, 0x1E ))) - private_key = bytes(bytearray(( + prv = bytes(bytearray(( 0x0B, 0xA6, 0x04, 0x8A, 0xAD, 0xAE, 0x24, 0x1B, 0xA4, 0x09, 0x36, 0xD4, 0x77, 0x56, 0xD7, 0xC9, 0x30, 0x91, 0xA0, 0xE8, 0x51, 0x46, 0x69, 0x70, @@ -162,7 +160,7 @@ class Test34102012(TestCase): 0xA2, 0x63, 0x6B, 0x7B, 0xFD, 0x18, 0xAA, 0xDF, 0xC6, 0x29, 0x67, 0x82, 0x1F, 0xA1, 0x8D, 0xD4 ))) - public_key_x = bytes(bytearray(( + pub_x = bytes(bytearray(( 0x11, 0x5D, 0xC5, 0xBC, 0x96, 0x76, 0x0C, 0x7B, 0x48, 0x59, 0x8D, 0x8A, 0xB9, 0xE7, 0x40, 0xD4, 0xC4, 0xA8, 0x5A, 0x65, 0xBE, 0x33, 0xC1, 0x81, @@ -172,7 +170,7 @@ class Test34102012(TestCase): 0xF7, 0x5C, 0x45, 0x41, 0x5C, 0x1D, 0x9D, 0xD9, 0xDD, 0x33, 0x61, 0x2C, 0xD5, 0x30, 0xEF, 0xE1 ))) - public_key_y = bytes(bytearray(( + pub_y = bytes(bytearray(( 0x37, 0xC7, 0xC9, 0x0C, 0xD4, 0x0B, 0x0F, 0x56, 0x21, 0xDC, 0x3A, 0xC1, 0xB7, 0x51, 0xCF, 0xA0, 0xE2, 0x63, 0x4F, 0xA0, 0x50, 0x3B, 0x3D, 0x52, @@ -210,23 +208,23 @@ class Test34102012(TestCase): 0x6A, 0x6E, 0xEB, 0x1F, 0x56, 0x91, 0x9C, 0xB9, 0x2A, 0x98, 0x53, 0xBD, 0xE7, 0x3E, 0x5B, 0x4A ))) - private_key = bytes2long(private_key) + prv = bytes2long(prv) signature = signature[64:] + signature[:64] c = GOST3410Curve(p, q, a, b, x, y) - pubX, pubY = public_key(c, private_key) - self.assertEqual(long2bytes(pubX), public_key_x) - self.assertEqual(long2bytes(pubY), public_key_y) - s = sign(c, private_key, digest, size=SIZE_3410_2012) - self.assertTrue(verify(c, pubX, pubY, digest, s, size=SIZE_3410_2012)) - self.assertTrue(verify(c, pubX, pubY, digest, signature, size=SIZE_3410_2012)) + pubX, pubY = public_key(c, prv) + self.assertEqual(long2bytes(pubX), pub_x) + self.assertEqual(long2bytes(pubY), pub_y) + s = sign(c, prv, digest, mode=2012) + self.assertTrue(verify(c, (pubX, pubY), digest, s, mode=2012)) + self.assertTrue(verify(c, (pubX, pubY), digest, signature, mode=2012)) def test_sequence(self): c = GOST3410Curve(*CURVE_PARAMS["GostR3410_2012_TC26_ParamSetA"]) - private_key = bytes2long(urandom(64)) - pubX, pubY = public_key(c, private_key) + prv = bytes2long(urandom(64)) + pubX, pubY = public_key(c, prv) for _ in range(20): digest = urandom(64) - s = sign(c, private_key, digest, size=SIZE_3410_2012) - self.assertTrue(verify(c, pubX, pubY, digest, s, size=SIZE_3410_2012)) + s = sign(c, prv, digest, mode=2012) + self.assertTrue(verify(c, (pubX, pubY), digest, s, mode=2012)) self.assertNotIn(b"\x00" * 8, s)