[Fix LP#1176482] Restore previous behavior of the block cipher 'IV' attribute

PEP 272 describes the behavior of the block cipher 'IV' attribute as
follows:

    IV

        Contains the initial value which will be used to start a
        cipher feedback mode; it will always be a string exactly one
        block in length. After encrypting or decrypting a string,
        this value is updated to reflect the modified feedback text.
        It is read-only, and cannot be assigned a new value.

In versions of PyCrypto prior to 2.6, the implementation of the 'IV'
attribute matched this description, except that the attribute was
also writable and could modify the behavior of the cipher.

In PyCrypto 2.6, this behavior was changed: The 'IV' attribute was no
longer updated during encryptions and decryptions, and writing to it no
longer had any effect.

PyCrypto 2.5 and below:

    >>> from Crypto.Cipher import AES
    >>> ciph = AES.new("\0"*16, AES.MODE_CBC, "ABCDEFGHIJKLMNOP")
    >>> ciph.encrypt("\0"*16)
    'a\xd7\x82X\xeb\x1a\xbdo\xffG\x9d\x1d\xab\xb6\x10;'
    >>> ciph.IV
    'a\xd7\x82X\xeb\x1a\xbdo\xffG\x9d\x1d\xab\xb6\x10;'

PyCrypto 2.6:

    >>> from Crypto.Cipher import AES
    >>> ciph = AES.new("\0"*16, AES.MODE_CBC, "ABCDEFGHIJKLMNOP")
    >>> ciph.encrypt("\0"*16)
    'a\xd7\x82X\xeb\x1a\xbdo\xffG\x9d\x1d\xab\xb6\x10;'
    >>> ciph.IV
    'ABCDEFGHIJKLMNOP'

The bug was introduced at the same time that we introduced Python
wrappers around the native C objects.

Bug introduced: commit 6f9fe103a582999c397f7bc8a2248613a207b780
Bug report: https://bugs.launchpad.net/pycrypto/+bug/1176482

This commit restores the previous (PyCrypto 2.5) behavior.
2 files changed