File: //opt/alt/python38/lib64/python3.8/site-packages/Crypto/Cipher/__pycache__/blockalgo.cpython-38.pyc
U
Bd\R41 � @ sp d Z ddlZejd dkr0ejd dkr0ddlT ddlT dZdZdZdZdZ d Z
d
Zddd�ZG d
d� d�Z
dS )z4Module with definitions common to all block ciphers.� N� � )�*� � � � � c C s6 |� | �}t|�|kr.|r&td| ��|| }|p4|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/python38/lib64/python3.8/site-packages/Crypto/Cipher/blockalgo.py�
_getParameter| s
r c @ s( e Zd ZdZdd� Zdd� Zdd� ZdS ) � BlockAlgoz)Class modelling an abstract block cipher.c O s� t dd||td�| _|j| _| jtkrH|j|f|�|�| _| jj| _�n^d| _d| _ t dd||�| _| jsrt
d��|j|ttd�| j | jd d
�}t
| j�| jkr�|�| j| jdd � td�| jd �d | jd � | _n�t
| j�| jd k�rf| j| _|�| jtd�| jd �d | jd � | _| jdd � | jd
d� k�rTt
d��| jd d� | _nt
d| j| jd f ��|j|t| j| j d � | jd d
�| _d S )N�moder )r FZivr zMODE_OPENPGP requires an IV� � )Zsegment_size���r ���z%Failed integrity check for OPENPGP IVz4Length of IV must be %d or %d bytes for MODE_OPENPGP)r �MODE_ECBr �
block_size�MODE_OPENPGP�new�_cipherZIV�_done_first_block�_done_last_blockr �MODE_CFB�br �encrypt�
_encrypted_IV�decrypt)�self�factory�keyr r Z IV_cipherr r r �__init__� sN
����
����zBlockAlgo.__init__c C s� | j tkr�| jt|�| j | j }|dkrn| jr>td| j��d| _|td�| }| j�|�dt|�� }n| j�|�}| j s�| j
| }d| _ |S | j�|�S )aX Encrypt 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.
r �FOnly the last chunk is allowed to have length not multiple of %d bytesTr N)r r r r r! r r# r r$ r r% )r'