]> Cypherpunks.ru repositories - pygost.git/commitdiff
Trivial docstring corrections
authorSergey Matveev <stargrave@stargrave.org>
Sat, 19 Nov 2016 15:13:53 +0000 (18:13 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 19 Nov 2016 15:13:53 +0000 (18:13 +0300)
pygost/gost28147.py
pygost/gost3410.py
pygost/gost3410_vko.py
pygost/gost3412.py
pygost/utils.py
pygost/wrap.py

index 6727fe394505864b8131dfb727a5f5bd43a274da..9b2104747d0f8c3b544dfe75ceb65b52b11d4532 100644 (file)
@@ -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)
index 77637c31b534e28c30bd972755a89b5a45567f02..84881b699a2ac5e56b47b19d8d2c459035928d7e 100644 (file)
@@ -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]
index affe819fcdc0d50337a29be871b6809c121c7988..a0354b52b4933b7918080738481eb213b054fde2 100644 (file)
@@ -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])
index 38940b9922ac011e80aacba6760fe0f39a64bade..ba204a0a1e24fa2d744e941b6fe1268193526c09 100644 (file)
@@ -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.
 """
index 1fdba000f842517d7e40869aa51577c5841c6fe4..3f50af37c9df69e57cf212a7c1fccae79f6e9004 100644 (file)
@@ -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
index 4ab17370d2df7c80f6272c5fe8ac5c266afebd92..81498a2b3f2e0a5d5d2cd312d096611d9e6ddc37 100644 (file)
@@ -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: