diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-10-31 21:10:20 -0700 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-10-31 21:10:20 -0700 |
commit | c94cdbca7f48095ddbaf15612c7b119b3ca26f73 (patch) | |
tree | 24bb6898fca61e4b19065421399ffa589f17b617 /cryptography | |
parent | 3b243187f9ca6bec2bea125cf69dc2ddbbc7285f (diff) | |
parent | e833eac23008bc7bcb4db981f7fcc3d508d0381e (diff) | |
download | cryptography-c94cdbca7f48095ddbaf15612c7b119b3ca26f73.tar.gz cryptography-c94cdbca7f48095ddbaf15612c7b119b3ca26f73.tar.bz2 cryptography-c94cdbca7f48095ddbaf15612c7b119b3ca26f73.zip |
Merge pull request #202 from reaperhulk/cast128-cipher
CAST5 Support
Diffstat (limited to 'cryptography')
-rw-r--r-- | cryptography/hazmat/bindings/openssl/backend.py | 7 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/block/ciphers.py | 20 |
2 files changed, 26 insertions, 1 deletions
diff --git a/cryptography/hazmat/bindings/openssl/backend.py b/cryptography/hazmat/bindings/openssl/backend.py index f9bef1a5..fc73dd39 100644 --- a/cryptography/hazmat/bindings/openssl/backend.py +++ b/cryptography/hazmat/bindings/openssl/backend.py @@ -20,7 +20,7 @@ import cffi from cryptography.hazmat.primitives import interfaces from cryptography.hazmat.primitives.block.ciphers import ( - AES, Blowfish, Camellia, TripleDES, + AES, Blowfish, Camellia, CAST5, TripleDES, ) from cryptography.hazmat.primitives.block.modes import CBC, CTR, ECB, OFB, CFB @@ -227,6 +227,11 @@ class Ciphers(object): mode_cls, GetCipherByName("bf-{mode.name}") ) + self.register_cipher_adapter( + CAST5, + ECB, + GetCipherByName("cast5-ecb") + ) def create_encrypt_ctx(self, cipher, mode): return _CipherContext(self._backend, cipher, mode, diff --git a/cryptography/hazmat/primitives/block/ciphers.py b/cryptography/hazmat/primitives/block/ciphers.py index 1ab81a63..8046bd26 100644 --- a/cryptography/hazmat/primitives/block/ciphers.py +++ b/cryptography/hazmat/primitives/block/ciphers.py @@ -96,3 +96,23 @@ class Blowfish(object): @property def key_size(self): return len(self.key) * 8 + + +class CAST5(object): + name = "CAST5" + block_size = 64 + key_sizes = frozenset([40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128]) + + def __init__(self, key): + super(CAST5, 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 |