X-Git-Url: http://www.git.cypherpunks.ru/?p=pygost.git;a=blobdiff_plain;f=pygost%2Ftest_gost28147.py;h=5ccb6870693ad22ffac0a3c1ebea3831783299ce;hp=5e3191e1a2a960f00a5ab5f8e039c46613a63c51;hb=7e5fe8586c0f17834a8df558b7ca86c5d7accd3e;hpb=c9abb42693dfe8288aecb7ef064b907be0561629 diff --git a/pygost/test_gost28147.py b/pygost/test_gost28147.py index 5e3191e..5ccb687 100644 --- a/pygost/test_gost28147.py +++ b/pygost/test_gost28147.py @@ -18,6 +18,7 @@ from os import urandom from unittest import TestCase from pygost.gost28147 import block2ns +from pygost.gost28147 import BLOCKSIZE from pygost.gost28147 import cbc_decrypt from pygost.gost28147 import cbc_encrypt from pygost.gost28147 import cfb_decrypt @@ -27,6 +28,7 @@ from pygost.gost28147 import DEFAULT_SBOX from pygost.gost28147 import ecb_decrypt from pygost.gost28147 import ecb_encrypt from pygost.gost28147 import encrypt +from pygost.gost28147 import KEYSIZE from pygost.gost28147 import MESH_MAX_DATA from pygost.gost28147 import ns2block from pygost.utils import hexdec @@ -171,8 +173,8 @@ class CFBTest(TestCase): def test_steps(self): """ Check step-by-step operation manually """ - key = urandom(32) - iv = urandom(8) + key = urandom(KEYSIZE) + iv = urandom(BLOCKSIZE) plaintext = urandom(20) ciphertext = cfb_encrypt(key, plaintext, iv) @@ -194,8 +196,8 @@ class CFBTest(TestCase): def test_random(self): """ Random data with various sizes """ - key = urandom(32) - iv = urandom(8) + key = urandom(KEYSIZE) + iv = urandom(BLOCKSIZE) for size in (5, 8, 16, 120): pt = urandom(size) self.assertSequenceEqual( @@ -307,7 +309,7 @@ class CTRTest(TestCase): 0x13, 0xcc, 0x55, 0x38, 0xb5, 0x63, 0x32, 0xc5, 0x23, 0xa4, 0xcb, 0x7d, 0x51, ))) - iv = 8 * b"\x00" + iv = BLOCKSIZE * b"\x00" encrypted = cnt(key, plaintext, iv=iv, sbox=sbox) self.assertSequenceEqual(encrypted, ciphertext) decrypted = cnt(key, encrypted, iv=iv, sbox=sbox) @@ -316,7 +318,7 @@ class CTRTest(TestCase): class CBCTest(TestCase): def test_pad_requirement(self): - key = 32 * b"x" + key = KEYSIZE * b"x" for s in (b"", b"foo", b"foobarbaz"): with self.assertRaises(ValueError): cbc_encrypt(key, s, pad=False) @@ -324,23 +326,23 @@ class CBCTest(TestCase): cbc_decrypt(key, s, pad=False) def test_passes(self): - iv = urandom(8) - key = 32 * b"x" + iv = urandom(BLOCKSIZE) + key = KEYSIZE * 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.assertSequenceEqual(pt, dt) def test_iv_existence_check(self): - key = 32 * b"x" + key = KEYSIZE * b"x" with self.assertRaises(ValueError): - cbc_decrypt(key, 8 * b"x") - iv = urandom(8) - cbc_decrypt(key, cbc_encrypt(key, 8 * b"x", iv)) + cbc_decrypt(key, BLOCKSIZE * b"x") + iv = urandom(BLOCKSIZE) + cbc_decrypt(key, cbc_encrypt(key, BLOCKSIZE * b"x", iv)) def test_meshing(self): pt = urandom(MESH_MAX_DATA * 3) - key = urandom(32) + key = urandom(KEYSIZE) ct = cbc_encrypt(key, pt) dt = cbc_decrypt(key, ct) self.assertSequenceEqual(pt, dt) @@ -348,8 +350,8 @@ class CBCTest(TestCase): class CFBMeshingTest(TestCase): def setUp(self): - self.key = urandom(32) - self.iv = urandom(8) + self.key = urandom(KEYSIZE) + self.iv = urandom(BLOCKSIZE) def test_single(self): pt = b"\x00"