From c5a63fc144c59342e32304e4e86b2bad479a8187 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sat, 19 Nov 2016 12:07:00 +0300 Subject: [PATCH] Consistent source code quote symbols --- pygost/gost28147.py | 22 ++++++------- pygost/gost28147_mac.py | 4 +-- pygost/gost3410.py | 2 +- pygost/gost3411_2012.py | 14 ++++---- pygost/gost3411_94.py | 24 +++++++------- pygost/gost3413.py | 4 +-- pygost/iface.py | 6 ++-- pygost/test_gost28147.py | 64 ++++++++++++++++++------------------ pygost/test_gost28147_mac.py | 32 +++++++++--------- pygost/test_gost3410.py | 8 ++--- pygost/test_gost3411_2012.py | 6 ++-- pygost/test_gost3411_94.py | 44 ++++++++++++------------- pygost/utils.py | 2 +- 13 files changed, 116 insertions(+), 116 deletions(-) diff --git a/pygost/gost28147.py b/pygost/gost28147.py index 55fd474..6727fe3 100644 --- a/pygost/gost28147.py +++ b/pygost/gost28147.py @@ -282,14 +282,14 @@ def ecb(key, data, action, sbox=DEFAULT_SBOX): result.append(ns2block(action( sbox, key, block2ns(data[i:i + BLOCKSIZE]) ))) - return b''.join(result) + return b"".join(result) ecb_encrypt = partial(ecb, action=encrypt) ecb_decrypt = partial(ecb, action=decrypt) -def cbc_encrypt(key, data, iv=8 * b'\x00', pad=True, sbox=DEFAULT_SBOX): +def cbc_encrypt(key, data, iv=8 * b"\x00", pad=True, sbox=DEFAULT_SBOX): """ CBC encryption mode of operation :param bytes key: encryption key @@ -318,7 +318,7 @@ def cbc_encrypt(key, data, iv=8 * b'\x00', pad=True, sbox=DEFAULT_SBOX): ciphertext.append(ns2block(encrypt(sbox, key, block2ns( strxor(ciphertext[-1], data[i:i + BLOCKSIZE]) )))) - return b''.join(ciphertext) + return b"".join(ciphertext) def cbc_decrypt(key, data, pad=True, sbox=DEFAULT_SBOX): @@ -348,17 +348,17 @@ def cbc_decrypt(key, data, pad=True, sbox=DEFAULT_SBOX): )) if pad: last_block = bytearray(plaintext[-1]) - pad_index = last_block.rfind(b'\x80') + pad_index = last_block.rfind(b"\x80") if pad_index == -1: raise ValueError("Invalid padding") for c in last_block[pad_index + 1:]: if c != 0: raise ValueError("Invalid padding") plaintext[-1] = bytes(last_block[:pad_index]) - return b''.join(plaintext) + return b"".join(plaintext) -def cnt(key, data, iv=8 * b'\x00', sbox=DEFAULT_SBOX): +def cnt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX): """ Counter mode of operation :param bytes key: encryption key @@ -385,7 +385,7 @@ def cnt(key, data, iv=8 * b'\x00', sbox=DEFAULT_SBOX): n1 = addmod(n1, C2, 2 ** 32) n2 = addmod(n2, C1, 2 ** 32 - 1) gamma.append(ns2block(encrypt(sbox, key, (n1, n2)))) - return strxor(b''.join(gamma), data[:size]) + return strxor(b"".join(gamma), data[:size]) MESH_CONST = hexdec("6900722264C904238D3ADB9646E92AC418FEAC9400ED0712C086DCC2EF4CA92B") @@ -400,7 +400,7 @@ def meshing(key, iv, sbox=DEFAULT_SBOX): return key, iv -def cfb_encrypt(key, data, iv=8 * b'\x00', sbox=DEFAULT_SBOX, mesh=False): +def cfb_encrypt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX, mesh=False): """ CFB encryption mode of operation :param bytes key: encryption key @@ -433,10 +433,10 @@ def cfb_encrypt(key, data, iv=8 * b'\x00', sbox=DEFAULT_SBOX, mesh=False): data[i:i + BLOCKSIZE], ns2block(encrypt(sbox, key, block2ns(ciphertext[-1]))), )) - return b''.join(ciphertext[1:])[:size] + return b"".join(ciphertext[1:])[:size] -def cfb_decrypt(key, data, iv=8 * b'\x00', sbox=DEFAULT_SBOX, mesh=False): +def cfb_decrypt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX, mesh=False): """ CFB decryption mode of operation :param bytes key: encryption key @@ -474,4 +474,4 @@ def cfb_decrypt(key, data, iv=8 * b'\x00', sbox=DEFAULT_SBOX, mesh=False): data[i:i + BLOCKSIZE], ns2block(encrypt(sbox, key, block2ns(data[i - BLOCKSIZE:i]))), )) - return b''.join(plaintext)[:size] + return b"".join(plaintext)[:size] diff --git a/pygost/gost28147_mac.py b/pygost/gost28147_mac.py index 0f7eda1..5f1ce69 100644 --- a/pygost/gost28147_mac.py +++ b/pygost/gost28147_mac.py @@ -51,7 +51,7 @@ class MAC(PEP247): """ digest_size = digest_size - def __init__(self, key, data=b'', iv=8 * b'\x00', sbox=DEFAULT_SBOX): + def __init__(self, key, data=b"", iv=8 * b"\x00", sbox=DEFAULT_SBOX): """ :param key: authentication key :type key: bytes, 32 bytes @@ -100,5 +100,5 @@ class MAC(PEP247): return hexenc(self.digest()) -def new(key, data=b'', iv=8 * b'\x00', sbox=DEFAULT_SBOX): +def new(key, data=b"", iv=8 * b"\x00", sbox=DEFAULT_SBOX): return MAC(key, data, iv, sbox) diff --git a/pygost/gost3410.py b/pygost/gost3410.py index e3e2c91..c9b905e 100644 --- a/pygost/gost3410.py +++ b/pygost/gost3410.py @@ -200,7 +200,7 @@ def kek(curve, private_key, ukm, pubkey): hash output. """ key = curve.exp(private_key, pubkey[0], pubkey[1]) - key = curve.exp(bytes2long(24 * b'\x00' + ukm), key[0], key[1]) + key = curve.exp(bytes2long(24 * b"\x00" + ukm), key[0], key[1]) return GOST341194( (long2bytes(key[1]) + long2bytes(key[0]))[::-1], "GostR3411_94_CryptoProParamSet" diff --git a/pygost/gost3411_2012.py b/pygost/gost3411_2012.py index cea2bb5..7ba2b5d 100644 --- a/pygost/gost3411_2012.py +++ b/pygost/gost3411_2012.py @@ -211,7 +211,7 @@ def L(data): res64 ^= A[j] val <<= 1 res.append(pack("Q", l), self.sbox) + h = _step(h, 24 * b"\x00" + pack(">Q", l), self.sbox) checksum = hex(checksum)[2:].rstrip("L") if len(checksum) % 2 != 0: checksum = "0" + checksum checksum = hexdec(checksum) - checksum = b'\x00' * (BLOCKSIZE - len(checksum)) + checksum + checksum = b"\x00" * (BLOCKSIZE - len(checksum)) + checksum h = _step(h, checksum, self.sbox) return h @@ -184,5 +184,5 @@ class GOST341194(PEP247): return hexenc(self.digest()) -def new(data=b'', sbox=DEFAULT_SBOX): +def new(data=b"", sbox=DEFAULT_SBOX): return GOST341194(data, sbox) diff --git a/pygost/gost3413.py b/pygost/gost3413.py index a31a3c2..5fb73f8 100644 --- a/pygost/gost3413.py +++ b/pygost/gost3413.py @@ -35,7 +35,7 @@ def pad1(data, blocksize): Just fill up with zeros if necessary. """ - return data + b'\x00' * pad_size(len(data), blocksize) + return data + b"\x00" * pad_size(len(data), blocksize) def pad2(data, blocksize): @@ -43,7 +43,7 @@ def pad2(data, blocksize): Add one bit and then fill up with zeros. """ - return data + b'\x80' + b'\x00' * pad_size(len(data) + 1, blocksize) + return data + b"\x80" + b"\x00" * pad_size(len(data) + 1, blocksize) def pad3(data, blocksize): diff --git a/pygost/iface.py b/pygost/iface.py index 3fcaacd..887d69f 100644 --- a/pygost/iface.py +++ b/pygost/iface.py @@ -7,14 +7,14 @@ def add_metaclass(metaclass): """Class decorator for creating a class with a metaclass.""" def wrapper(cls): orig_vars = cls.__dict__.copy() - slots = orig_vars.get('__slots__') + slots = orig_vars.get("__slots__") if slots is not None: if isinstance(slots, str): slots = [slots] for slots_var in slots: orig_vars.pop(slots_var) - orig_vars.pop('__dict__', None) - orig_vars.pop('__weakref__', None) + orig_vars.pop("__dict__", None) + orig_vars.pop("__weakref__", None) return metaclass(cls.__name__, cls.__bases__, orig_vars) return wrapper diff --git a/pygost/test_gost28147.py b/pygost/test_gost28147.py index 6e25d53..7fd95af 100644 --- a/pygost/test_gost28147.py +++ b/pygost/test_gost28147.py @@ -39,7 +39,7 @@ class ECBTest(TestCase): """ Test vectors from libgcl3 """ sbox = "Gost2814789_TestParamSet" - key = hexdec(b'0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd') + key = hexdec(b"0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd") plaintext = bytes(bytearray(( 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, @@ -118,14 +118,14 @@ class ECBTest(TestCase): """ sbox = "AppliedCryptography" data = ( - (b'BE5EC2006CFF9DCF52354959F1FF0CBFE95061B5A648C10387069C25997C0672', b'0DF82802B741A292', b'07F9027DF7F7DF89'), - (b'B385272AC8D72A5A8B344BC80363AC4D09BF58F41F540624CBCB8FDCF55307D7', b'1354EE9C0A11CD4C', b'4FB50536F960A7B1'), - (b'AEE02F609A35660E4097E546FD3026B032CD107C7D459977ADF489BEF2652262', b'6693D492C4B0CC39', b'670034AC0FA811B5'), - (b'320E9D8422165D58911DFC7D8BBB1F81B0ECD924023BF94D9DF7DCF7801240E0', b'99E2D13080928D79', b'8118FF9D3B3CFE7D'), - (b'C9F703BBBFC63691BFA3B7B87EA8FD5E8E8EF384EF733F1A61AEF68C8FFA265F', b'D1E787749C72814C', b'A083826A790D3E0C'), - (b'728FEE32F04B4C654AD7F607D71C660C2C2670D7C999713233149A1C0C17A1F0', b'D4C05323A4F7A7B5', b'4D1F2E6B0D9DE2CE'), - (b'35FC96402209500FCFDEF5352D1ABB038FE33FC0D9D58512E56370B22BAA133B', b'8742D9A05F6A3AF6', b'2F3BB84879D11E52'), - (b'D416F630BE65B7FE150656183370E07018234EE5DA3D89C4CE9152A03E5BFB77', b'F86506DA04E41CB8', b'96F0A5C77A04F5CE'), + (b"BE5EC2006CFF9DCF52354959F1FF0CBFE95061B5A648C10387069C25997C0672", b"0DF82802B741A292", b"07F9027DF7F7DF89"), + (b"B385272AC8D72A5A8B344BC80363AC4D09BF58F41F540624CBCB8FDCF55307D7", b"1354EE9C0A11CD4C", b"4FB50536F960A7B1"), + (b"AEE02F609A35660E4097E546FD3026B032CD107C7D459977ADF489BEF2652262", b"6693D492C4B0CC39", b"670034AC0FA811B5"), + (b"320E9D8422165D58911DFC7D8BBB1F81B0ECD924023BF94D9DF7DCF7801240E0", b"99E2D13080928D79", b"8118FF9D3B3CFE7D"), + (b"C9F703BBBFC63691BFA3B7B87EA8FD5E8E8EF384EF733F1A61AEF68C8FFA265F", b"D1E787749C72814C", b"A083826A790D3E0C"), + (b"728FEE32F04B4C654AD7F607D71C660C2C2670D7C999713233149A1C0C17A1F0", b"D4C05323A4F7A7B5", b"4D1F2E6B0D9DE2CE"), + (b"35FC96402209500FCFDEF5352D1ABB038FE33FC0D9D58512E56370B22BAA133B", b"8742D9A05F6A3AF6", b"2F3BB84879D11E52"), + (b"D416F630BE65B7FE150656183370E07018234EE5DA3D89C4CE9152A03E5BFB77", b"F86506DA04E41CB8", b"96F0A5C77A04F5CE"), ) for key, pt, ct in data: key = hexdec(key) @@ -137,10 +137,10 @@ class ECBTest(TestCase): """ Test vector from http://cryptomanager.com/tv.html """ sbox = "GostR3411_94_TestParamSet" - key = hexdec(b'75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B') + key = hexdec(b"75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B") self.assertEqual( - ecb_encrypt(key, hexdec(b'1122334455667788'), sbox=sbox), - hexdec(b'03251E14F9D28ACB'), + ecb_encrypt(key, hexdec(b"1122334455667788"), sbox=sbox), + hexdec(b"03251E14F9D28ACB"), ) @@ -148,25 +148,25 @@ class CFBTest(TestCase): def test_cryptomanager(self): """ Test vector from http://cryptomanager.com/tv.html """ - key = hexdec(b'75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B') + key = hexdec(b"75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B") sbox = "GostR3411_94_TestParamSet" self.assertEqual( cfb_encrypt( key, - hexdec(b'112233445566778899AABBCCDD800000'), - iv=hexdec(b'0102030405060708'), + hexdec(b"112233445566778899AABBCCDD800000"), + iv=hexdec(b"0102030405060708"), sbox=sbox, ), - hexdec(b'6EE84586DD2BCA0CAD3616940E164242'), + hexdec(b"6EE84586DD2BCA0CAD3616940E164242"), ) self.assertEqual( cfb_decrypt( key, - hexdec(b'6EE84586DD2BCA0CAD3616940E164242'), - iv=hexdec(b'0102030405060708'), + hexdec(b"6EE84586DD2BCA0CAD3616940E164242"), + iv=hexdec(b"0102030405060708"), sbox=sbox, ), - hexdec(b'112233445566778899AABBCCDD800000'), + hexdec(b"112233445566778899AABBCCDD800000"), ) def test_steps(self): @@ -189,7 +189,7 @@ class CFBTest(TestCase): # Third non-full block step = encrypt(DEFAULT_SBOX, key, block2ns(step)) - step = strxor(plaintext[16:] + 4 * b'\x00', ns2block(step)) + step = strxor(plaintext[16:] + 4 * b"\x00", ns2block(step)) self.assertEqual(step[:4], ciphertext[16:]) def test_random(self): @@ -209,7 +209,7 @@ class CTRTest(TestCase): """ Test vectors from libgcl3 """ sbox = "Gost2814789_TestParamSet" - key = hexdec(b'0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd') + key = hexdec(b"0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd") plaintext = bytes(bytearray(( 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, @@ -278,7 +278,7 @@ class CTRTest(TestCase): 0x13, 0xc3, 0xfe, 0x1f, 0x8c, 0x55, 0x63, 0x09, 0x1f, 0xcd, 0xd4, 0x28, 0xca, ))) - iv = b'\x02\x01\x01\x01\x01\x01\x01\x01' + iv = b"\x02\x01\x01\x01\x01\x01\x01\x01" encrypted = cnt(key, plaintext, iv=iv, sbox=sbox) self.assertEqual(encrypted, ciphertext) decrypted = cnt(key, encrypted, iv=iv, sbox=sbox) @@ -288,7 +288,7 @@ class CTRTest(TestCase): """ Test vectors 2 from libgcl3 """ sbox = "Gost2814789_TestParamSet" - key = hexdec(b'fc7ad2886f455b50d29008fa622b57d5c65b3c637202025799cadf0768519e8a') + key = hexdec(b"fc7ad2886f455b50d29008fa622b57d5c65b3c637202025799cadf0768519e8a") plaintext = bytes(bytearray(( 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, @@ -307,7 +307,7 @@ class CTRTest(TestCase): 0x13, 0xcc, 0x55, 0x38, 0xb5, 0x63, 0x32, 0xc5, 0x23, 0xa4, 0xcb, 0x7d, 0x51, ))) - iv = 8 * b'\x00' + iv = 8 * b"\x00" encrypted = cnt(key, plaintext, iv=iv, sbox=sbox) self.assertEqual(encrypted, ciphertext) decrypted = cnt(key, encrypted, iv=iv, sbox=sbox) @@ -316,8 +316,8 @@ class CTRTest(TestCase): class CBCTest(TestCase): def test_pad_requirement(self): - key = 32 * b'x' - for s in (b'', b'foo', b'foobarbaz'): + key = 32 * b"x" + for s in (b"", b"foo", b"foobarbaz"): with self.assertRaises(ValueError): cbc_encrypt(key, s, pad=False) with self.assertRaises(ValueError): @@ -325,18 +325,18 @@ class CBCTest(TestCase): def test_passes(self): iv = urandom(8) - key = 32 * b'x' - for pt in (b'foo', b'foobarba', b'foobarbaz', 16 * b'x'): + key = 32 * b"x" + for pt in (b"foo", b"foobarba", b"foobarbaz", 16 * b"x"): ct = cbc_encrypt(key, pt, iv) dt = cbc_decrypt(key, ct) self.assertEqual(pt, dt) def test_iv_existence_check(self): - key = 32 * b'x' + key = 32 * b"x" with self.assertRaises(ValueError): - cbc_decrypt(key, 8 * b'x') + cbc_decrypt(key, 8 * b"x") iv = urandom(8) - cbc_decrypt(key, cbc_encrypt(key, 8 * b'x', iv)) + cbc_decrypt(key, cbc_encrypt(key, 8 * b"x", iv)) class CFBMeshingTest(TestCase): @@ -345,7 +345,7 @@ class CFBMeshingTest(TestCase): self.iv = urandom(8) def test_single(self): - pt = b'\x00' + pt = b"\x00" ct = cfb_encrypt(self.key, pt, mesh=True) dec = cfb_decrypt(self.key, ct, mesh=True) self.assertEqual(pt, dec) diff --git a/pygost/test_gost28147_mac.py b/pygost/test_gost28147_mac.py index 6bc0a99..00e9f5f 100644 --- a/pygost/test_gost28147_mac.py +++ b/pygost/test_gost28147_mac.py @@ -23,42 +23,42 @@ from pygost.gost28147_mac import MAC class TestMAC(TestCase): """ Test vectors generated with libgcl3 library """ - k = b'This is message\xFF length\x0032 bytes' + k = b"This is message\xFF length\x0032 bytes" def test_a(self): self.assertEqual( - MAC(self.k, b'a').hexdigest(), - 'bd5d3b5b2b7b57af', + MAC(self.k, b"a").hexdigest(), + "bd5d3b5b2b7b57af", ) def test_abc(self): self.assertEqual( - MAC(self.k, b'abc').hexdigest(), - '28661e40805b1ff9', + MAC(self.k, b"abc").hexdigest(), + "28661e40805b1ff9", ) def test_128U(self): self.assertEqual( - MAC(self.k, 128 * b'U').hexdigest(), - '1a06d1bad74580ef', + MAC(self.k, 128 * b"U").hexdigest(), + "1a06d1bad74580ef", ) def test_13x(self): self.assertEqual( - MAC(self.k, 13 * b'x').hexdigest(), - '917ee1f1a668fbd3', + MAC(self.k, 13 * b"x").hexdigest(), + "917ee1f1a668fbd3", ) def test_parts(self): m = MAC(self.k) - m.update(b'foo') - m.update(b'bar') - self.assertEqual(m.digest(), MAC(self.k, b'foobar').digest()) + m.update(b"foo") + m.update(b"bar") + self.assertEqual(m.digest(), MAC(self.k, b"foobar").digest()) def test_copy(self): - m = MAC(self.k, b'foo') + m = MAC(self.k, b"foo") c = m.copy() - m.update(b'barbaz') - c.update(b'bar') - c.update(b'baz') + m.update(b"barbaz") + c.update(b"bar") + c.update(b"baz") self.assertEqual(m.digest(), c.digest()) diff --git a/pygost/test_gost3410.py b/pygost/test_gost3410.py index fe19371..0dc9d3e 100644 --- a/pygost/test_gost3410.py +++ b/pygost/test_gost3410.py @@ -80,7 +80,7 @@ class Test341001(TestCase): self.assertTrue(verify(c, pubX, pubY, digest, signature)) def test_sequence(self): - c = GOST3410Curve(*CURVE_PARAMS['GostR3410_2001_TestParamSet']) + c = GOST3410Curve(*CURVE_PARAMS["GostR3410_2001_TestParamSet"]) private_key = bytes2long(urandom(32)) pubX, pubY = public_key(c, private_key) for _ in range(20): @@ -223,19 +223,19 @@ class Test34102012(TestCase): self.assertTrue(verify(c, pubX, pubY, digest, signature, size=SIZE_3410_2012)) def test_sequence(self): - c = GOST3410Curve(*CURVE_PARAMS['GostR3410_2012_TC26_ParamSetA']) + c = GOST3410Curve(*CURVE_PARAMS["GostR3410_2012_TC26_ParamSetA"]) private_key = bytes2long(urandom(64)) pubX, pubY = public_key(c, private_key) 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)) - self.assertNotIn(b'\x00' * 8, s) + self.assertNotIn(b"\x00" * 8, s) class TestVKO(TestCase): def test_sequence(self): - curve = GOST3410Curve(*CURVE_PARAMS['GostR3410_2001_TestParamSet']) + curve = GOST3410Curve(*CURVE_PARAMS["GostR3410_2001_TestParamSet"]) for _ in range(20): ukm = urandom(8) prv1 = bytes2long(urandom(32)) diff --git a/pygost/test_gost3411_2012.py b/pygost/test_gost3411_2012.py index 95af7a9..bcb4f20 100644 --- a/pygost/test_gost3411_2012.py +++ b/pygost/test_gost3411_2012.py @@ -29,9 +29,9 @@ class TestCopy(TestCase): def runTest(self): m = GOST34112012256() c = m.copy() - m.update(b'foobar') - c.update(b'foo') - c.update(b'bar') + m.update(b"foobar") + c.update(b"foo") + c.update(b"bar") self.assertEqual(m.digest(), c.digest()) diff --git a/pygost/test_gost3411_94.py b/pygost/test_gost3411_94.py index 771cad6..b4d08fb 100644 --- a/pygost/test_gost3411_94.py +++ b/pygost/test_gost3411_94.py @@ -26,54 +26,54 @@ class TestCopy(TestCase): def runTest(self): m = GOST341194() c = m.copy() - m.update(b'foobar') - c.update(b'foo') - c.update(b'bar') + m.update(b"foobar") + c.update(b"foo") + c.update(b"bar") self.assertEqual(m.digest(), c.digest()) class TestHMACPEP247(TestCase): def runTest(self): - h = hmac.new(b'foo', digestmod=gost3411_94) - h.update(b'foobar') + h = hmac.new(b"foo", digestmod=gost3411_94) + h.update(b"foobar") h.digest() class TestVectors(TestCase): def test_empty(self): self.assertEqual( - GOST341194(b'', "GostR3411_94_TestParamSet").hexdigest(), + GOST341194(b"", "GostR3411_94_TestParamSet").hexdigest(), "8d0f49492c91f45a68ff5c05d2c2b4ab78027b9aab5ce3feff5267c49cb985ce", ) def test_a(self): self.assertEqual( - GOST341194(b'a', "GostR3411_94_TestParamSet").hexdigest(), + GOST341194(b"a", "GostR3411_94_TestParamSet").hexdigest(), "dd14f362cefd49f873a5c644431b87219c3449661f808ac8e9667c369e532cd4", ) def test_abc(self): self.assertEqual( - GOST341194(b'abc', "GostR3411_94_TestParamSet").hexdigest(), + GOST341194(b"abc", "GostR3411_94_TestParamSet").hexdigest(), "1dd5a4067c49703b75bc75c9290f5ecbb5eb85229e7277a2b2b14fc4484313f3", ) def test_message_digest(self): self.assertEqual( - GOST341194(b'message digest', "GostR3411_94_TestParamSet").hexdigest(), + GOST341194(b"message digest", "GostR3411_94_TestParamSet").hexdigest(), "4d9a88a416de2fdb72de483f27652b5869243dec59be0cb6992c8fb1ec3444ad", ) def test_Us(self): self.assertEqual( - GOST341194(128 * b'U', "GostR3411_94_TestParamSet").hexdigest(), + GOST341194(128 * b"U", "GostR3411_94_TestParamSet").hexdigest(), "a43357fee8a926d9522a06870a66251c553e2774a0851d0cef0c1825eda3a353", ) def test_dog(self): self.assertEqual( GOST341194( - b'The quick brown fox jumps over the lazy dog', + b"The quick brown fox jumps over the lazy dog", "GostR3411_94_TestParamSet", ).hexdigest(), "94421f6d370fa1d16ba7ac5e31296529c968047dca9bf4258ac59a0c41fab777", @@ -82,7 +82,7 @@ class TestVectors(TestCase): def test_cog(self): self.assertEqual( GOST341194( - b'The quick brown fox jumps over the lazy cog', + b"The quick brown fox jumps over the lazy cog", "GostR3411_94_TestParamSet", ).hexdigest(), "45c4ee4ee1d25091312135540d6702e6677f7a73b5da31e10b8bb7aadac4eba3", @@ -91,7 +91,7 @@ class TestVectors(TestCase): def test_rfc32(self): self.assertEqual( GOST341194( - b'This is message, length=32 bytes', + b"This is message, length=32 bytes", "GostR3411_94_TestParamSet", ).hexdigest(), "faff37a615a816691cff3ef8b68ca247e09525f39f8119832eb81975d366c4b1", @@ -100,7 +100,7 @@ class TestVectors(TestCase): def test_rfc50(self): self.assertEqual( GOST341194( - b'Suppose the original message has length = 50 bytes', + b"Suppose the original message has length = 50 bytes", "GostR3411_94_TestParamSet", ).hexdigest(), "0852f5623b89dd57aeb4781fe54df14eeafbc1350613763a0d770aa657ba1a47", @@ -112,26 +112,26 @@ class TestVectorsCryptoPro(TestCase): """ def test_empty(self): self.assertEqual( - GOST341194(b'', "GostR3411_94_CryptoProParamSet").hexdigest(), + GOST341194(b"", "GostR3411_94_CryptoProParamSet").hexdigest(), "c056d64c2383c44a58139c9b560111ac133e43fb840f838714840ca33c5f1e98", ) def test_a(self): self.assertEqual( - GOST341194(b'a', "GostR3411_94_CryptoProParamSet").hexdigest(), + GOST341194(b"a", "GostR3411_94_CryptoProParamSet").hexdigest(), "1130402fcfaaf1ef3c13e3173f105a715580f7c97900af37bf832128dd524ce7", ) def test_abc(self): self.assertEqual( - GOST341194(b'abc', "GostR3411_94_CryptoProParamSet").hexdigest(), + GOST341194(b"abc", "GostR3411_94_CryptoProParamSet").hexdigest(), "2cd42ff986293b167e994381ed59747414dd24953677762d39d718bf6d0585b2", ) def test_message_digest(self): self.assertEqual( GOST341194( - b'message digest', + b"message digest", "GostR3411_94_CryptoProParamSet", ).hexdigest(), "a01b72299bc39a540fd672a99a72b4bdfe74417386986efaeb01a42add4160bc", @@ -140,7 +140,7 @@ class TestVectorsCryptoPro(TestCase): def test_dog(self): self.assertEqual( GOST341194( - b'The quick brown fox jumps over the lazy dog', + b"The quick brown fox jumps over the lazy dog", "GostR3411_94_CryptoProParamSet", ).hexdigest(), "760a8365d570476e787254761be7656774021b1f3de56f588c501a364a290490", @@ -149,7 +149,7 @@ class TestVectorsCryptoPro(TestCase): def test_32(self): self.assertEqual( GOST341194( - b'This is message, length=32 bytes', + b"This is message, length=32 bytes", "GostR3411_94_CryptoProParamSet", ).hexdigest(), "eb48de3e89e71bcb695fc752d617fae757f34fa77fa58ee114c5bdb7f7c2ef2c", @@ -158,7 +158,7 @@ class TestVectorsCryptoPro(TestCase): def test_50(self): self.assertEqual( GOST341194( - b'Suppose the original message has length = 50 bytes', + b"Suppose the original message has length = 50 bytes", "GostR3411_94_CryptoProParamSet", ).hexdigest(), "1150a63031dc611a5f5e40d93153f74ebde8216f6792c25a91cfcabc5c0c73c3", @@ -166,6 +166,6 @@ class TestVectorsCryptoPro(TestCase): def test_Us(self): self.assertEqual( - GOST341194(128 * b'U', "GostR3411_94_CryptoProParamSet").hexdigest(), + GOST341194(128 * b"U", "GostR3411_94_CryptoProParamSet").hexdigest(), "e8c449f608104c512710cd37fded920df1e86b211623fa27f4bb914661c74a1c", ) diff --git a/pygost/utils.py b/pygost/utils.py index 3844e1a..1fdba00 100644 --- a/pygost/utils.py +++ b/pygost/utils.py @@ -74,7 +74,7 @@ def long2bytes(n, size=32): res = "0" + res s = hexdec(res) if len(s) != size: - s = (size - len(s)) * b'\x00' + s + s = (size - len(s)) * b"\x00" + s return s -- 2.44.0