aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2013-10-19 16:01:14 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2013-10-19 16:01:14 -0500
commit3b8729006b9f2778158554d3699c05babb0c6489 (patch)
tree1f483f8aff550f71f6a2ab8aaa219d82db624a9c
parentc113b325c68834d577af0d245bd32c7407877a44 (diff)
downloadcryptography-3b8729006b9f2778158554d3699c05babb0c6489.tar.gz
cryptography-3b8729006b9f2778158554d3699c05babb0c6489.tar.bz2
cryptography-3b8729006b9f2778158554d3699c05babb0c6489.zip
fix #140. properly size char buffer for encryption
-rw-r--r--cryptography/bindings/openssl/api.py6
1 files 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)