
    9i                     |    S SK Jr  S SKJrJrJrJrJrJrJ	r	J
r
  S SKJr  \" SS5      r " S S5      rSS	 jrS
rSrg)    )_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Crypto.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                   2    \ rS rSrSrS rSS jrSS jrSrg)	Salsa20Cipher.   zSalsa20 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   [        U5      [        ;  a  [        S[        U5      -  5      e[        U5      S:w  a  [        S[        U5      -  5      e[        SSU5      U l        [        5       U l        [        R                  [        U5      [        [        U5      5      [        U5      [        [        U5      5      U R                  R                  5       5      nU(       a  [        S5      e[        U R                  R                  5       [        R                  5      U l        SU l        [        U5      U l        g)zIInitialize 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/land-doc-ocr/venv/lib/python3.13/site-packages/Crypto/Cipher/Salsa20.py__init__Salsa20Cipher.__init__6   s    
 s88#JSQTXUVVu:?L Z( ) ) !tU3
!m!55#C( S*#E* U,..02 FGG"4;;??#4#3#J#JL C    Nc           
         Uc  [        [        U5      5      nOLUn[        U5      (       d  [        S5      e[        U5      [        U5      :w  a  [	        S[        U5      -  5      e[
        R                  U R                  R                  5       [        U5      [        U5      [        [        U5      5      5      nU(       a  [	        SU-  5      eUc  [        U5      $ g)ac  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!   encryptSalsa20Cipher.encryptS   s     >-c)n=JJ&v.. VWW9~V,  "025i."A B B "88)-):)4Y)?)4Z)@)1#i.)A	C
 ENOO>!*--r$   c                      U R                  XS9$ ! [         a)  n[        [        U5      R                  SS5      5      eSnAff = f)aa  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!   decryptSalsa20Cipher.decrypty   sB    	;<<
<:: 	;SV^^E59::	;s    
A$?A)r   r   r   r   N)	__name__
__module____qualname____firstlineno____doc__r"   r+   r3   __static_attributes__ r$   r!   r   r   .   s    !:$L;r$   r   Nc                 4    Uc  [        S5      n[        X5      $ )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:`Crypto.Cipher.Salsa20.Salsa20Cipher` object
r   )r   r   )r   r   s     r!   newr>      s    " } #$$r$   r   )       r5   )Crypto.Util.py3compatr   Crypto.Util._raw_apir   r   r   r   r   r	   r
   r   Crypto.Randomr   r   r   r>   r   r   r<   r$   r!   <module>rD      sT   2 .D D D +,-E	 [; [;|%. 
 r$   