diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-10-30 14:45:43 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-10-31 13:35:25 -0500 |
commit | b7c46effc66d0181dec1090ada7d6864a84540d8 (patch) | |
tree | 974204b56fb88cda2a6be33f8755c56fd4d7840d /cryptography | |
parent | 6adaf277a100412826af6c8cdd31753832c5609a (diff) | |
download | cryptography-b7c46effc66d0181dec1090ada7d6864a84540d8.tar.gz cryptography-b7c46effc66d0181dec1090ada7d6864a84540d8.tar.bz2 cryptography-b7c46effc66d0181dec1090ada7d6864a84540d8.zip |
blowfish support + test vectors
Vectors sourced from https://www.schneier.com/code/vectors.txt but
reformatted to comply with our NIST loader
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 8de37d5b..f9bef1a5 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, Camellia, TripleDES, + AES, Blowfish, Camellia, TripleDES, ) from cryptography.hazmat.primitives.block.modes import CBC, CTR, ECB, OFB, CFB @@ -221,6 +221,12 @@ class Ciphers(object): mode_cls, GetCipherByName("des-ede3-{mode.name}") ) + for mode_cls in [CBC, CFB, OFB, ECB]: + self.register_cipher_adapter( + Blowfish, + mode_cls, + GetCipherByName("bf-{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 4143b89d..1ab81a63 100644 --- a/cryptography/hazmat/primitives/block/ciphers.py +++ b/cryptography/hazmat/primitives/block/ciphers.py @@ -76,3 +76,23 @@ class TripleDES(object): @property def key_size(self): return len(self.key) * 8 + + +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 + 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 |