
    ¿ig                         d dl mZ d dlmZmZmZ 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  edd          Z G d d	e          Zd
 ZdS )    )	unhexlify)bordtobytes_copy_bytes)BLAKE2s)get_random_bytes)load_pycryptodome_raw_libVoidPointerSmartPointercreate_string_bufferget_raw_bufferc_size_tc_uint8_ptrzCryptodome.Hash._poly1305a  
                        int poly1305_init(void **state,
                                          const uint8_t *r,
                                          size_t r_len,
                                          const uint8_t *s,
                                          size_t s_len);
                        int poly1305_destroy(void *state);
                        int poly1305_update(void *state,
                                            const uint8_t *in,
                                            size_t len);
                        int poly1305_digest(const void *state,
                                            uint8_t *digest,
                                            size_t len);
                        c                   @    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
S )Poly1305_MACzAn Poly1305 MAC object.
    Do not instantiate directly. Use the :func:`new` function.

    :ivar digest_size: the size in bytes of the resulting MAC tag
    :vartype digest_size: integer
       c                 p   t          |          dk    rt          d          t          |          dk    rt          d          d | _        t                      }t                              |                                t          |          t          t          |                    t          |          t          t          |                              }|rt          d|z            t          |
                                t          j                  | _        |r|                     |           d S d S )Nr   z Parameter r is not 16 bytes longz Parameter s is not 16 bytes longz%Error %d while instantiating Poly1305)len
ValueError_mac_tagr
   _raw_poly1305poly1305_init
address_ofr   r   r   getpoly1305_destroy_stateupdate)selfrsdatastateresults         T/var/www/html/afkarena/venv/lib/python3.11/site-packages/Cryptodome/Hash/Poly1305.py__init__zPoly1305_MAC.__init__?   s   q66R<<?@@@q66R<<?@@@,,U-=-=-?-?-8^^-5c!ff-=-=-8^^-5c!ff-=-=	/ /  	ODvMNNN"599;;#0#AC C 	KK	 	    c           	         | j         rt          d          t                              | j                                        t          |          t          t          |                              }|rt          d|z            | S )zAuthenticate the next chunk of message.

        Args:
            data (byte string/byte array/memoryview): The next chunk of data
        z8You can only call 'digest' or 'hexdigest' on this objectz$Error %d while hashing Poly1305 data)
r   	TypeErrorr   poly1305_updater   r   r   r   r   r   )r   r!   r#   s      r$   r   zPoly1305_MAC.updateV   s     = 	XVWWW..t{/@/@/:4/@/@/7D		/B/BD D  	NCfLMMMr&   c                     t                      )N)NotImplementedErrorr   s    r$   copyzPoly1305_MAC.copyg   s    !###r&   c           	      4   | j         r| j         S t          d          }t                              | j                                        |t          t          |                              }|rt          d|z            t          |          | _         | j         S )zReturn the **binary** (non-printable) MAC tag of the message
        authenticated so far.

        :return: The MAC tag digest, computed over the data processed so far.
                 Binary form.
        :rtype: byte string
        r   z'Error %d while creating Poly1305 digest)
r   r   r   poly1305_digestr   r   r   r   r   r   )r   bfrr#   s      r$   digestzPoly1305_MAC.digestj   s     = 	!= "2&&..t{/@/@/2/7C/A/AC C  	QFOPPP&s++}r&   c                 ~    d                     d t          |                                           D                       S )zReturn the **printable** MAC tag of the message authenticated so far.

        :return: The MAC tag, computed over the data processed so far.
                 Hexadecimal encoded.
        :rtype: string
         c                 2    g | ]}d t          |          z  S )z%02x)r   ).0xs     r$   
<listcomp>z*Poly1305_MAC.hexdigest.<locals>.<listcomp>   s3     7 7 7 a( 7 7 7r&   )jointupler1   r,   s    r$   	hexdigestzPoly1305_MAC.hexdigest   sF     ww 7 7!&t{{}}!5!57 7 7 8 8 	8r&   c                    t          d          }t          j        d||          }t          j        d||                                           }|                                |                                k    rt	          d          dS )ah  Verify that a given **binary** MAC (computed by another party)
        is valid.

        Args:
          mac_tag (byte string/byte string/memoryview): the expected MAC of the message.

        Raises:
            ValueError: if the MAC does not match. It means that the message
                has been tampered with or that the MAC key is incorrect.
        r      )digest_bitskeyr!   zMAC check failedN)r   r   newr1   r   )r   mac_tagsecretmac1mac2s        r$   verifyzPoly1305_MAC.verify   sw     ""%%{sWEEE{sT[[]]KKK;;==DKKMM))/000 *)r&   c                 d    |                      t          t          |                               dS )a~  Verify that a given **printable** MAC (computed by another party)
        is valid.

        Args:
            hex_mac_tag (string): the expected MAC of the message,
                as a hexadecimal string.

        Raises:
            ValueError: if the MAC does not match. It means that the message
                has been tampered with or that the MAC key is incorrect.
        N)rD   r   r   )r   hex_mac_tags     r$   	hexverifyzPoly1305_MAC.hexverify   s,     	Igk223344444r&   N)__name__
__module____qualname____doc__digest_sizer%   r   r-   r1   r:   rD   rG    r&   r$   r   r   5   s          K  .  "$ $ $  ,	8 	8 	81 1 1(5 5 5 5 5r&   r   c                     |                      dd          }t          |d          st          d          |                      dd          }|t          d          |                      dd          }|                      dd          }| rt          d	t	          |           z             |                    ||          \  }}}t          |||          }t          dd|          |_        |S )
a  Create a new Poly1305 MAC object.

    Args:
        key (bytes/bytearray/memoryview):
            The 32-byte key for the Poly1305 object.
        cipher (module from ``Cryptodome.Cipher``):
            The cipher algorithm to use for deriving the Poly1305
            key pair *(r, s)*.
            It can only be ``Cryptodome.Cipher.AES`` or ``Cryptodome.Cipher.ChaCha20``.
        nonce (bytes/bytearray/memoryview):
            Optional. The non-repeatable value to use for the MAC of this message.
            It must be 16 bytes long for ``AES`` and 8 or 12 bytes for ``ChaCha20``.
            If not passed, a random nonce is created; you will find it in the
            ``nonce`` attribute of the new object.
        data (bytes/bytearray/memoryview):
            Optional. The very first chunk of the message to authenticate.
            It is equivalent to an early call to ``update()``.

    Returns:
        A :class:`Poly1305_MAC` object
    cipherN_derive_Poly1305_key_pairz*Parameter 'cipher' must be AES or ChaCha20r>   zYou must pass a parameter 'key'noncer!   zUnknown parameters: )	pophasattrr   r(   strrP   r   r   rQ   )kwargsrO   
cipher_keyrQ   r!   r   r    new_macs           r$   r?   r?      s    . ZZ$''F6677 GEFFFE4((J9:::JJw%%E::fd##D >.V<===22:uEEKAq%1a&&GdE22GMNr&   N)binasciir   Cryptodome.Util.py3compatr   r   r   Cryptodome.Hashr   Cryptodome.Randomr   Cryptodome.Util._raw_apir	   r
   r   r   r   r   r   r   objectr   r?   rM   r&   r$   <module>r^      s  .       @ @ @ @ @ @ @ @ @ @ # # # # # # . . . . . ./ / / / / / / / / / / / / / / / / / *)*E "w5 w5 w5 w5 w56 w5 w5 w5v) ) ) ) )r&   