j% d dl mZ d dlmZ d dlmZmZmZmZm Z m Z mZmZm Z edd Zd Z G d de Zd Zd ZdZdZd S ) )get_random_bytes)_copy_bytes) load_pycryptodome_raw_libcreate_string_bufferget_raw_bufferVoidPointerSmartPointerc_size_tc_uint8_ptrc_ulongis_writeable_bufferzCrypto.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 & t | dk sJ t | dk sJ t d }t t | t | t | }|rt d|z |S )N z,Error %d when deriving subkey with HChaCha20)len bytearray_raw_chacha20_lib hchacha20r ValueError)keynoncesubkeyresults x/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Cipher/ChaCha20.py _HChaCha20r B s s88r>>>>u:: r]]F ( (C E""F##% %F RG&PQQQM c 8 e Zd ZdZdZd Zd dZd Zd dZd Z dS ) ChaCha20CipherzChaCha20 (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 t dd| | _ t | dk r-t ||dd }d|dd z }d| _ nd| _ | j }d| _ t | _ t | j t | t t | |t t | }|rt d|| j fz t | j t j | _ dS ) z\Initialize a ChaCha20/XChaCha20 cipher object See also `new()` at the module level.N r XChaCha20ChaCha20)encryptdecryptz"Error %d instantiating a %s cipher)r r r r _name_nextr _stater chacha20_init address_ofr r r r getchacha20_destroy)selfr r r s r __init__zChaCha20Cipher.__init__\ s4 !tU33 u::S%*--C%*,E$DJJ#DJJE+ !mm"00..00#C(( S** U,,. . RAVEIZEQ Q R R R"4;??#4#4#4#EG Gr Nc l d| j vrt d 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. plaintextoutputs r r% zChaCha20Cipher.encrypt| s; DJ&&KLLL! }}Y///r c * |t t | }n_|}t | st d t | t | k rt dt | z t | j t | t | t t | }|rt d|| j fz |t | 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 r1 r r chacha20_encryptr) r, r r r' r )r. r3 r4 ciphertextr s r r2 zChaCha20Cipher._encrypt s >-c)nn==JJJ&v.. X VWWW9~~V,, "025i.."A B B B #33)-):):)4Y)?)?)4Z)@)@)1#i..)A)A C C Y@FDJCWWXXX>!*---4r c d| j vrt d d| _ | || S # t $ r5}t t | dd d}~ww xY w)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&