
    ¿igE                     x    d dl mZ d dlmZmZmZ d dlmZ ddlm	Z	m
Z
 ddl	mZmZmZ  G d de          Zd	 Zd
S )    )	unhexlify)bordtobytesis_bytes)get_random_bytes   )	cSHAKE128SHA3_256)_bytepad_encode_str_right_encodec                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
	KMAC_Hashz[A KMAC hash object.
    Do not instantiate directly.
    Use the :func:`new` function.
    c                     d|z   | _         || _        d | _        t          t	          t          |                    |          }|                    ||d          | _        |r| j                            |           d S d S )Nz2.16.840.1.101.3.4.2.s   KMAC)	oiddigest_size_macr   r   r   _new_cshakeupdate)	selfdatakeymac_lencustomoid_variantcshakeratepartial_newXs	            S/var/www/html/afkarena/venv/lib/python3.11/site-packages/Cryptodome/Hash/KMAC128.py__init__zKMAC_Hash.__init__.   s     +[8"	GCLL 9 94@@{{<AA 	&L%%%%%	& 	&    c                 f    | j         rt          d          | j                            |           | S )zAuthenticate the next chunk of message.

        Args:
            data (bytes/bytearray/memoryview): The next chunk of the message to
            authenticate.
        z8You can only call 'digest' or 'hexdigest' on this object)r   	TypeErrorr   r   )r   r   s     r    r   zKMAC_Hash.update=   s9     9 	XVWWWD!!!r"   c                     | j         sS| j                            t          | j        dz                       | j                            | j                  | _         | j         S )zReturn the **binary** (non-printable) MAC tag of the message.

        :return: The MAC tag. Binary form.
        :rtype: byte string
           )r   r   r   r   r   readr   s    r    digestzKMAC_Hash.digestK   sV     y 	<Ld.>.B C CDDD))$*:;;DIyr"   c                 ~    d                     d t          |                                           D                       S )zReturn the **printable** MAC tag of the message.

        :return: The MAC tag. Hexadecimal encoded.
        :rtype: string
         c                 2    g | ]}d t          |          z  S )z%02x)r   ).0xs     r    
<listcomp>z'KMAC_Hash.hexdigest.<locals>.<listcomp>_   s#    GGGQa(GGGr"   )jointupler)   r(   s    r    	hexdigestzKMAC_Hash.hexdigestX   s5     wwGG%2F2FGGGHHHr"   c                    t          d          }t          j        ||z             }t          j        ||                                 z             }|                                |                                k    rt	          d          dS )a`  Verify that a given **binary** MAC (computed by another party)
        is valid.

        Args:
          mac_tag (bytes/bytearray/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.
           zMAC check failedN)r   r
   newr)   
ValueError)r   mac_tagsecretmac1mac2s        r    verifyzKMAC_Hash.verifya   ss     ""%%|FW,--|FT[[]]233;;==DKKMM))/000 *)r"   c                 d    |                      t          t          |                               dS )an  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KMAC_Hash.hexverifyu   s,     	Igk223344444r"   c                 6    d|vr
| j         |d<   t          di |S )zNReturn a new instance of a KMAC hash object.
        See :func:`new`.
        r    )r   r5   )r   kwargss     r    r5   zKMAC_Hash.new   s,    
 F"" $ 0F9}}V}}r"   N)__name__
__module____qualname____doc__r!   r   r)   r2   r;   r>   r5   r@   r"   r    r   r   (   s         
& & &    I I I1 1 1(5 5 5    r"   r   c            	         |                      dd          }t          |          st          d          t          |          dk     rt	          d          |                      dd          }|                      dd          }|d	k     rt	          d
          |                      dd          }| rt          dt          |           z             t          ||||dt          d          S )a  Create a new KMAC128 object.

    Args:
        key (bytes/bytearray/memoryview):
            The key to use to compute the MAC.
            It must be at least 128 bits long (16 bytes).
        data (bytes/bytearray/memoryview):
            Optional. The very first chunk of the message to authenticate.
            It is equivalent to an early call to :meth:`KMAC_Hash.update`.
        mac_len (integer):
            Optional. The size of the authentication tag, in bytes.
            Default is 64. Minimum is 8.
        custom (bytes/bytearray/memoryview):
            Optional. A customization byte string (``S`` in SP 800-185).

    Returns:
        A :class:`KMAC_Hash` hash object
    r   NzYou must pass a key to KMAC128r4   z1The key must be at least 128 bits long (16 bytes)r   r   @   r&   z!'mac_len' must be 8 bytes or morer   r"   zUnknown parameters: 19   )popr   r$   lenr6   strr   r	   )rA   r   r   r   r   s        r    r5   r5      s    ( **UD
!
!CC== :8999
3xx"}}LMMM::fd##DjjB''G{{<===ZZ#&&F >.V<===T3y#FFFr"   N)binasciir   Cryptodome.Util.py3compatr   r   r   Cryptodome.Randomr   r+   r	   r
   r   r   r   objectr   r5   r@   r"   r    <module>rQ      s   >       = = = = = = = = = = . . . . . . ! ! ! ! ! ! ! ! ; ; ; ; ; ; ; ; ; ;c c c c c c c cL%G %G %G %G %Gr"   