
    ¿ig                         d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZ  edd          Z G d d          Zdd	Zd
ZdZdS )    )_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_byteszCryptodome.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                   (    e Zd ZdZd ZddZddZdS )Salsa20CipherzSalsa20 cipher object. Do not create it directly. Use :py:func:`new`
    instead.

    :var nonce: The nonce with length 8
    :vartype nonce: byte string
    c           
         t          |          t          vrt          dt          |          z            t          |          dk    rt          dt          |          z            t          dd|          | _        t                      | _        t                              t          |          t          t          |                    t          |          t          t          |                    | j                                                  }|rt          d          t          | j                                        t          j                  | _        d| _        t          |          | _        dS )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_libSalsa20_stream_initr
   r	   
address_ofr   getSalsa20_stream_destroy
block_size)selfkeyr   results       U/var/www/html/afkarena/venv/lib/python3.11/site-packages/Cryptodome/Cipher/Salsa20.py__init__zSalsa20Cipher.__init__6   s;   
 s888##JSQTXXUVVVu::??L ZZ( ) ) ) !tU33
!mm!55#C(( S**#E** U,,..002 2  	HFGGG"4;??#4#4#3#JL L C    Nc           
         |t          t          |                    }n_|}t          |          st          d          t          |          t          |          k    rt	          dt          |          z            t
                              | j                                        t          |          t          |          t          t          |                              }|rt	          d|z            |t          |          S 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``.
        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   Salsa20_stream_encryptr   r   r
   r	   r   )r   	plaintextoutput
ciphertextr   s        r    encryptzSalsa20Cipher.encryptS   s	    >-c)nn==JJJ&v.. X VWWW9~~V,,  "025i.."A B B B "88)-):):)4Y)?)?)4Z)@)@)1#i..)A)A	C C
  	PENOOO>!*---4r"   c                     	 |                      ||          S # t          $ r5}t          t          |                              dd                    d}~ww xY 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'   encdecN)r)   r   strreplace)r   r(   r'   es       r    decryptzSalsa20Cipher.decrypty   s^    	;<<
6<::: 	; 	; 	;SVV^^E599:::	;s    
A0AAN)__name__
__module____qualname____doc__r!   r)   r0    r"   r    r   r   .   sV         ! ! !:$ $ $ $L; ; ; ; ; ;r"   r   Nc                 D    |t          d          }t          | |          S )a)  Create a new Salsa20 cipher

    :keyword key: The secret key to use. It must be 16 or 32 bytes long.
    :type key: bytes/bytearray/memoryview

    :keyword nonce:
        A value that must never be reused for any other encryption
        done with this key. It must be 8 bytes long.

        If not provided, a random byte string will be generated (you can read
        it back via the ``nonce`` attribute of the returned object).
    :type nonce: bytes/bytearray/memoryview

    :Return: a :class:`Cryptodome.Cipher.Salsa20.Salsa20Cipher` object
    Nr   )r   r   )r   r   s     r    newr8      s&    " } ##e$$$r"   r   )       r1   )Cryptodome.Util.py3compatr   Cryptodome.Util._raw_apir   r   r   r   r   r	   r
   r   Cryptodome.Randomr   r   r   r8   r   r   r6   r"   r    <module>r>      s  2 2 1 1 1 1 1D D D D D D D D D D D D D D D D D D D D / . . . . .,,-I	 	 [; [; [; [; [; [; [; [;|% % % %. 
 r"   