X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fcipher.py;h=c2053e988354574d299e0bd1c36e6cf98c7ff701;hb=297667fab5c13886d82b037e74c84459f52e829c;hp=8734b6dba1fc1a6de8b67544fc2dd93e0fb2dda3;hpb=bfc5335b3138cb5902f5c807d2d27a2250380045;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/cipher.py b/ctypescrypto/cipher.py index 8734b6d..c2053e9 100644 --- a/ctypescrypto/cipher.py +++ b/ctypescrypto/cipher.py @@ -1,3 +1,7 @@ +""" +access to symmetric ciphers from libcrypto + +""" from ctypes import create_string_buffer,c_char_p,c_void_p,c_int,c_long,byref,POINTER from ctypescrypto import libcrypto from ctypescrypto.exception import LibCryptoError @@ -121,14 +125,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"