diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-10-30 16:47:06 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-10-31 18:07:03 -0500 |
commit | b47f6e1a9f8389224b80b5c3489bafa9e0b57273 (patch) | |
tree | 3a5e5cb17829b3f2b540c5239257c775fa2402f2 /cryptography | |
parent | 0419e5ef5f8b4f068cc30e006c55158de914c366 (diff) | |
download | cryptography-b47f6e1a9f8389224b80b5c3489bafa9e0b57273.tar.gz cryptography-b47f6e1a9f8389224b80b5c3489bafa9e0b57273.tar.bz2 cryptography-b47f6e1a9f8389224b80b5c3489bafa9e0b57273.zip |
CAST5 support + ECB vectors
Diffstat (limited to 'cryptography')
-rw-r--r-- | cryptography/hazmat/bindings/openssl/backend.py | 8 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/block/ciphers.py | 20 |
2 files changed, 27 insertions, 1 deletions
diff --git a/cryptography/hazmat/bindings/openssl/backend.py b/cryptography/hazmat/bindings/openssl/backend.py index f9bef1a5..3702dcae 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,12 @@ class Ciphers(object): mode_cls, GetCipherByName("bf-{mode.name}") ) + for mode_cls in [CBC, CFB, OFB, ECB]: + self.register_cipher_adapter( + CAST5, + mode_cls, + GetCipherByName("cast5-{mode.name}") + ) 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 |