From 31b08d5a78505f0ae1a144e58d023d84eda2cc6e Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 4 Sep 2020 21:48:36 +0300 Subject: [PATCH] Unify docstring's leading space presence --- pygost/__init__.py | 2 +- pygost/gost28147.py | 28 ++++++++++++++-------------- pygost/gost28147_mac.py | 8 ++++---- pygost/gost3410.py | 10 +++++----- pygost/gost3410_vko.py | 6 +++--- pygost/gost34112012.py | 10 +++++----- pygost/gost34112012256.py | 2 +- pygost/gost34112012512.py | 2 +- pygost/gost341194.py | 12 ++++++------ pygost/gost3413.py | 2 +- pygost/mgm.py | 2 +- pygost/pbkdf2.py | 2 +- pygost/test_gost28147.py | 16 ++++++++-------- pygost/test_gost28147_mac.py | 2 +- pygost/test_gost3410.py | 4 ++-- pygost/test_gost341194.py | 2 +- pygost/utils.py | 8 ++++---- 17 files changed, 59 insertions(+), 59 deletions(-) diff --git a/pygost/__init__.py b/pygost/__init__.py index 7ab12bf..0ac5a2d 100644 --- a/pygost/__init__.py +++ b/pygost/__init__.py @@ -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. """ diff --git a/pygost/gost28147.py b/pygost/gost28147.py index b7fc0f4..74f5e87 100644 --- a/pygost/gost28147.py +++ b/pygost/gost28147.py @@ -13,7 +13,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -""" 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 diff --git a/pygost/gost28147_mac.py b/pygost/gost28147_mac.py index 64712c6..4a257c5 100644 --- a/pygost/gost28147_mac.py +++ b/pygost/gost28147_mac.py @@ -13,7 +13,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -""" 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 diff --git a/pygost/gost3410.py b/pygost/gost3410.py index b518c95..433c818 100644 --- a/pygost/gost3410.py +++ b/pygost/gost3410.py @@ -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.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) diff --git a/pygost/gost3410_vko.py b/pygost/gost3410_vko.py index 4bc2d4e..0d49838 100644 --- a/pygost/gost3410_vko.py +++ b/pygost/gost3410_vko.py @@ -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 diff --git a/pygost/gost34112012.py b/pygost/gost34112012.py index df4777f..b21b83c 100644 --- a/pygost/gost34112012.py +++ b/pygost/gost34112012.py @@ -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-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") diff --git a/pygost/gost34112012256.py b/pygost/gost34112012256.py index 865847d..82c947e 100644 --- a/pygost/gost34112012256.py +++ b/pygost/gost34112012256.py @@ -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. diff --git a/pygost/gost34112012512.py b/pygost/gost34112012512.py index f02b061..d41bea6 100644 --- a/pygost/gost34112012512.py +++ b/pygost/gost34112012512.py @@ -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. diff --git a/pygost/gost341194.py b/pygost/gost341194.py index 4ffb45e..ba20a6e 100644 --- a/pygost/gost341194.py +++ b/pygost/gost341194.py @@ -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. @@ -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 diff --git a/pygost/gost3413.py b/pygost/gost3413.py index ec16f8c..32be5a3 100644 --- a/pygost/gost3413.py +++ b/pygost/gost3413.py @@ -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.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. """ diff --git a/pygost/mgm.py b/pygost/mgm.py index 0321628..33e297c 100644 --- a/pygost/mgm.py +++ b/pygost/mgm.py @@ -13,7 +13,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -""" Multilinear Galois Mode (MGM) block cipher mode. +"""Multilinear Galois Mode (MGM) block cipher mode. """ from hmac import compare_digest diff --git a/pygost/pbkdf2.py b/pygost/pbkdf2.py index 4bef6c6..0fd6ddc 100644 --- a/pygost/pbkdf2.py +++ b/pygost/pbkdf2.py @@ -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. diff --git a/pygost/test_gost28147.py b/pygost/test_gost28147.py index 5ccb687..5e9da8d 100644 --- a/pygost/test_gost28147.py +++ b/pygost/test_gost28147.py @@ -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") diff --git a/pygost/test_gost28147_mac.py b/pygost/test_gost28147_mac.py index 2f54dd8..d5d5bfe 100644 --- a/pygost/test_gost28147_mac.py +++ b/pygost/test_gost28147_mac.py @@ -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" diff --git a/pygost/test_gost3410.py b/pygost/test_gost3410.py index ecbacf6..f95c47b 100644 --- a/pygost/test_gost3410.py +++ b/pygost/test_gost3410.py @@ -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, diff --git a/pygost/test_gost341194.py b/pygost/test_gost341194.py index 96009b9..f4d2f1e 100644 --- a/pygost/test_gost341194.py +++ b/pygost/test_gost341194.py @@ -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( diff --git a/pygost/utils.py b/pygost/utils.py index 0ec91fc..fb0ccca 100644 --- a/pygost/utils.py +++ b/pygost/utils.py @@ -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 -- 2.44.0