]> Cypherpunks.ru repositories - pygost.git/blobdiff - pygost/gost28147.py
34.13-2015 cipher modes of operation implementation
[pygost.git] / pygost / gost28147.py
index 79ef968f7bbc964baf3c8941a5fb4e86a806f934..2b39844694a39a8a1a9864e5ea23f25132ef27c9 100644 (file)
@@ -26,6 +26,7 @@ from functools import partial
 
 from pygost.gost3413 import pad2
 from pygost.gost3413 import pad_size
+from pygost.gost3413 import unpad2
 from pygost.utils import hexdec
 from pygost.utils import strxor
 from pygost.utils import xrange  # pylint: disable=redefined-builtin
@@ -347,14 +348,7 @@ def cbc_decrypt(key, data, pad=True, sbox=DEFAULT_SBOX):
             data[i - BLOCKSIZE:i],
         ))
     if pad:
-        last_block = bytearray(plaintext[-1])
-        pad_index = last_block.rfind(b"\x80")
-        if pad_index == -1:
-            raise ValueError("Invalid padding")
-        for c in last_block[pad_index + 1:]:
-            if c != 0:
-                raise ValueError("Invalid padding")
-        plaintext[-1] = bytes(last_block[:pad_index])
+        plaintext[-1] = unpad2(plaintext[-1], BLOCKSIZE)
     return b"".join(plaintext)