Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/Cryptodome/Cipher/__pycache__/Salsa20.cpython-39.pyc
Ðазад
a c�h� � @ sn d dl mZ d dlmZmZmZmZmZmZm Z m Z d dlmZ edd�Z G dd� d�Zd d d �ZdZdZdS )� )�_copy_bytes)�load_pycryptodome_raw_lib�create_string_buffer�get_raw_buffer�VoidPointer�SmartPointer�c_size_t�c_uint8_ptr�is_writeable_buffer)�get_random_byteszCryptodome.Cipher._Salsa20a� int Salsa20_stream_init(uint8_t *key, size_t keylen, uint8_t *nonce, size_t nonce_len, void **pSalsaState); int Salsa20_stream_destroy(void *salsaState); int Salsa20_stream_encrypt(void *salsaState, const uint8_t in[], uint8_t out[], size_t len); c @ s, e Zd ZdZdd� Zd dd�Zd dd�ZdS )� Salsa20Cipherz�Salsa20 cipher object. Do not create it directly. Use :py:func:`new` instead. :var nonce: The nonce with length 8 :vartype nonce: byte string c C s� t |�tvrtdt |� ��t |�dkr8tdt |� ��tdd|�| _t� | _t�t |�t t |��t |�t t |��| j�� �}|r�td��t| j� � tj�| _d| _t |�| _dS )zQInitialize a Salsa20 cipher object See also `new()` at the module level.z+Incorrect key length for Salsa20 (%d bytes)� z-Incorrect nonce length for Salsa20 (%d bytes)Nz'Error %d instantiating a Salsa20 cipher� )�len�key_size� ValueErrorr �noncer �_state�_raw_salsa20_libZSalsa20_stream_initr r Z address_ofr �getZSalsa20_stream_destroy� block_size)�self�keyr �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/Salsa20.py�__init__6 s, � � �zSalsa20Cipher.__init__Nc C s� |du rt t|��}n4|}t|�s*td��t|�t|�krJtdt|� ��t�| j�� t |�t |�t t|���}|r�td| ��|du r�t|�S dS dS )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``. Nz4output must be a bytearray or a writeable memoryviewz9output must have the same length as the input (%d bytes)z&Error %d while encrypting with Salsa20)r r r � TypeErrorr r ZSalsa20_stream_encryptr r r r r )r Z plaintext�output� ciphertextr r r r �encryptS s( � �zSalsa20Cipher.encryptc C sN z| j ||d�W S tyH } z tt|��dd���W Y d}~n d}~0 0 dS )a� Decrypt a piece of data. Args: ciphertext(bytes/bytearray/memoryview): The data to decrypt, of any size. Keyword Args: output(bytes/bytearray/memoryview): The location where the plaintext is written to. If ``None``, the plaintext is returned. Returns: If ``output`` is ``None``, the plaintext is returned as ``bytes``. Otherwise, ``None``. )r �enc�decN)r r �str�replace)r r r �er r r �decrypty s zSalsa20Cipher.decrypt)N)N)�__name__� __module__�__qualname__�__doc__r r r&