From 92c1f35054c79f3aef26712ac7ca16480f1847a0 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 9 Aug 2013 10:18:44 -0700 Subject: Compute the cipher name slightly (only slightly) better --- cryptography/bindings/openssl/api.py | 4 ++-- cryptography/primitives/block/ciphers.py | 2 ++ cryptography/primitives/block/modes.py | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index ba6fbb83..24679966 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -60,8 +60,8 @@ class API(object): def create_block_cipher_context(self, cipher, mode): ctx = self._ffi.new("EVP_CIPHER_CTX *") - # TODO: compute real cipher - ciphername = b"AES-{}-CBC".format(len(cipher.key) * 8) + # TODO: compute name using a better algorithm + ciphername = b"{}-{}-{}".format(cipher.name, len(cipher.key) * 8, mode.name) evp_cipher = self._lib.EVP_get_cipherbyname(ciphername) if evp_cipher == self._ffi.NULL: raise OpenSSLError(self) diff --git a/cryptography/primitives/block/ciphers.py b/cryptography/primitives/block/ciphers.py index e4e570d7..87dfa733 100644 --- a/cryptography/primitives/block/ciphers.py +++ b/cryptography/primitives/block/ciphers.py @@ -1,4 +1,6 @@ class AES(object): + name = "AES" + def __init__(self, key): super(AES, self).__init__() self.key = key diff --git a/cryptography/primitives/block/modes.py b/cryptography/primitives/block/modes.py index d336ed37..08d411f4 100644 --- a/cryptography/primitives/block/modes.py +++ b/cryptography/primitives/block/modes.py @@ -1,4 +1,6 @@ class CBC(object): + name = "CBC" + def __init__(self, initialization_vector, padding): super(CBC, self).__init__() self.initialization_vector = initialization_vector -- cgit v1.2.3