From: Sergey Matveev Date: Sat, 19 Nov 2016 15:13:53 +0000 (+0300) Subject: Trivial docstring corrections X-Git-Tag: 3.0~13 X-Git-Url: http://www.git.cypherpunks.ru/?p=pygost.git;a=commitdiff_plain;h=9b43fc211fc6f4d2ee95d5716fc7e010dd800a26 Trivial docstring corrections --- diff --git a/pygost/gost28147.py b/pygost/gost28147.py index 6727fe3..9b21047 100644 --- a/pygost/gost28147.py +++ b/pygost/gost28147.py @@ -161,7 +161,7 @@ def _K(s, _in): :param s: S-box :param _in: 32-bit word - :return: substituted 32-bit word + :returns: substituted 32-bit word """ return ( (s[0][(_in >> 0) & 0x0F] << 0) + @@ -232,7 +232,7 @@ def xcrypt(seq, sbox, key, ns): :param bytes key: 256-bit encryption key :param ns: N1 and N2 integers :type ns: (int, int) - :return: resulting N1 and N2 + :returns: resulting N1 and N2 :rtype: (int, int) """ s = SBOXES[sbox] @@ -267,10 +267,10 @@ def ecb(key, data, action, sbox=DEFAULT_SBOX): :param bytes key: encryption key :param data: plaintext :type data: bytes, multiple of BLOCKSIZE - :param func action: encrypt/decrypt + :param func action: "encrypt"/"decrypt" :param sbox: S-box parameters to use :type sbox: str, SBOXES'es key - :return: ciphertext + :returns: ciphertext :rtype: bytes """ validate_key(key) @@ -299,7 +299,7 @@ def cbc_encrypt(key, data, iv=8 * b"\x00", pad=True, sbox=DEFAULT_SBOX): :type bool pad: perform ISO/IEC 7816-4 padding :param sbox: S-box parameters to use :type sbox: str, SBOXES'es key - :return: ciphertext + :returns: ciphertext :rtype: bytes 34.13-2015 padding method 2 is used. @@ -331,7 +331,7 @@ def cbc_decrypt(key, data, pad=True, sbox=DEFAULT_SBOX): :type bool pad: perform ISO/IEC 7816-4 unpadding after decryption :param sbox: S-box parameters to use :type sbox: str, SBOXES'es key - :return: plaintext + :returns: plaintext :rtype: bytes """ validate_key(key) @@ -367,7 +367,7 @@ def cnt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX): :type iv: bytes, BLOCKSIZE length :param sbox: S-box parameters to use :type sbox: str, SBOXES'es key - :return: ciphertext + :returns: ciphertext :rtype: bytes For decryption you use the same function again. @@ -410,7 +410,7 @@ def cfb_encrypt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX, mesh=False): :param sbox: S-box parameters to use :type sbox: str, SBOXES'es key :param bool mesh: enable key meshing - :return: ciphertext + :returns: ciphertext :rtype: bytes """ validate_key(key) @@ -446,7 +446,7 @@ def cfb_decrypt(key, data, iv=8 * b"\x00", sbox=DEFAULT_SBOX, mesh=False): :param sbox: S-box parameters to use :type sbox: str, SBOXES'es key :param bool mesh: enable key meshing - :return: ciphertext + :returns: ciphertext :rtype: bytes """ validate_key(key) diff --git a/pygost/gost3410.py b/pygost/gost3410.py index 77637c3..84881b6 100644 --- a/pygost/gost3410.py +++ b/pygost/gost3410.py @@ -178,7 +178,7 @@ def public_key(curve, prv): :param GOST3410Curve curve: curve to use :param long prv: private key - :return: public key's parts, X and Y + :returns: public key's parts, X and Y :rtype: (long, long) """ return curve.exp(prv) @@ -191,7 +191,7 @@ def sign(curve, prv, digest, mode=2001): :param long prv: private key :param digest: digest for signing :type digest: bytes, 32 or 64 bytes - :return: signature + :returns: signature :rtype: bytes, 64 or 128 bytes """ size = MODE2SIZE[mode] diff --git a/pygost/gost3410_vko.py b/pygost/gost3410_vko.py index affe819..a0354b5 100644 --- a/pygost/gost3410_vko.py +++ b/pygost/gost3410_vko.py @@ -10,11 +10,11 @@ def vko_34102001(curve, prv, pubkey, ukm): :param GOST3410Curve curve: curve to use :param long prv: private key + :param pubkey: public key + :type pubkey: (long, long) :param ukm: UKM value (VKO-factor) :type ukm: bytes, 8 bytes - :param pubkey: public key's part - :type pubkey: (long, long) - :return: Key Encryption Key (shared key) + :returns: Key Encryption Key (shared key) :rtype: bytes, 32 bytes Shared Key Encryption Key computation is based on @@ -31,11 +31,11 @@ def vko_34102012256(curve, prv, pubkey, ukm=b"\x00\x00\x00\x00\x00\x00\x00\01"): :param GOST3410Curve curve: curve to use :param long prv: private key + :param pubkey: public key + :type pubkey: (long, long) :param ukm: UKM value (VKO-factor) :type ukm: bytes, 8 bytes - :param pubkey: public key's part - :type pubkey: (long, long) - :return: Key Encryption Key (shared key) + :returns: Key Encryption Key (shared key) :rtype: bytes, 32 bytes """ key = curve.exp(prv, pubkey[0], pubkey[1]) @@ -48,11 +48,11 @@ def vko_34102012512(curve, prv, pubkey, ukm=b"\x00\x00\x00\x00\x00\x00\x00\01"): :param GOST3410Curve curve: curve to use :param long prv: private key + :param pubkey: public key + :type pubkey: (long, long) :param ukm: UKM value (VKO-factor) :type ukm: bytes, 8 bytes - :param pubkey: public key's part - :type pubkey: (long, long) - :return: Key Encryption Key (shared key) + :returns: Key Encryption Key (shared key) :rtype: bytes, 32 bytes """ key = curve.exp(prv, pubkey[0], pubkey[1]) diff --git a/pygost/gost3412.py b/pygost/gost3412.py index 38940b9..ba204a0 100644 --- a/pygost/gost3412.py +++ b/pygost/gost3412.py @@ -17,7 +17,8 @@ """GOST 34.12-2015 128-bit block cipher Кузнечик (Kuznechik) :rfc:`7801`. Pay attention that 34.12-2015 also defines 64-bit block -cipher Магма (Magma) -- it is **not** implemented here. +cipher Магма (Magma) -- it is **not** implemented here, but in gost28147 +module. Several precalculations are performed during this module importing. """ diff --git a/pygost/utils.py b/pygost/utils.py index 1fdba00..3f50af3 100644 --- a/pygost/utils.py +++ b/pygost/utils.py @@ -56,7 +56,7 @@ def bytes2long(raw): """ Deserialize big-endian bytes into long number :param bytes raw: binary string - :return: deserialized long number + :returns: deserialized long number :rtype: int """ return int(hexenc(raw), 16) @@ -66,7 +66,7 @@ def long2bytes(n, size=32): """ Serialize long number into big-endian bytestring :param long n: long number - :return: serialized bytestring + :returns: serialized bytestring :rtype: bytes """ res = hex(int(n))[2:].rstrip("L") @@ -81,7 +81,7 @@ def long2bytes(n, size=32): def modinvert(a, n): """ Modular multiplicative inverse - :return: inverse number. -1 if it does not exist + :returns: inverse number. -1 if it does not exist Realization is taken from: https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm diff --git a/pygost/wrap.py b/pygost/wrap.py index 4ab1737..81498a2 100644 --- a/pygost/wrap.py +++ b/pygost/wrap.py @@ -37,7 +37,7 @@ def wrap_gost(ukm, kek, cek): :type kek: bytes, 32 bytes :param cek: content encryption key :type cek: bytes, 32 bytes - :return: wrapped key + :returns: wrapped key :rtype: bytes, 44 bytes """ cek_mac = MAC(kek, data=cek, iv=ukm).digest()[:4] @@ -52,7 +52,7 @@ def unwrap_gost(kek, data): :type kek: bytes, 32 bytes :param data: wrapped key :type data: bytes, 44 bytes - :return: unwrapped CEK + :returns: unwrapped CEK :rtype: 32 bytes """ if len(data) != 44: @@ -73,7 +73,7 @@ def wrap_cryptopro(ukm, kek, cek): :type kek: bytes, 32 bytes :param cek: content encryption key :type cek: bytes, 32 bytes - :return: wrapped key + :returns: wrapped key :rtype: bytes, 44 bytes """ return wrap_gost(ukm, diversify(kek, bytearray(ukm)), cek) @@ -86,7 +86,7 @@ def unwrap_cryptopro(kek, data): :type kek: bytes, 32 bytes :param data: wrapped key :type data: bytes, 44 bytes - :return: unwrapped CEK + :returns: unwrapped CEK :rtype: 32 bytes """ if len(data) < 8: