diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-19 07:38:19 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-19 07:38:19 -0800 |
commit | b29a6b2e4623fa87fecaccc05551b996f684cd53 (patch) | |
tree | f3579a5536862a304eaba25612f07f0c2515c8bd /cryptography/hazmat/primitives/ciphers/algorithms.py | |
parent | 867acfa0300ca75f2c11c15490e04b556d8bfe99 (diff) | |
parent | 62e96cbb0698d8f7d65d8dd2d301ef975a829d9e (diff) | |
download | cryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.tar.gz cryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.tar.bz2 cryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.zip |
Merge branch 'master' into fernet
Diffstat (limited to 'cryptography/hazmat/primitives/ciphers/algorithms.py')
-rw-r--r-- | cryptography/hazmat/primitives/ciphers/algorithms.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/cryptography/hazmat/primitives/ciphers/algorithms.py b/cryptography/hazmat/primitives/ciphers/algorithms.py index 8046bd26..75a87265 100644 --- a/cryptography/hazmat/primitives/ciphers/algorithms.py +++ b/cryptography/hazmat/primitives/ciphers/algorithms.py @@ -13,14 +13,17 @@ from __future__ import absolute_import, division, print_function +from cryptography import utils +from cryptography.hazmat.primitives import interfaces + +@utils.register_interface(interfaces.CipherAlgorithm) class AES(object): name = "AES" block_size = 128 key_sizes = frozenset([128, 192, 256]) def __init__(self, key): - super(AES, self).__init__() self.key = key # Verify that the key size matches the expected key size @@ -34,13 +37,13 @@ class AES(object): return len(self.key) * 8 +@utils.register_interface(interfaces.CipherAlgorithm) 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 @@ -54,13 +57,13 @@ class Camellia(object): return len(self.key) * 8 +@utils.register_interface(interfaces.CipherAlgorithm) class TripleDES(object): name = "3DES" block_size = 64 key_sizes = frozenset([64, 128, 192]) def __init__(self, key): - super(TripleDES, self).__init__() if len(key) == 8: key += key + key elif len(key) == 16: @@ -78,13 +81,13 @@ class TripleDES(object): return len(self.key) * 8 +@utils.register_interface(interfaces.CipherAlgorithm) class Blowfish(object): name = "Blowfish" block_size = 64 key_sizes = frozenset(range(32, 449, 8)) def __init__(self, key): - super(Blowfish, self).__init__() self.key = key # Verify that the key size matches the expected key size @@ -98,13 +101,33 @@ class Blowfish(object): return len(self.key) * 8 +@utils.register_interface(interfaces.CipherAlgorithm) 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 + + +@utils.register_interface(interfaces.CipherAlgorithm) +class ARC4(object): + name = "RC4" + block_size = 1 + key_sizes = frozenset([40, 56, 64, 80, 128, 192, 256]) + + def __init__(self, key): self.key = key # Verify that the key size matches the expected key size |