Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/Cryptodome/Cipher/__pycache__/_mode_ofb.cpython-39.pyc
Ðазад
a c�h=( � @ sp d Z dgZddlmZ ddlmZmZmZmZm Z m Z mZmZ ddl mZ edd�ZG dd� de�Zd d � ZdS )z Output Feedback (CFB) mode. �OfbMode� )�_copy_bytes)�load_pycryptodome_raw_lib�VoidPointer�create_string_buffer�get_raw_buffer�SmartPointer�c_size_t�c_uint8_ptr�is_writeable_buffer)�get_random_byteszCryptodome.Cipher._raw_ofba int OFB_start_operation(void *cipher, const uint8_t iv[], size_t iv_len, void **pResult); int OFB_encrypt(void *ofbState, const uint8_t *in, uint8_t *out, size_t data_len); int OFB_decrypt(void *ofbState, const uint8_t *in, uint8_t *out, size_t data_len); int OFB_stop_operation(void *state); c @ s, e Zd ZdZdd� Zd dd�Zd dd�ZdS )r a� *Output FeedBack (OFB)*. This mode is very similar to CBC, but it transforms the underlying block cipher into a stream cipher. The keystream is the iterated block encryption of the previous ciphertext block. An Initialization Vector (*IV*) is required. See `NIST SP800-38A`_ , Section 6.4. .. _`NIST SP800-38A` : http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf :undocumented: __init__ c C s� t � | _t�|�� t|�tt|��| j�� �}|r>t d| ��t | j�� tj�| _|�� t|�| _ tdd|�| _| j| _| j| jg| _dS )aS Create a new block cipher, configured in OFB mode. :Parameters: block_cipher : C pointer A smart pointer to the low-level block cipher instance. iv : bytes/bytearray/memoryview The initialization vector to use for encryption or decryption. It is as long as the cipher block. **The IV must be a nonce, to to be reused for any other message**. It shall be a nonce or a random value. Reusing the *IV* for encryptions performed with the same key compromises confidentiality. z)Error %d while instantiating the OFB modeN)r �_state�raw_ofb_libZOFB_start_operation�getr r �lenZ address_of� ValueErrorr ZOFB_stop_operation�release� block_sizer �iv�IV�encrypt�decrypt�_next)�selfZblock_cipherr �result� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/Cryptodome/Cipher/_mode_ofb.py�__init__I s$ �� � zOfbMode.__init__Nc C s� | j | jvrtd��| j g| _|du r4tt|��}n4|}t|�sHtd��t|�t|�krhtdt|� ��t�| j � � t|�t|�tt|���}|r�td| ��|du r�t |�S dS dS )a� Encrypt data with the key and the parameters set at initialization. A cipher object is stateful: once you have encrypted a message you cannot encrypt (or decrypt) another message using the same object. The data to encrypt can be broken up in two or more pieces and `encrypt` can be called multiple times. That is, the statement: >>> c.encrypt(a) + c.encrypt(b) is equivalent to: >>> c.encrypt(a+b) This function does not add any padding to the plaintext. :Parameters: plaintext : bytes/bytearray/memoryview The piece of data to encrypt. It can be of any length. :Keywords: output : bytearray/memoryview The location where the ciphertext must be written to. If ``None``, the ciphertext is returned. :Return: If ``output`` is ``None``, the ciphertext is returned as ``bytes``. Otherwise, ``None``. z*encrypt() cannot be called after decrypt()N�4output must be a bytearray or a writeable memoryview�9output must have the same length as the input (%d bytes)z%Error %d while encrypting in OFB mode)r r � TypeErrorr r r r r ZOFB_encryptr r r r r )r � plaintext�output� ciphertextr r r r r y s, ! � �zOfbMode.encryptc C s� | j | jvrtd��| j g| _|du r4tt|��}n4|}t|�sHtd��t|�t|�krhtdt|� ��t�| j � � t|�t|�tt|���}|r�td| ��|du r�t |�S dS dS )a� Decrypt data with the key and the parameters set at initialization. A cipher object is stateful: once you have decrypted a message you cannot decrypt (or encrypt) another message with the same object. The data to decrypt can be broken up in two or more pieces and `decrypt` can be called multiple times. That is, the statement: >>> c.decrypt(a) + c.decrypt(b) is equivalent to: >>> c.decrypt(a+b) This function does not remove any padding from the plaintext. :Parameters: ciphertext : bytes/bytearray/memoryview The piece of data to decrypt. It can be of any length. :Keywords: output : bytearray/memoryview The location where the plaintext is written to. If ``None``, the plaintext is returned. :Return: If ``output`` is ``None``, the plaintext is returned as ``bytes``. Otherwise, ``None``. z*decrypt() cannot be called after encrypt()Nr r z%Error %d while decrypting in OFB mode)r r r r r r r r ZOFB_decryptr r r r r )r r# r"