aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-10-16 04:25:41 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2013-10-16 04:25:41 -0700
commitaefd08be25c43576f8a0672cdf857390e044d7ea (patch)
tree98103fa523afdbc5a9cead9e23245d8a7e6122dc /cryptography
parent3be7983bba08821b10b4846f5efa4995020da613 (diff)
parentf54277876b76c867af3ad121bae7581b765fcb7c (diff)
downloadcryptography-aefd08be25c43576f8a0672cdf857390e044d7ea.tar.gz
cryptography-aefd08be25c43576f8a0672cdf857390e044d7ea.tar.bz2
cryptography-aefd08be25c43576f8a0672cdf857390e044d7ea.zip
Merge pull request #72 from reaperhulk/camellia-support
Camellia support
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/bindings/openssl/api.py6
-rw-r--r--cryptography/primitives/block/ciphers.py20
2 files changed, 25 insertions, 1 deletions
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py
index 56381ae9..02ba8fd4 100644
--- a/cryptography/bindings/openssl/api.py
+++ b/cryptography/bindings/openssl/api.py
@@ -85,6 +85,10 @@ class API(object):
"""
return self.ffi.string(self.lib.OPENSSL_VERSION_TEXT).decode("ascii")
+ def supports_cipher(self, ciphername):
+ return (self.ffi.NULL !=
+ self.lib.EVP_get_cipherbyname(ciphername.encode("ascii")))
+
def create_block_cipher_context(self, cipher, mode):
ctx = self.ffi.new("EVP_CIPHER_CTX *")
res = self.lib.EVP_CIPHER_CTX_init(ctx)
@@ -93,7 +97,7 @@ class API(object):
# TODO: compute name using a better algorithm
ciphername = "{0}-{1}-{2}".format(
cipher.name, cipher.key_size, mode.name
- )
+ ).lower()
evp_cipher = self.lib.EVP_get_cipherbyname(ciphername.encode("ascii"))
assert evp_cipher != self.ffi.NULL
if isinstance(mode, interfaces.ModeWithInitializationVector):
diff --git a/cryptography/primitives/block/ciphers.py b/cryptography/primitives/block/ciphers.py
index 01dbd027..4ac150a4 100644
--- a/cryptography/primitives/block/ciphers.py
+++ b/cryptography/primitives/block/ciphers.py
@@ -32,3 +32,23 @@ class AES(object):
@property
def key_size(self):
return len(self.key) * 8
+
+
+class Camellia(object):
+ name = "camellia"
+ block_size = 128
+ key_sizes = frozenset([128, 192, 256])
+
+ def __init__(self, key):
+ super(Camellia, self).__init__()
+ self.key = key
+
+ # Verify that the key size matches the expected key size
+ if self.key_size not in self.key_sizes:
+ raise ValueError("Invalid key size ({0}) for {1}".format(
+ self.key_size, self.name
+ ))
+
+ @property
+ def key_size(self):
+ return len(self.key) * 8