diff options
| author | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-05-05 01:17:21 -0700 |
|---|---|---|
| committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-05-05 01:41:30 -0700 |
| commit | 4ce0dd74b36af9f96747da650aed84bbe93c76df (patch) | |
| tree | b987ef074d9b80c8d9d7f31796979e6955d7f495 /lib/Crypto | |
| parent | 1a19b607881311e7a30bbedab2bb49fa45019250 (diff) | |
| download | pycrypto-4ce0dd74b36af9f96747da650aed84bbe93c76df.tar.gz | |
Fix LP#1132550: Expect uppercase 'IV' kwarg instead of lowercase 'iv' for MODE_OPENPGP
For most modes, the IV is passed as a kward named 'IV' (uppercase), but
for MODE_OPENPGP, it needed to be 'iv' (lowercase).
This change does not affect the use of positional arguments with
MODE_OPENPGP, and it does not affect the other modes.
Bug report: https://bugs.launchpad.net/pycrypto/+bug/1132550
Diffstat (limited to 'lib/Crypto')
| -rw-r--r-- | lib/Crypto/Cipher/blockalgo.py | 19 | ||||
| -rw-r--r-- | lib/Crypto/pct_warnings.py | 3 |
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/Crypto/Cipher/blockalgo.py b/lib/Crypto/Cipher/blockalgo.py index dd183dc..8f78cc8 100644 --- a/lib/Crypto/Cipher/blockalgo.py +++ b/lib/Crypto/Cipher/blockalgo.py @@ -26,6 +26,9 @@ if sys.version_info[0] == 2 and sys.version_info[1] == 1: from Crypto.Util.py21compat import * from Crypto.Util.py3compat import * +import warnings +from Crypto.pct_warnings import LowercaseIV_DeprecationWarning + #: *Electronic Code Book (ECB)*. #: This is the simplest encryption mode. Each of the plaintext blocks #: is directly encrypted into a ciphertext block, independently of @@ -150,10 +153,20 @@ class BlockAlgo: self._done_first_block = False self._done_last_block = False - self.IV = _getParameter('iv', 1, args, kwargs) + self.IV = _getParameter('IV', 1, args, kwargs) if not self.IV: - raise ValueError("MODE_OPENPGP requires an IV") - + # XXX - When MODE_OPENPGP was introduced in PyCrypto 2.6, it + # expected a lowercase 'iv' kwarg, but every other block cipher + # module expected uppercase 'IV'. For backward-compatibility, + # we'll support the old form for a release or two, then remove + # it. + self.IV = _getParameter('iv', 1, args, kwargs) + if self.IV: + warnings.warn("lowercase 'iv' kwarg will be removed in a future version of PyCrypto", + LowercaseIV_DeprecationWarning, 4) + else: + raise ValueError("MODE_OPENPGP requires an IV") + # Instantiate a temporary cipher to process the IV IV_cipher = factory.new(key, MODE_CFB, b('\x00')*self.block_size, # IV for CFB diff --git a/lib/Crypto/pct_warnings.py b/lib/Crypto/pct_warnings.py index 9b4361e..10cf33a 100644 --- a/lib/Crypto/pct_warnings.py +++ b/lib/Crypto/pct_warnings.py @@ -52,6 +52,9 @@ class GetRandomNumber_DeprecationWarning(CryptoDeprecationWarning): class PowmInsecureWarning(CryptoRuntimeWarning): """Warning for when _fastmath is built without mpz_powm_sec""" +class LowercaseIV_DeprecationWarning(CryptoDeprecationWarning): + """Issued when lowercase 'iv' kwarg is passed to a block cipher""" + # By default, we want this warning to be shown every time we compensate for # clock rewinding. import warnings as _warnings |
