]> Cypherpunks.ru repositories - pygost.git/blobdiff - pygost/gost3413.py
34.13-2015 does not require double blocksized IVs
[pygost.git] / pygost / gost3413.py
index c0201c97ae8d2947aaf149494d444463c6c83a90..a350915ba3631f61892c918318a35c00b64d9092 100644 (file)
@@ -1,6 +1,6 @@
 # coding: utf-8
 # PyGOST -- Pure Python GOST cryptographic functions library
-# Copyright (C) 2015-2017 Sergey Matveev <stargrave@stargrave.org>
+# Copyright (C) 2015-2018 Sergey Matveev <stargrave@stargrave.org>
 #
 # 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
@@ -128,17 +128,17 @@ def ofb(encrypter, bs, data, iv):
     :param encrypter: Encrypting function, that takes block as an input
     :param int bs: cipher's blocksize
     :param bytes data: plaintext/ciphertext
-    :param bytes iv: double blocksize-sized initialization vector
+    :param bytes iv: blocksize-sized initialization vector
 
     For decryption you use the same function again.
     """
-    if len(iv) < 2 * bs or len(iv) % bs != 0:
+    if len(iv) < bs or len(iv) % bs != 0:
         raise ValueError("Invalid IV size")
     r = [iv[i:i + bs] for i in range(0, len(iv), bs)]
     result = []
     for i in xrange(0, len(data) + pad_size(len(data), bs), bs):
         r = r[1:] + [encrypter(r[0])]
-        result.append(strxor(r[1], data[i:i + bs]))
+        result.append(strxor(r[-1], data[i:i + bs]))
     return b"".join(result)
 
 
@@ -148,11 +148,11 @@ def cbc_encrypt(encrypter, bs, pt, iv):
     :param encrypter: Encrypting function, that takes block as an input
     :param int bs: cipher's blocksize
     :param bytes pt: already padded plaintext
-    :param bytes iv: double blocksize-sized initialization vector
+    :param bytes iv: blocksize-sized initialization vector
     """
     if not pt or len(pt) % bs != 0:
         raise ValueError("Plaintext is not blocksize aligned")
-    if len(iv) < 2 * bs or len(iv) % bs != 0:
+    if len(iv) < bs or len(iv) % bs != 0:
         raise ValueError("Invalid IV size")
     r = [iv[i:i + bs] for i in range(0, len(iv), bs)]
     ct = []
@@ -168,11 +168,11 @@ def cbc_decrypt(decrypter, bs, ct, iv):
     :param decrypter: Decrypting function, that takes block as an input
     :param int bs: cipher's blocksize
     :param bytes ct: ciphertext
-    :param bytes iv: double blocksize-sized initialization vector
+    :param bytes iv: blocksize-sized initialization vector
     """
     if not ct or len(ct) % bs != 0:
         raise ValueError("Ciphertext is not blocksize aligned")
-    if len(iv) < 2 * bs or len(iv) % bs != 0:
+    if len(iv) < bs or len(iv) % bs != 0:
         raise ValueError("Invalid IV size")
     r = [iv[i:i + bs] for i in range(0, len(iv), bs)]
     pt = []
@@ -189,9 +189,9 @@ def cfb_encrypt(encrypter, bs, pt, iv):
     :param encrypter: Encrypting function, that takes block as an input
     :param int bs: cipher's blocksize
     :param bytes pt: plaintext
-    :param bytes iv: double blocksize-sized initialization vector
+    :param bytes iv: blocksize-sized initialization vector
     """
-    if len(iv) < 2 * bs or len(iv) % bs != 0:
+    if len(iv) < bs or len(iv) % bs != 0:
         raise ValueError("Invalid IV size")
     r = [iv[i:i + bs] for i in range(0, len(iv), bs)]
     ct = []
@@ -207,9 +207,9 @@ def cfb_decrypt(encrypter, bs, ct, iv):
     :param encrypter: Encrypting function, that takes block as an input
     :param int bs: cipher's blocksize
     :param bytes ct: ciphertext
-    :param bytes iv: double blocksize-sized initialization vector
+    :param bytes iv: blocksize-sized initialization vector
     """
-    if len(iv) < 2 * bs or len(iv) % bs != 0:
+    if len(iv) < bs or len(iv) % bs != 0:
         raise ValueError("Invalid IV size")
     r = [iv[i:i + bs] for i in range(0, len(iv), bs)]
     pt = []