
    e                         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y)    )	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y
)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                    t        |      dk7  rt        d      t        |      dk7  rt        d      d | _        t               }t        j                  |j                         t        |      t        t        |            t        |      t        t        |                  }|rt        d|z        t        |j                         t        j                        | _        |r| j                  |       y y )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         :/usr/lib/python3/dist-packages/Cryptodome/Hash/Poly1305.py__init__zPoly1305_MAC.__init__?   s    q6R<?@@q6R<?@@,,U-=-=-?-8^-5c!f-=-8^-5c!f-=	/ DvMNN"599;#0#A#ACKK     c           	          | j                   rt        d      t        j                  | j                  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   sd     ==VWW..t{{/@/:4/@/7D	/BD CfLMMr&   c                     t               )N)NotImplementedError)r   s    r$   copyzPoly1305_MAC.copyg   s    !##r&   c           	      "   | j                   r| j                   S t        d      }t        j                  | j                  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   sx     ==== "2&..t{{/@/2/7C/AC FOPP&s+}}r&   c           	          dj                  t        | j                               D cg c]  }dt        |      z   c}      S c c}w )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
         z%02x)jointupler0   r   )r   xs     r$   	hexdigestzPoly1305_MAC.hexdigest   sD     ww!&t{{}!57 a( 7 8 	8 7s   Ac                     t        d      }t        j                  d||      }t        j                  d|| j                               }|j                         |j                         k7  rt	        d      y)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   newr0   r   )r   mac_tagsecretmac1mac2s        r$   verifyzPoly1305_MAC.verify   s]     ""%{{sWE{{sT[[]K;;=DKKM)/00 *r&   c                 J    | j                  t        t        |                   y)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)r@   r   r   )r   hex_mac_tags     r$   	hexverifyzPoly1305_MAC.hexverify   s     	Igk234r&   N)__name__
__module____qualname____doc__digest_sizer%   r   r,   r0   r6   r@   rC    r&   r$   r   r   5   s1     K."$,	81(5r&   r   c                  z   | j                  dd      }t        |d      st        d      | j                  dd      }|t        d      | j                  dd      }| j                  dd      }| rt        d	t	        |       z         |j                  ||      \  }}}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(   strrL   r   r   rM   )kwargsrK   
cipher_keyrM   r!   r   r    new_macs           r$   r;   r;      s    . ZZ$'F667EFFE4(J9::JJw%E::fd#D.V<==22:uEKAq%1a&GdE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;   rI   r&   r$   <module>rZ      sM   .  @ @ # ./ / / **E"w56 w5v)r&   