diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-10-19 14:26:21 -0700 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-10-19 14:26:21 -0700 |
commit | 107b74ed7f973f104ede1c30ac6d3e020792afe0 (patch) | |
tree | 407d8a29f9488f0b22077e4522441151b096f04d /cryptography | |
parent | e16bdfda6b2eadec0bde399f408a179379c31d9d (diff) | |
parent | c3a2b4270fbf9aba44afd04088866f2a3da21af7 (diff) | |
download | cryptography-107b74ed7f973f104ede1c30ac6d3e020792afe0.tar.gz cryptography-107b74ed7f973f104ede1c30ac6d3e020792afe0.tar.bz2 cryptography-107b74ed7f973f104ede1c30ac6d3e020792afe0.zip |
Merge pull request #141 from reaperhulk/block-cipher-buffer-sizing
Fix Block cipher buffer sizing
Diffstat (limited to 'cryptography')
-rw-r--r-- | cryptography/bindings/openssl/api.py | 6 | ||||
-rw-r--r-- | cryptography/bindings/openssl/evp.py | 1 |
2 files changed, 4 insertions, 3 deletions
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index 35be19c7..3c2cf2e2 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -128,7 +128,8 @@ class API(object): return ctx def update_encrypt_context(self, ctx, plaintext): - buf = self.ffi.new("unsigned char[]", len(plaintext)) + block_size = self.lib.EVP_CIPHER_CTX_block_size(ctx) + buf = self.ffi.new("unsigned char[]", len(plaintext) + block_size - 1) outlen = self.ffi.new("int *") res = self.lib.EVP_EncryptUpdate( ctx, buf, outlen, plaintext, len(plaintext) @@ -137,8 +138,7 @@ class API(object): return self.ffi.buffer(buf)[:outlen[0]] def finalize_encrypt_context(self, ctx): - cipher = self.lib.EVP_CIPHER_CTX_cipher(ctx) - block_size = self.lib.EVP_CIPHER_block_size(cipher) + block_size = self.lib.EVP_CIPHER_CTX_block_size(ctx) buf = self.ffi.new("unsigned char[]", block_size) outlen = self.ffi.new("int *") res = self.lib.EVP_EncryptFinal_ex(ctx, buf, outlen) diff --git a/cryptography/bindings/openssl/evp.py b/cryptography/bindings/openssl/evp.py index 2b7b0f4c..20159906 100644 --- a/cryptography/bindings/openssl/evp.py +++ b/cryptography/bindings/openssl/evp.py @@ -76,4 +76,5 @@ int EVP_VerifyFinal(EVP_MD_CTX *, const unsigned char *, unsigned int, MACROS = """ int EVP_PKEY_assign_RSA(EVP_PKEY *, RSA *); int EVP_PKEY_assign_DSA(EVP_PKEY *, DSA *); +int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *); """ |