
    ,h=                     p    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y
)    )	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
y	)
	KMAC_Hashz[A KMAC hash object.
    Do not instantiate directly.
    Use the :func:`new` function.
    c                     d|z   | _         || _        d | _        t        t	        t        |            |      }|j                  ||d      | _        |r| j                  j                  |       y y )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	            U/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/Crypto/Hash/KMAC128.py__init__zKMAC_Hash.__init__.   sb     +[8"	GCL 94@{{<ALL%     c                 j    | j                   rt        d      | j                  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=   s.     99VWWD!r"   c                     | j                   s[| j                  j                  t        | j                  dz               | j                  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   sS     yyLLd.>.>.B CD))$*:*:;DIyy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.

        :return: The MAC tag. Hexadecimal encoded.
        :rtype: string
         z%02x)jointupler(   r   )r   xs     r    	hexdigestzKMAC_Hash.hexdigestX   s5     ww%2FGQa(GHHGs   Ac                     t        d      }t        j                  ||z         }t        j                  || j                         z         }|j                         |j                         k7  rt	        d      y)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   s_     ""%||FW,-||FT[[]23;;=DKKM)/00 *r"   c                 J    | j                  t        t        |                   y)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)r7   r   r   )r   hex_mac_tags     r    	hexverifyzKMAC_Hash.hexverifyu   s     	Igk234r"   c                 >    d|vr| j                   |d<   t        di |S )zNReturn a new instance of a KMAC hash object.
        See :func:`new`.
        r    )r   r1   )r   kwargss     r    r1   zKMAC_Hash.new   s(    
 F" $ 0 0F9}V}r"   N)__name__
__module____qualname____doc__r!   r   r(   r.   r7   r:   r1   r<   r"   r    r   r   (   s+    
&I1(5r"   r   c            	      l   | j                  dd      }t        |      st        d      t        |      dk  rt	        d      | j                  dd      }| j                  dd      }|d	k  rt	        d
      | j                  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 KMAC128r0   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$   lenr2   strr   r	   )r=   r   r   r   r   s        r    r1   r1      s    ( **UD
!CC=899
3x"}LMM::fd#DjjB'G{<==ZZ#&F.V<==T3y#FFr"   N)binasciir   Crypto.Util.py3compatr   r   r   Crypto.Randomr   r*   r	   r
   r   r   r   objectr   r1   r<   r"   r    <module>rM      s1   >  9 9 * ! ; ;c cL%Gr"   