]> Cypherpunks.ru repositories - pygost.git/commitdiff
Unify docstring's leading space presence
authorSergey Matveev <stargrave@stargrave.org>
Fri, 4 Sep 2020 18:48:36 +0000 (21:48 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 4 Sep 2020 19:07:40 +0000 (22:07 +0300)
17 files changed:
pygost/__init__.py
pygost/gost28147.py
pygost/gost28147_mac.py
pygost/gost3410.py
pygost/gost3410_vko.py
pygost/gost34112012.py
pygost/gost34112012256.py
pygost/gost34112012512.py
pygost/gost341194.py
pygost/gost3413.py
pygost/mgm.py
pygost/pbkdf2.py
pygost/test_gost28147.py
pygost/test_gost28147_mac.py
pygost/test_gost3410.py
pygost/test_gost341194.py
pygost/utils.py

index 7ab12bfc9fbc6d98730a7423aa45ee5f1412d68c..0ac5a2d6a31e226c0baee0fa9ff59853655b0a65 100644 (file)
@@ -1,4 +1,4 @@
-""" Pure Python GOST cryptographic functions library.
+"""Pure Python GOST cryptographic functions library.
 
 PyGOST is free software: see the file COPYING for copying conditions.
 """
index b7fc0f46634d5589cb41b3bdef10feff8d2e4c84..74f5e877add7e7945d824d73e2cf237d09a54bb1 100644 (file)
@@ -13,7 +13,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-""" GOST 28147-89 block cipher
+"""GOST 28147-89 block cipher
 
 This is implementation of :rfc:`5830` ECB, CNT, CFB and :rfc:`4357`
 CBC modes of operation. N1, N2, K names are taken according to
@@ -148,7 +148,7 @@ SBOXES["AppliedCryptography"] = SBOXES["id-GostR3411-94-TestParamSet"]
 
 
 def _K(s, _in):
-    """ S-box substitution
+    """S-box substitution
 
     :param s: S-box
     :param _in: 32-bit word
@@ -167,7 +167,7 @@ def _K(s, _in):
 
 
 def block2ns(data):
-    """ Convert block to N1 and N2 integers
+    """Convert block to N1 and N2 integers
     """
     data = bytearray(data)
     return (
@@ -177,7 +177,7 @@ def block2ns(data):
 
 
 def ns2block(ns):
-    """ Convert N1 and N2 integers to 8-byte block
+    """Convert N1 and N2 integers to 8-byte block
     """
     n1, n2 = ns
     return bytes(bytearray((
@@ -187,7 +187,7 @@ def ns2block(ns):
 
 
 def _shift11(x):
-    """ 11-bit cyclic shift
+    """11-bit cyclic shift
     """
     return ((x << 11) & (2 ** 32 - 1)) | ((x >> (32 - 11)) & (2 ** 32 - 1))
 
@@ -208,7 +208,7 @@ def validate_sbox(sbox):
 
 
 def xcrypt(seq, sbox, key, ns):
-    """ Perform full-round single-block operation
+    """Perform full-round single-block operation
 
     :param seq: sequence of K_i S-box applying (either encrypt or decrypt)
     :param sbox: S-box parameters to use
@@ -234,19 +234,19 @@ def xcrypt(seq, sbox, key, ns):
 
 
 def encrypt(sbox, key, ns):
-    """ Encrypt single block
+    """Encrypt single block
     """
     return xcrypt(SEQ_ENCRYPT, sbox, key, ns)
 
 
 def decrypt(sbox, key, ns):
-    """ Decrypt single block
+    """Decrypt single block
     """
     return xcrypt(SEQ_DECRYPT, sbox, key, ns)
 
 
 def ecb(key, data, action, sbox=DEFAULT_SBOX):
-    """ ECB mode of operation
+    """ECB mode of operation
 
     :param bytes key: encryption key
     :param data: plaintext
@@ -274,7 +274,7 @@ ecb_decrypt = partial(ecb, action=decrypt)
 
 
 def cbc_encrypt(key, data, iv=8 * b"\x00", pad=True, sbox=DEFAULT_SBOX, mesh=False):
-    """ CBC encryption mode of operation
+    """CBC encryption mode of operation
 
     :param bytes key: encryption key
     :param bytes data: plaintext
@@ -309,7 +309,7 @@ def cbc_encrypt(key, data, iv=8 * b"\x00", pad=True, sbox=DEFAULT_SBOX, mesh=Fal
 
 
 def cbc_decrypt(key, data, pad=True, sbox=DEFAULT_SBOX, mesh=False):
-    """ CBC decryption mode of operation
+    """CBC decryption mode of operation
 
     :param bytes key: encryption key
     :param bytes data: ciphertext
@@ -345,7 +345,7 @@ def cbc_decrypt(key, data, pad=True, sbox=DEFAULT_SBOX, mesh=False):
 
 
 def cnt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX):
-    """ Counter mode of operation
+    """Counter mode of operation
 
     :param bytes key: encryption key
     :param bytes data: plaintext
@@ -385,7 +385,7 @@ def meshing(key, iv, sbox=DEFAULT_SBOX):
 
 
 def cfb_encrypt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX, mesh=False):
-    """ CFB encryption mode of operation
+    """CFB encryption mode of operation
 
     :param bytes key: encryption key
     :param bytes data: plaintext
@@ -419,7 +419,7 @@ def cfb_encrypt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX, mesh=False):
 
 
 def cfb_decrypt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX, mesh=False):
-    """ CFB decryption mode of operation
+    """CFB decryption mode of operation
 
     :param bytes key: encryption key
     :param bytes data: plaintext
index 64712c6da5090e5d9e9cf86e9c26a82fcec92459..4a257c56f4536169a85622d4729873513851f711 100644 (file)
@@ -13,7 +13,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-""" GOST 28147-89 MAC
+"""GOST 28147-89 MAC
 """
 
 from copy import copy
@@ -39,7 +39,7 @@ SEQ_MAC = (
 
 
 class MAC(PEP247):
-    """ GOST 28147-89 MAC mode of operation
+    """GOST 28147-89 MAC mode of operation
 
     >>> m = MAC(key=key)
     >>> m.update("some data")
@@ -70,12 +70,12 @@ class MAC(PEP247):
         return MAC(self.key, copy(self.data), self.iv, self.sbox)
 
     def update(self, data):
-        """ Append data that has to be authenticated
+        """Append data that has to be authenticated
         """
         self.data += data
 
     def digest(self):
-        """ Get MAC tag of supplied data
+        """Get MAC tag of supplied data
 
         You have to provide at least single byte of data.
         If you want to produce tag length of 3 bytes, then
index b518c95707b48c9d0f3c0741a25a2845c90b2ac0..433c8188f96144dd7457a308d1cf4c274b805376 100644 (file)
@@ -13,7 +13,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-""" GOST R 34.10 public-key signature function.
+"""GOST R 34.10 public-key signature function.
 
 This is implementation of GOST R 34.10-2001 (:rfc:`5832`), GOST R
 34.10-2012 (:rfc:`7091`). The difference between 2001 and 2012 is the
@@ -35,7 +35,7 @@ def point_size(point):
 
 
 class GOST3410Curve(object):
-    """ GOST 34.10 validated curve
+    """GOST 34.10 validated curve
 
     >>> curve = CURVES["id-GostR3410-2001-TestParamSet"]
     >>> prv = prv_unmarshal(urandom(32))
@@ -219,7 +219,7 @@ DEFAULT_CURVE = CURVES["id-GostR3410-2001-CryptoPro-A-ParamSet"]
 
 
 def public_key(curve, prv):
-    """ Generate public key from the private one
+    """Generate public key from the private one
 
     :param GOST3410Curve curve: curve to use
     :param long prv: private key
@@ -230,7 +230,7 @@ def public_key(curve, prv):
 
 
 def sign(curve, prv, digest, rand=None):
-    """ Calculate signature for provided digest
+    """Calculate signature for provided digest
 
     :param GOST3410Curve curve: curve to use
     :param long prv: private key
@@ -268,7 +268,7 @@ def sign(curve, prv, digest, rand=None):
 
 
 def verify(curve, pub, digest, signature):
-    """ Verify provided digest with the signature
+    """Verify provided digest with the signature
 
     :param GOST3410Curve curve: curve to use
     :type pub: (long, long)
index 4bc2d4e9df85410c7d21d6f7ab88999e1a95b25d..0d49838b49c602e8492715f8d4e84461714ebe58 100644 (file)
@@ -39,7 +39,7 @@ def kek(curve, prv, pub, ukm):
 
 
 def kek_34102001(curve, prv, pub, ukm):
-    """ Key agreement (34.10-2001, 34.11-94)
+    """Key agreement (34.10-2001, 34.11-94)
 
     :param GOST3410Curve curve: curve to use
     :param long prv: private key
@@ -60,7 +60,7 @@ def kek_34102001(curve, prv, pub, ukm):
 
 
 def kek_34102012256(curve, prv, pub, ukm=1):
-    """ Key agreement (34.10-2012, 34.11-2012 256 bit)
+    """Key agreement (34.10-2012, 34.11-2012 256 bit)
 
     :param GOST3410Curve curve: curve to use
     :param long prv: private key
@@ -77,7 +77,7 @@ def kek_34102012256(curve, prv, pub, ukm=1):
 
 
 def kek_34102012512(curve, prv, pub, ukm=1):
-    """ Key agreement (34.10-2012, 34.11-2012 512 bit)
+    """Key agreement (34.10-2012, 34.11-2012 512 bit)
 
     :param GOST3410Curve curve: curve to use
     :param long prv: private key
index df4777fce69efd277ad942ef9a7b645595019ceb..b21b83c3f99b2b8dae94847fa4cf9b213fc1156a 100644 (file)
@@ -13,7 +13,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-""" GOST R 34.11-2012 (Streebog) hash function common files
+"""GOST R 34.11-2012 (Streebog) hash function common files
 
 This is implementation of :rfc:`6986`. Most function and variable names are
 taken according to specification's terminology.
@@ -164,7 +164,7 @@ C = [hexdec("".join(s))[::-1] for s in (
 
 
 def add512bit(a, b):
-    """ Add two 512 integers
+    """Add two 512 integers
     """
     a = bytearray(a)
     b = bytearray(b)
@@ -213,7 +213,7 @@ def L(data):
 
 
 class GOST34112012(PEP247):
-    """ GOST 34.11-2012 big-endian hash
+    """GOST 34.11-2012 big-endian hash
 
     >>> m = GOST34112012(digest_size=32)
     >>> m.update("foo")
@@ -239,12 +239,12 @@ class GOST34112012(PEP247):
         return self._digest_size
 
     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
         """
         hsh = BLOCKSIZE * (b"\x01" if self.digest_size == 32 else b"\x00")
         chk = bytearray(BLOCKSIZE * b"\x00")
index 865847dc8d33f93c88d41987fdae8ff94fefce4b..82c947e0037575b0601cdcbfa8f8760b52d9a79b 100644 (file)
@@ -1,4 +1,4 @@
-""" GOST R 34.11-2012 (Streebog) 256-bit hash function
+"""GOST R 34.11-2012 (Streebog) 256-bit hash function
 
 This is implementation of :rfc:`6986`. Most function and variable names are
 taken according to specification's terminology.
index f02b061b548ea2706c49284185991e3ddb2868bd..d41bea62389b19b443494bbc33344fb4dd4b130e 100644 (file)
@@ -1,4 +1,4 @@
-""" GOST R 34.11-2012 (Streebog) 512-bit hash function
+"""GOST R 34.11-2012 (Streebog) 512-bit hash function
 
 This is implementation of :rfc:`6986`. Most function and variable names are
 taken according to specification's terminology.
index 4ffb45e63f189cb4a4c1027b884c68ee54fddf6e..ba20a6eb2c04fff687a59331c199ed7dd5a2a002 100644 (file)
@@ -13,7 +13,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-""" 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.
@@ -58,7 +58,7 @@ def P(x):
 
 
 def _chi(Y):
-    """ Chi function
+    """Chi function
 
     This is some kind of LFSR.
     """
@@ -79,7 +79,7 @@ def _chi(Y):
 
 
 def _step(hin, m, sbox):
-    """ Step function
+    """Step function
 
     H_out = f(H_in, m)
     """
@@ -126,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")
@@ -152,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
index ec16f8c6b0903f73d78a3e4ee2602722d6973bc8..32be5a33f33f6a628bf2aac239f15e160f6e1df7 100644 (file)
@@ -13,7 +13,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-""" GOST R 34.13-2015: Modes of operation for block ciphers
+"""GOST R 34.13-2015: Modes of operation for block ciphers
 
 This module currently includes only padding methods.
 """
index 0321628bb16f37138f6d6b00b01d6766c9334140..33e297c3c5046ef498d6da5d7e5a7945361dc2d9 100644 (file)
@@ -13,7 +13,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-""" Multilinear Galois Mode (MGM) block cipher mode.
+"""Multilinear Galois Mode (MGM) block cipher mode.
 """
 
 from hmac import compare_digest
index 4bef6c6ea07b0c95d56bd892c129cc12054be7bb..0fd6ddcbe72400e6002b87135f7e6ba77c6e5f1a 100644 (file)
@@ -1,5 +1,5 @@
 # coding: utf-8
-""" PBKDF2 implementation suitable for GOST R 34.11-94/34.11-2012.
+"""PBKDF2 implementation suitable for GOST R 34.11-94/34.11-2012.
 
 This implementation is based on Python 3.5.2 source code's one.
 PyGOST does not register itself in hashlib anyway, so use it instead.
index 5ccb6870693ad22ffac0a3c1ebea3831783299ce..5e9da8d10d4805b91fb409ea0d29e1faf4c24b4d 100644 (file)
@@ -37,7 +37,7 @@ from pygost.utils import strxor
 
 class ECBTest(TestCase):
     def test_gcl(self):
-        """ Test vectors from libgcl3
+        """Test vectors from libgcl3
         """
         sbox = "id-Gost28147-89-TestParamSet"
         key = hexdec(b"0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd")
@@ -115,7 +115,7 @@ class ECBTest(TestCase):
         self.assertSequenceEqual(decrypted, plaintext)
 
     def test_cryptopp(self):
-        """ Test vectors from Crypto++ 5.6.2
+        """Test vectors from Crypto++ 5.6.2
         """
         sbox = "AppliedCryptography"
         data = (
@@ -135,7 +135,7 @@ class ECBTest(TestCase):
             self.assertSequenceEqual(ecb_encrypt(key, pt, sbox=sbox), ct)
 
     def test_cryptomanager(self):
-        """ Test vector from http://cryptomanager.com/tv.html
+        """Test vector from http://cryptomanager.com/tv.html
         """
         sbox = "id-GostR3411-94-TestParamSet"
         key = hexdec(b"75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B")
@@ -147,7 +147,7 @@ class ECBTest(TestCase):
 
 class CFBTest(TestCase):
     def test_cryptomanager(self):
-        """ Test vector from http://cryptomanager.com/tv.html
+        """Test vector from http://cryptomanager.com/tv.html
         """
         key = hexdec(b"75713134B60FEC45A607BB83AA3746AF4FF99DA6D1B53B5B1B402A1BAA030D1B")
         sbox = "id-GostR3411-94-TestParamSet"
@@ -171,7 +171,7 @@ class CFBTest(TestCase):
         )
 
     def test_steps(self):
-        """ Check step-by-step operation manually
+        """Check step-by-step operation manually
         """
         key = urandom(KEYSIZE)
         iv = urandom(BLOCKSIZE)
@@ -194,7 +194,7 @@ class CFBTest(TestCase):
         self.assertSequenceEqual(step[:4], ciphertext[16:])
 
     def test_random(self):
-        """ Random data with various sizes
+        """Random data with various sizes
         """
         key = urandom(KEYSIZE)
         iv = urandom(BLOCKSIZE)
@@ -208,7 +208,7 @@ class CFBTest(TestCase):
 
 class CTRTest(TestCase):
     def test_gcl(self):
-        """ Test vectors from libgcl3
+        """Test vectors from libgcl3
         """
         sbox = "id-Gost28147-89-TestParamSet"
         key = hexdec(b"0475f6e05038fbfad2c7c390edb3ca3d1547124291ae1e8a2f79cd9ed2bcefbd")
@@ -287,7 +287,7 @@ class CTRTest(TestCase):
         self.assertSequenceEqual(decrypted, plaintext)
 
     def test_gcl2(self):
-        """ Test vectors 2 from libgcl3
+        """Test vectors 2 from libgcl3
         """
         sbox = "id-Gost28147-89-TestParamSet"
         key = hexdec(b"fc7ad2886f455b50d29008fa622b57d5c65b3c637202025799cadf0768519e8a")
index 2f54dd855bf43b44aea4c9392827f7524ab96b4b..d5d5bfe0814764fb45c7a00aa0a78575e045f27b 100644 (file)
@@ -20,7 +20,7 @@ from pygost.gost28147_mac import MAC
 
 
 class TestMAC(TestCase):
-    """ Test vectors generated with libgcl3 library
+    """Test vectors generated with libgcl3 library
     """
     k = b"This is message\xFF length\x0032 bytes"
 
index ecbacf6fefc9efcf672c1e1bee2d4f93be3c8eb9..f95c47b9b5cb859f466c460632a1dae6bf2100ac 100644 (file)
@@ -32,7 +32,7 @@ from pygost.utils import long2bytes
 
 class Test341001(TestCase):
     def test_rfc(self):
-        """ Test vector from :rfc:`5832`
+        """Test vector from :rfc:`5832`
         """
         prv = bytes(bytearray((
             0x7A, 0x92, 0x9A, 0xDE, 0x78, 0x9B, 0xB9, 0xBE,
@@ -122,7 +122,7 @@ class Test34102012(TestCase):
         self.assertSequenceEqual(hexenc(signature), s + r)
 
     def test_gcl3(self):
-        """ Test vector from libgcl3
+        """Test vector from libgcl3
         """
         p = bytes2long(bytes(bytearray((
             0x45, 0x31, 0xAC, 0xD1, 0xFE, 0x00, 0x23, 0xC7,
index 96009b956ec95b0ed07e93da1590dc0d7d9cd0fd..f4d2f1eab8f781bfe8aeacef431ad733f07f5504 100644 (file)
@@ -98,7 +98,7 @@ class TestVectors(TestCase):
 
 
 class TestVectorsCryptoPro(TestCase):
-    """ CryptoPro S-box test vectors
+    """CryptoPro S-box test vectors
     """
     def test_empty(self):
         self.assertSequenceEqual(
index 0ec91fc56fe980639b88e91743d582f14759750b..fb0ccca49101ca9e43b3ddd0187a5dd1aee274a5 100644 (file)
@@ -23,7 +23,7 @@ xrange = range if version_info[0] == 3 else xrange
 
 
 def strxor(a, b):
-    """ XOR of two strings
+    """XOR of two strings
 
     This function will process only shortest length of both strings,
     ignoring remaining one.
@@ -52,7 +52,7 @@ def hexenc(data):
 
 
 def bytes2long(raw):
-    """ Deserialize big-endian bytes into long number
+    """Deserialize big-endian bytes into long number
 
     :param bytes raw: binary string
     :returns: deserialized long number
@@ -62,7 +62,7 @@ def bytes2long(raw):
 
 
 def long2bytes(n, size=32):
-    """ Serialize long number into big-endian bytestring
+    """Serialize long number into big-endian bytestring
 
     :param long n: long number
     :returns: serialized bytestring
@@ -78,7 +78,7 @@ def long2bytes(n, size=32):
 
 
 def modinvert(a, n):
-    """ Modular multiplicative inverse
+    """Modular multiplicative inverse
 
     :returns: inverse number. -1 if it does not exist