From 3b8729006b9f2778158554d3699c05babb0c6489 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sat, 19 Oct 2013 16:01:14 -0500 Subject: fix #140. properly size char buffer for encryption --- cryptography/bindings/openssl/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index 30f95b84..86937cf8 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -126,7 +126,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) @@ -135,8 +136,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) -- cgit v1.2.3