X-Git-Url: http://www.git.cypherpunks.ru/?p=pygost.git;a=blobdiff_plain;f=pygost%2Ftest_gost3413.py;h=e26a3ea8752c865201d27af06cb83fcc00becdf5;hp=f1574eef6f17c73e247b967d199534dbc884b5a7;hb=22d0a1d34cbf1466e01b59a8567af36cf315f328;hpb=8041023f83244e7bc19c9bb02ae8ba83ffdf654b diff --git a/pygost/test_gost3413.py b/pygost/test_gost3413.py index f1574ee..e26a3ea 100644 --- a/pygost/test_gost3413.py +++ b/pygost/test_gost3413.py @@ -18,6 +18,7 @@ from pygost.gost3413 import pad2 from pygost.gost3413 import unpad2 from pygost.utils import hexdec from pygost.utils import hexenc +from pygost.utils import strxor class Pad2Test(TestCase): @@ -110,6 +111,19 @@ class GOST3412KuznechikModesTest(TestCase): ct = ofb(ciph.encrypt, 16, pt, iv) self.assertSequenceEqual(ofb(ciph.encrypt, 16, ct, iv), pt) + def test_ofb_manual(self): + iv = [urandom(16) for _ in range(randint(2, 10))] + pt = [urandom(16) for _ in range(len(iv), len(iv) + randint(1, 10))] + ciph = GOST3412Kuznechik(urandom(32)) + r = [ciph.encrypt(i) for i in iv] + for i in range(len(pt) - len(iv)): + r.append(ciph.encrypt(r[i])) + ct = [strxor(g, r) for g, r in zip(pt, r)] + self.assertSequenceEqual( + ofb(ciph.encrypt, 16, b"".join(pt), b"".join(iv)), + b"".join(ct), + ) + def test_cbc_vectors(self): ciphtext = "" ciphtext += "689972d4a085fa4d90e52e3d6d7dcc27"