Ë
    (üàgW*  ã                   óŠ   — d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZ  edd«      Zd„ Z G d„ de«      Zd	„ Zd
„ ZdZdZy)é    )Ú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_bufferzCrypto.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        | «      dk(  sJ ‚t        |«      dk(  sJ ‚t        d«      }t        j                  t	        | «      t	        |«      t	        |«      «      }|rt        d|z  «      ‚|S )Né    é   z,Error %d when deriving subkey with HChaCha20)ÚlenÚ	bytearrayÚ_raw_chacha20_libÚ	hchacha20r   Ú
ValueError)ÚkeyÚnonceÚsubkeyÚresults       úT/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/Crypto/Cipher/ChaCha20.pyÚ
_HChaCha20r   C   sp   € äˆs‹8�rŠ>Ðˆ>Üˆu‹:˜ÒÐÐä�r‹]€FÜ×(Ñ(Ü˜CÓ Ü˜EÓ"Ü˜FÓ#ó%€Fñ ÜÐGÈ&ÑPÓQÐQà€Mó    c                   ó6   — e Zd ZdZdZd„ Zd	d„Zd„ Zd	d„Zd„ Z	y)
Ú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                 ó6  — t        dd|«      | _        t        |«      dk(  rt        ||dd «      }d|dd z   }d| _        nd| _        | j                  }d| _        t        «       | _        t        j                  | j                  j                  «       t        |«      t        t        |«      «      |t        t        |«      «      «      }|rt        d|| j                  fz  «      ‚t        | j                  j                  «       t        j                   «      | _        y)	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__zChaCha20Cipher.__init__]   sþ   € ô
 !  t¨UÓ3ˆŒ
ô ˆu‹:˜ÒÜ˜S %¨¨ *Ó-ˆCØ %¨¨ *Ñ,ˆEØ$ˆD�Jà#ˆDŒJØ—J‘JˆEà+ˆŒ
ä!“mˆŒÜ"×0Ñ0ØŸ™×.Ñ.Ó0Ü# CÓ(Ü ¤ S£Ó*ØÜ ¤ U£Ó,ó.ˆñ ÜÐAÀVØEIÇZÁZðEQñ Qó Rð Rä" 4§;¡;§?¡?Ó#4Ü#4×#EÑ#EóGˆ�r   Nc                 óf   — d| j                   vrt        d«      ‚d| _         | j                  ||«      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%   zChaCha20Cipher.encrypt}   s4   € ð ˜DŸJ™JÑ&ÜÐKÓLÐLØ!ˆŒ
Ø�}‰}˜Y¨Ó/Ð/r   c           
      ó¸  — |€t        t        |«      «      }nF|}t        |«      st        d«      ‚t        |«      t        |«      k7  rt	        dt        |«      z  «      ‚t
        j                  | j                  j                  «       t        |«      t        |«      t        t        |«      «      «      }|rt	        d|| j                  fz  «      ‚|€t        |«      S y)zEncrypt 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   zChaCha20Cipher._encrypt�   sÐ   € ð ˆ>Ü-¬c°)«nÓ=‰JàˆJä& vÔ.ÜÐ VÓWÐWä�9‹~¤ V£Ò,Ü ð "0Ü25°i³.ñ"Aó Bð Bô #×3Ñ3Ø)-¯©¯©Ó):Ü)4°YÓ)?Ü)4°ZÓ)@Ü)1´#°i³.Ó)Aó	Cˆñ
 ÜÐ@ÀFÈDÏJÉJÐCWÑWÓXÐXàˆ>Ü! *Ó-Ð-àr   c                 óÒ   — d| j                   vrt        d«      ‚d| _         	 | j                  ||«      S # t        $ r)}t        t	        |«      j                  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&   z-Cipher object can only be used for encryption)r&   ÚencÚdecN)r(   r1   r2   r   ÚstrÚreplace)r.   r7   r4   Úes       r   r&   zChaCha20Cipher.decrypt«   sc   € ð ˜DŸJ™JÑ&ÜÐKÓLÐLØ!ˆŒ
ð	;Ø—=‘= ¨VÓ4Ð4øÜò 	;ÜœS ›VŸ^™^¨E°5Ó9Ó:Ð:ûð	;ús   ¢4 ´	A&½$A!Á!A&c                 óò   — t        |d«      \  }}|dz  }|dz	  }t        j                  | j                  j	                  «       t        |«      t        |«      |«      }|rt        d|| j                  fz  «      ‚y)a   Seek to a certain position in the key stream.

        If you want to seek to a certain block,
        use ``seek(block_number * 64)``.

        Args:
          position (integer):
            The absolute position within the key stream, in bytes.
        é@   l   ÿÿ r   zError %d while seeking with %sN)Údivmodr   Úchacha20_seekr)   r,   r   r   r'   )r.   ÚpositionÚblock_numberÚoffsetÚ	block_lowÚ
block_highr   s          r   ÚseekzChaCha20Cipher.seekÁ   s~   € ô  & h°Ó3Ñˆ�fØ  :Ñ-ˆ	Ø! RÑ'ˆ
ä"×0Ñ0Ø15·±·±Ó1BÜ18¸Ó1DÜ18¸Ó1CØ17ó	3ˆñ ÜÐ=ÀÈÏÉÐ@TÑTÓUÐUð r   )N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
block_sizer/   r%   r2   r&   rG   © r   r   r   r   S   s*   „ ñð €JòGó@0ò$ó8;ó,Vr   r   c                 ó  — t        | «      dk7  rt        d«      ‚|€t        d«      x}}n0t        |«      dk(  rd|z   }nt        |«      dk(  r|}nt        d«      ‚t        | |¬«      j	                  d	«      }|dd
 |d
d |fS )zrDerive a tuple (r, s, nonce) for a Poly1305 MAC.

    If nonce is ``None``, a new 12-byte nonce is generated.
    r   z-Poly1305 with ChaCha20 requires a 32-byte keyNé   é   r"   z6Poly1305 with ChaCha20 requires an 8- or 12-byte nonce)r   r   s                                    r   )r   r   r   Únewr%   )r   r   Úpadded_nonceÚrss       r   Ú_derive_Poly1305_key_pairrT   Ú   s“   € ô ˆ3ƒx�2‚~ÜÐHÓIÐIà€}Ü/°Ó3Ð3ˆ‘uÜ	ˆU‹�qŠð +¨UÑ2‰Ü	ˆU‹�rÒ	Ø‰äÐQÓRÐRä	�˜LÔ	)×	1Ñ	1°,Ó	?€BØˆcˆrˆ7�B�r�s�G˜UÐ"Ð"r   c                  óN  — 	 | j                  d«      }| j                  dd«      }|€t        d«      }t	        |«      dk7  rt        d«      ‚t	        |«      dvrt        d	«      ‚| rt        d
t        | «      z   «      ‚t        ||«      S # t        $ r}t        d|z  «      ‚d}~ww xY w)a}  Create a new ChaCha20 or XChaCha20 cipher

    Keyword Args:
        key (bytes/bytearray/memoryview): The secret key to use.
            It must be 32 bytes long.
        nonce (bytes/bytearray/memoryview): A mandatory value that
            must never be reused for any other encryption
            done with this key.

            For ChaCha20, it must be 8 or 12 bytes long.

            For XChaCha20, it must be 24 bytes long.

            If not provided, 8 bytes will be randomly generated
            (you can find them back in the ``nonce`` attribute).

    :Return: a :class:`Crypto.Cipher.ChaCha20.ChaCha20Cipher` object
    r   zMissing parameter %sNr   rP   r   z,ChaCha20/XChaCha20 key must be 32 bytes long)rP   rO   r!   z:Nonce must be 8/12 bytes(ChaCha20) or 24 bytes (XChaCha20)zUnknown parameters: )ÚpopÚKeyErrorr1   r   r   r   r;   r   )Úkwargsr   r=   r   s       r   rQ   rQ   ÷   s­   € ð(4Ø�j‰j˜Óˆð �J‰J�w Ó%€EØ€}Ü  Ó#ˆä
ˆ3ƒx�2‚~ÜÐGÓHÐHä
ˆ5ƒz˜Ñ$ÜÐUÓVÐVáÜÐ.´°V³Ñ<Ó=Ð=ä˜#˜uÓ%Ð%øô! ò 4ÜÐ.°Ñ2Ó3Ð3ûð4ús   ‚B Â	B$ÂBÂB$r   r   N)ÚCrypto.Randomr   ÚCrypto.Util.py3compatr   ÚCrypto.Util._raw_apir   r   r   r   r	   r
   r   r   r   r   r   Úobjectr   rT   rQ   rL   Úkey_sizerM   r   r   ú<module>r^      s`   ðõ> +å -÷7÷ 7õ 7ñ .Ð.GðóÐ ò4ô DV�Vô DVòN#ò:&&ðR €
ð �r   