X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pygost%2Fgost341194.py;h=da8623e61abba84e6e2e6871b76ecef632b4a165;hb=9af4461c6af50f9cf83030867e7054d1f6311b32;hp=6d58efd666de769c9358ff66b2bf5f0175681d23;hpb=d59175f7b4ae74bf32dee438fb64577140e0ac23;p=pygost.git diff --git a/pygost/gost341194.py b/pygost/gost341194.py index 6d58efd..da8623e 100644 --- a/pygost/gost341194.py +++ b/pygost/gost341194.py @@ -1,6 +1,6 @@ # coding: utf-8 # PyGOST -- Pure Python GOST cryptographic functions library -# Copyright (C) 2015-2020 Sergey Matveev +# Copyright (C) 2015-2021 Sergey Matveev # # 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 @@ -13,7 +13,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -""" GOST R 34.11-94 hash function +"""GOST R 34.11-94 hash function This is implementation of :rfc:`5831`. Most function and variable names are taken according to specification's terminology. @@ -23,7 +23,6 @@ from copy import copy from functools import partial from struct import pack -from pygost.gost28147 import addmod from pygost.gost28147 import block2ns from pygost.gost28147 import encrypt from pygost.gost28147 import ns2block @@ -59,7 +58,7 @@ def P(x): def _chi(Y): - """ Chi function + """Chi function This is some kind of LFSR. """ @@ -80,7 +79,7 @@ def _chi(Y): def _step(hin, m, sbox): - """ Step function + """Step function H_out = f(H_in, m) """ @@ -127,7 +126,7 @@ def _step(hin, m, sbox): class GOST341194(PEP247): - """ GOST 34.11-94 big-endian hash + """GOST 34.11-94 big-endian hash >>> m = GOST341194() >>> m.update("foo") @@ -153,12 +152,12 @@ class GOST341194(PEP247): return GOST341194(copy(self.data), self.sbox) def update(self, data): - """ Append data that has to be hashed + """Append data that has to be hashed """ self.data += data def digest(self): - """ Get hash of the provided data + """Get hash of the provided data """ _len = 0 checksum = 0 @@ -167,7 +166,7 @@ class GOST341194(PEP247): for i in xrange(0, len(m), BLOCKSIZE): part = m[i:i + BLOCKSIZE][::-1] _len += len(part) * 8 - checksum = addmod(checksum, int(hexenc(part), 16), 2 ** 256) + checksum = (checksum + int(hexenc(part), 16)) % (2 ** 256) if len(part) < BLOCKSIZE: part = b"\x00" * (BLOCKSIZE - len(part)) + part h = _step(h, part, self.sbox)