Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/Crypto/Cipher/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/Crypto/Cipher/__pycache__/blockalgo.cpython-35.pyc



Bd\R41�@s�dZddlZejddkrBejddkrBddlTddlTdZdZdZdZdZ	d	Z
d
Zddd�ZGd
d�d�Z
dS)z4Module with definitions common to all block ciphers.�N��)�*�����cCsK|j|�}t|�|krA|r7td|��||}|pJ|S)zFFind a parameter in tuple and dictionary arguments a function receivesz!Parameter '%s' is specified twice)�get�len�
ValueError)�name�index�args�kwargs�defaultZparam�r�J/opt/alt/python35/lib64/python3.5/site-packages/Crypto/Cipher/blockalgo.py�
_getParameter|s
rc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�	BlockAlgoz)Class modelling an abstract block cipher.cOs@tdd||dt�|_|j|_|jtkrc|j|||�|_|jj|_n�d|_d|_	tdd||�|_|js�t
d��|j|ttd�|jd	|jd
�}t
|j�|jkr8|j|j|jdd�td�|jd�d|jd�|_n�t
|j�|jdkr�|j|_|j|jtd�|jd�d|jd�|_|jdd�|jdd�kr�t
d
��|jdd�|_n t
d|j|jdf��|j|t|j|jd�d	|jd
�|_dS)N�moderrFZivrzMODE_OPENPGP requires an IV�Zsegment_size�rrz%Failed integrity check for OPENPGP IVz4Length of IV must be %d or %d bytes for MODE_OPENPGP���r���rr)r�MODE_ECBr�
block_size�MODE_OPENPGP�new�_cipherZIV�_done_first_block�_done_last_blockr�MODE_CFB�br�encrypt�
_encrypted_IV�decrypt)�self�factory�keyrrZ	IV_cipherrrr�__init__�s>				&zBlockAlgo.__init__cCs�|jtkr�|jt|�|j|j}|dkr�|jrWtd|j��d|_|td�|}|jj|�dt|��}n|jj|�}|j	s�|j
|}d|_	|S|jj|�S)aXEncrypt 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.
        rzFOnly the last chunk is allowed to have length not multiple of %d bytesTrN)rrrrr!rr#rr$r r%)r'Z	plaintext�padding_length�padded�resrrrr$�s'!		%	
	zBlockAlgo.encryptcCs�|jtkr�|jt|�|j|j}|dkr�|jrWtd|j��d|_|td�|}|jj|�dt|��}n|jj|�}|S|jj|�S)a�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*).
        rzFOnly the last chunk is allowed to have length not multiple of %d bytesTrN)	rrrrr!rr#rr&)r'Z
ciphertextr+r,r-rrrr&�s"!		%zBlockAlgo.decryptN)�__name__�
__module__�__qualname__�__doc__r*r$r&rrrrr�s3;r)r1�sys�version_infoZCrypto.Util.py21compatZCrypto.Util.py3compatrZMODE_CBCr"ZMODE_PGPZMODE_OFBZMODE_CTRrrrrrrr�<module>s&