관리-도구
편집 파일: ChaCha20.cpython-311.pyc
� O�Dg�) � � � 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_lib�create_string_buffer�get_raw_buffer�VoidPointer�SmartPointer�c_size_t�c_uint8_ptr�c_ulong�is_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)�key�nonce�subkey�results �x/builddir/build/BUILD/imunify360-venv-2.4.0/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Cipher/ChaCha20.py� _HChaCha20r B s� � ��s�8�8�r�>�>�>�>��u�:�:������ �r�]�]�F� � (� (��C� � ��E�"�"��F�#�#�%� %�F� � R��G�&�P�Q�Q�Q��M� c �8 � e Zd ZdZdZd� Zd d�Zd� Zd d�Zd� 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 � � 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 � � XChaCha20�ChaCha20)�encrypt�decryptz"Error %d instantiating a %s cipher)r r r r �_name�_nextr �_stater � chacha20_init� address_ofr r r r �get�chacha20_destroy)�selfr r r s r �__init__zChaCha20Cipher.__init__\ s4 � � !��t�U�3�3�� � �u�:�:�����S�%����*�-�-�C��%����*�,�E�$�D�J�J�#�D�J��J�E�+�� �!�m�m���"�0�0���.�.�0�0�#�C�(�(� ��S���*�*�� ��U���,�,�.� .�� � R��A�V�EI�Z�EQ� Q� R� R� R�"�4�;�?�?�#4�#4�#4�#E�G� G����r 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. � plaintext�outputs r r% zChaCha20Cipher.encrypt| s; � � �D�J�&�&��K�L�L�L�!�� ��}�}�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'