Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/Cryptodome/Cipher/__pycache__/ChaCha20.cpython-39.pyc
Ðазад
a c�h* � @ s� d dl mZ d dlmZ d dlmZmZmZmZm Z m Z mZmZm Z edd�Zdd� ZG dd � d e�Zd d� Zdd � ZdZdZdS )� )�get_random_bytes)�_copy_bytes) �load_pycryptodome_raw_lib�create_string_buffer�get_raw_buffer�VoidPointer�SmartPointer�c_size_t�c_uint8_ptr�c_ulong�is_writeable_bufferzCryptodome.Cipher._chacha20a� int chacha20_init(void **pState, const uint8_t *key, size_t keySize, const uint8_t *nonce, size_t nonceSize); int chacha20_destroy(void *state); int chacha20_encrypt(void *state, const uint8_t in[], uint8_t out[], size_t len); int chacha20_seek(void *state, unsigned long block_high, unsigned long block_low, unsigned offset); int hchacha20( const uint8_t key[32], const uint8_t nonce16[16], uint8_t subkey[32]); c C sV t | �dksJ �t |�dks J �td�}t�t| �t|�t|��}|rRtd| ��|S )N� � z,Error %d when deriving subkey with HChaCha20)�len� bytearray�_raw_chacha20_libZ hchacha20r � ValueError)�key�nonce�subkey�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/ChaCha20.py� _HChaCha20B s �r c @ s@ e Zd ZdZdZdd� Zddd�Zdd � Zdd d�Zdd � Z dS )�ChaCha20Cipherz�ChaCha20 (or XChaCha20) cipher object. Do not create it directly. Use :py:func:`new` instead. :var nonce: The nonce with length 8, 12 or 24 bytes :vartype nonce: bytes � c C s� t |�dkr6t||dd� �}d|dd� }d| _nd| _tdd|�| _| j| jf| _t� | _ t �| j �� t |�tt |��| jtt |���}|r�td|| jf ��t| j �� t j�| _ dS )z\Initialize a ChaCha20/XChaCha20 cipher object See also `new()` at the module level.� Nr � Z XChaCha20ZChaCha20z"Error %d instantiating a %s cipher)r r �_namer r �encrypt�decrypt�_nextr �_stater Z chacha20_initZ address_ofr r r r �getZchacha20_destroy)�selfr r r r r r �__init__\ s, �� �zChaCha20Cipher.__init__Nc C s* | j | jvrtd��| j f| _| �||�S )a� Encrypt a piece of data. Args: plaintext(bytes/bytearray/memoryview): The data to encrypt, of any size. Keyword Args: output(bytes/bytearray/memoryview): The location where the ciphertext is written to. If ``None``, the ciphertext is returned. Returns: If ``output`` is ``None``, the ciphertext is returned as ``bytes``. Otherwise, ``None``. z-Cipher object can only be used for decryption)r r! � TypeError�_encrypt)r$ � plaintext�outputr r r r { s zChaCha20Cipher.encryptc C s� |du rt t|��}n4|}t|�s*td��t|�t|�krJtdt|� ��t�| j�� t |�t |�t t|���}|r�td|| jf ��|du r�t|�S dS dS )zEncrypt without FSM checksNz4output must be a bytearray or a writeable memoryviewz9output must have the same length as the input (%d bytes)z!Error %d while encrypting with %s) r r r r&