File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Cipher/__pycache__/ChaCha20.cpython-310.pyc
Back
o ;jk* � @ 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 |�dksJ �td�}t�t| �t|�t|��}|r)td| ��|S )N� � z,Error %d when deriving subkey with HChaCha20)�len� bytearray�_raw_chacha20_libZ hchacha20r � ValueError)�key�nonceZsubkey�result� r �N/opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Cipher/ChaCha20.py� _HChaCha20C 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 dd|�| _t|�dkr"t||dd� �}d|dd� }d| _nd| _| j}d| _t� | _t� | j� � t|�tt|��|tt|���}|rPt d|| jf ��t| j�� tj�| _dS ) z\Initialize a ChaCha20/XChaCha20 cipher object See also `new()` at the module level.N� r � Z XChaCha20ZChaCha20)�encrypt�decryptz"Error %d instantiating a %s cipher)r r r r �_name�_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$ d| j vr td��d| _ | �||�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``. r 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|��}n|}t|�std��t|�t|�kr%tdt|� ��t�| j�� t |�t |�t t|���}|rCtd|| jf ��|du rKt|�S 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% r r Zchacha20_encryptr! r"