diff options
Diffstat (limited to 'cryptography/hazmat')
| -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  | 
