]> wagner.pp.ru Git - oss/ctypescrypto.git/commitdiff
Fixed variable keylength error
authorVictor Wagner <wagner@atlas-kard.ru>
Fri, 24 Oct 2014 14:08:15 +0000 (18:08 +0400)
committerVictor Wagner <wagner@atlas-kard.ru>
Fri, 24 Oct 2014 14:08:15 +0000 (18:08 +0400)
ctypescrypto/cipher.py

index 8734b6dba1fc1a6de8b67544fc2dd93e0fb2dda3..3320d2f95031116e1e1f0d172f9241f05ee4c93c 100644 (file)
@@ -121,14 +121,16 @@ class Cipher:
                if len(key) != cipher_type.key_length():
                        if (cipher_type.flags() & 8) != 0:
                                # Variable key length cipher.
-                               result = libcrypto.EVP_CipherInit_ex(self.ctx, cipher_type.cipher, None, key_ptr, iv_ptr, c_int(enc))
+                               result = libcrypto.EVP_CipherInit_ex(self.ctx, cipher_type.cipher, None, None, None, c_int(enc))
                                result=libcrypto.EVP_CIPHER_CTX_set_key_length(self.ctx,len(key))
                                if result == 0:
                                        self._clean_ctx()
                                        raise CipherError("Unable to set key length")
+                               result = libcrypto.EVP_CipherInit_ex(self.ctx, None, None, key_ptr, iv_ptr, c_int(enc))
                        else:
                                raise ValueError("Invalid key length for this algorithm")
-               result = libcrypto.EVP_CipherInit_ex(self.ctx, cipher_type.cipher, None, key_ptr, iv_ptr, c_int(enc))
+               else:
+                       result = libcrypto.EVP_CipherInit_ex(self.ctx, cipher_type.cipher, None, key_ptr, iv_ptr, c_int(enc))
                if result == 0:
                        self._clean_ctx()
                        raise CipherError, "Unable to initialize cipher"