+# coding: utf-8
+# PyGOST -- Pure Python GOST cryptographic functions library
+# Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
+#
+# 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
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
from os import urandom
from random import randint
from unittest import TestCase
from pygost.gost3413 import unpad2
from pygost.utils import hexdec
from pygost.utils import hexenc
+from pygost.utils import strxor
class Pad2Test(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"