Current File : //usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.pyc
�
Bd\Rc@s�dZddlZejddkrEejddkrEddlTnddlTdZdZdZdZd	Z	d
Z
dZdd�Z
d
dd��YZdS(s4Module with definitions common to all block ciphers.i����Niii(t*iiiiicCsQ|j|�}t|�|krG|r:td|��n||}n|pP|S(sFFind a parameter in tuple and dictionary arguments a function receivess!Parameter '%s' is specified twice(tgettlent
ValueError(tnametindextargstkwargstdefaulttparam((s=/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.pyt
_getParameter|s
t	BlockAlgocBs)eZdZd�Zd�Zd�ZRS(s)Class modelling an abstract block cipher.cOstdd||dt�|_|j|_|jtkrc|j|||�|_|jj|_n�t|_	t|_
tdd||�|_|js�td��n|j|tt
d�|jd|jd	�}t|j�|jkr/|j|j|jd
t
d�|jd�|jd |_n�t|j�|jdkr�|j|_|j|jt
d�|jd�|jd |_|jd
|jdd
!kr�td
��n|jd
 |_n td|j|jdf��|j|t|j|jd|jd	�|_dS(NtmodeiRtivisMODE_OPENPGP requires an IVttsegment_sizeii����ii����s%Failed integrity check for OPENPGP IVs4Length of IV must be %d or %d bytes for MODE_OPENPGP(R
tMODE_ECBRt
block_sizetMODE_OPENPGPtnewt_ciphertIVtFalset_done_first_blockt_done_last_blockRtMODE_CFBtbRtencryptt
_encrypted_IVtdecrypt(tselftfactorytkeyRRt	IV_cipher((s=/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.pyt__init__�s>				cCs�|jtkr�|jt|�|j|j}|dkr�|jrZtd|j��nt|_|td�|}|jj	|�t|� }n|jj	|�}|j
s�|j|}t|_
n|S|jj	|�S(sXEncrypt data with the key and the parameters set at initialization.
        
        The cipher object is stateful; encryption of a long block
        of data can be broken up in two or more calls to `encrypt()`.
        That is, the statement:
            
            >>> c.encrypt(a) + c.encrypt(b)

        is always equivalent to:

             >>> c.encrypt(a+b)

        That also means that you cannot reuse an object for encrypting
        or decrypting other data with the same key.

        This function does not perform any padding.
       
         - For `MODE_ECB`, `MODE_CBC`, and `MODE_OFB`, *plaintext* length
           (in bytes) must be a multiple of *block_size*.

         - For `MODE_CFB`, *plaintext* length (in bytes) must be a multiple
           of *segment_size*/8.

         - For `MODE_CTR`, *plaintext* can be of any length.

         - For `MODE_OPENPGP`, *plaintext* must be a multiple of *block_size*,
           unless it is the last chunk of the message.

        :Parameters:
          plaintext : byte string
            The piece of data to encrypt.
        :Return:
            the encrypted data, as a byte string. It is as long as
            *plaintext* with one exception: when encrypting the first message
            chunk with `MODE_OPENPGP`, the encypted IV is prepended to the
            returned ciphertext.
        isFOnly the last chunk is allowed to have length not multiple of %d bytesR(RRRRRRtTrueRRRRR(Rt	plaintexttpadding_lengthtpaddedtres((s=/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.pyR�s'!			
cCs�|jtkr�|jt|�|j|j}|dkr�|jrZtd|j��nt|_|td�|}|jj	|�t|� }n|jj	|�}|S|jj	|�S(s�Decrypt data with the key and the parameters set at initialization.
        
        The cipher object is stateful; decryption of a long block
        of data can be broken up in two or more calls to `decrypt()`.
        That is, the statement:
            
            >>> c.decrypt(a) + c.decrypt(b)

        is always equivalent to:

             >>> c.decrypt(a+b)

        That also means that you cannot reuse an object for encrypting
        or decrypting other data with the same key.

        This function does not perform any padding.
       
         - For `MODE_ECB`, `MODE_CBC`, and `MODE_OFB`, *ciphertext* length
           (in bytes) must be a multiple of *block_size*.

         - For `MODE_CFB`, *ciphertext* length (in bytes) must be a multiple
           of *segment_size*/8.

         - For `MODE_CTR`, *ciphertext* can be of any length.

         - For `MODE_OPENPGP`, *plaintext* must be a multiple of *block_size*,
           unless it is the last chunk of the message.

        :Parameters:
          ciphertext : byte string
            The piece of data to decrypt.
        :Return: the decrypted data (byte string, as long as *ciphertext*).
        isFOnly the last chunk is allowed to have length not multiple of %d bytesR(
RRRRRRR#RRR(Rt
ciphertextR%R&R'((s=/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.pyR�s"!		(t__name__t
__module__t__doc__R"RR(((s=/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.pyR�s	3	;((R+tsystversion_infotCrypto.Util.py21compattCrypto.Util.py3compatRtMODE_CBCRtMODE_PGPtMODE_OFBtMODE_CTRRtNoneR
R(((s=/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.pyt<module>s&