# coding: utf-8
# PyGOST -- Pure Python GOST cryptographic functions library
-# Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
+# Copyright (C) 2015-2023 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.
+# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# 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 skip
from unittest import TestCase
import hmac
self.assertSequenceEqual(m.digest(), c.digest())
+class TestSymmetric(TestCase):
+ def runTest(self):
+ chunks = []
+ for _ in range(randint(1, 10)):
+ chunks.append(urandom(randint(20, 80)))
+ m = GOST34112012256()
+ for chunk in chunks:
+ m.update(chunk)
+ self.assertSequenceEqual(
+ m.hexdigest(),
+ GOST34112012256(b"".join(chunks)).hexdigest(),
+ )
+
+
class TestHMAC(TestCase):
"""RFC 7836
"""
GOST34112012256(m).digest(),
hexdec("508f7e553c06501d749a66fc28c6cac0b005746d97537fa85d9e40904efed29d")[::-1]
)
+
def test_habr144(self):
- """Test vector from https://habr.com/ru/post/450024/
+ """Test vector from https://habr.com/ru/post/452200/
"""
m = hexdec("d0cf11e0a1b11ae1000000000000000000000000000000003e000300feff0900060000000000000000000000010000000100000000000000001000002400000001000000feffffff0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
self.assertSequenceEqual(