diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-11-07 07:50:17 +0800 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-11-07 08:02:08 +0800 |
commit | 4da28c35d93e14a5e6b0a252751e7cfbaf0fe372 (patch) | |
tree | 854c50830dcd7083c31e8e91b16ba4f1813d6ca1 /cryptography | |
parent | 60d4c68845aff3d44902cb978231fa01a5e74359 (diff) | |
download | cryptography-4da28c35d93e14a5e6b0a252751e7cfbaf0fe372.tar.gz cryptography-4da28c35d93e14a5e6b0a252751e7cfbaf0fe372.tar.bz2 cryptography-4da28c35d93e14a5e6b0a252751e7cfbaf0fe372.zip |
ARC4 support
Diffstat (limited to 'cryptography')
-rw-r--r-- | cryptography/hazmat/bindings/openssl/backend.py | 7 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/ciphers/algorithms.py | 19 |
2 files changed, 25 insertions, 1 deletions
diff --git a/cryptography/hazmat/bindings/openssl/backend.py b/cryptography/hazmat/bindings/openssl/backend.py index 0c3d22d5..1cb886dc 100644 --- a/cryptography/hazmat/bindings/openssl/backend.py +++ b/cryptography/hazmat/bindings/openssl/backend.py @@ -21,7 +21,7 @@ import cffi from cryptography.exceptions import UnsupportedAlgorithm from cryptography.hazmat.primitives import interfaces from cryptography.hazmat.primitives.ciphers.algorithms import ( - AES, Blowfish, Camellia, CAST5, TripleDES, + AES, Blowfish, Camellia, CAST5, TripleDES, ARC4, ) from cryptography.hazmat.primitives.ciphers.modes import ( CBC, CTR, ECB, OFB, CFB @@ -254,6 +254,11 @@ class Ciphers(object): ECB, GetCipherByName("cast5-ecb") ) + self.register_cipher_adapter( + ARC4, + type(None), + GetCipherByName("rc4") + ) def create_encrypt_ctx(self, cipher, mode): return _CipherContext(self._backend, cipher, mode, diff --git a/cryptography/hazmat/primitives/ciphers/algorithms.py b/cryptography/hazmat/primitives/ciphers/algorithms.py index 8046bd26..cbfaceb8 100644 --- a/cryptography/hazmat/primitives/ciphers/algorithms.py +++ b/cryptography/hazmat/primitives/ciphers/algorithms.py @@ -116,3 +116,22 @@ class CAST5(object): @property def key_size(self): return len(self.key) * 8 + + +class ARC4(object): + name = "RC4" + key_sizes = frozenset([40, 56, 64, 80, 128, 192, 256]) + + def __init__(self, key): + super(ARC4, 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 |