
    9i=                     p    S SK Jr  S SKJrJrJr  S SKJr  SSKJ	r	J
r
  SSK	JrJrJr   " S S\5      rS	 rg
)    )	unhexlify)bordtobytesis_bytes)get_random_bytes   )	cSHAKE128SHA3_256)_bytepad_encode_str_right_encodec                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)	KMAC_Hash(   zOA KMAC hash object.
Do not instantiate directly.
Use the :func:`new` function.
c                     SU-   U l         X0l        S U l        [        [	        [        U5      5      U5      nUR                  XS5      U l        U(       a  U R                  R                  U5        g g )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/land-doc-ocr/venv/lib/python3.13/site-packages/Crypto/Hash/KMAC128.py__init__KMAC_Hash.__init__.   s^     +[8"	GCL 94@{{<ALL%     c                 t    U R                   (       a  [        S5      eU R                  R                  U5        U $ )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   KMAC_Hash.update=   s.     99VWWD!r$   c                     U R                   (       d[  U R                  R                  [        U R                  S-  5      5        U R                  R                  U R                  5      U l         U R                   $ )zvReturn 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!   digestKMAC_Hash.digestK   sS     yyLLd.>.>.B CD))$*:*:;DIyyr$   c           	          SR                  [        U R                  5       5       Vs/ s H  nS[        U5      -  PM     sn5      $ s  snf )zlReturn the **printable** MAC tag of the message.

:return: The MAC tag. Hexadecimal encoded.
:rtype: string
 z%02x)jointupler+   r   )r   xs     r!   	hexdigestKMAC_Hash.hexdigestX   s;     ww%2FG2FQa(2FGHHGs   Ac                     [        S5      n[        R                  " X!-   5      n[        R                  " X R                  5       -   5      nUR                  5       UR                  5       :w  a  [	        S5      eg)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!   verifyKMAC_Hash.verifya   s[     ""%||F,-||F[[]23;;=DKKM)/00 *r$   c                 J    U R                  [        [        U5      5      5        g)a6  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!   	hexverifyKMAC_Hash.hexverifyu   s     	Igk234r$   c                 B    SU;  a  U R                   US'   [        S0 UD6$ )z>Return a new instance of a KMAC hash object.
See :func:`new`.
r    )r   r6   )r   kwargss     r!   r6   KMAC_Hash.new   s(    
 F" $ 0 0F9}V}r$   )r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r"   r   r+   r2   r<   r@   r6   __static_attributes__rC   r$   r!   r   r   (   s+    
&I1(5r$   r   c            	         U R                  SS5      n[        U5      (       d  [        S5      e[        U5      S:  a  [	        S5      eU R                  SS5      nU R                  SS5      nUS	:  a  [	        S
5      eU R                  SS5      nU (       a  [        S[        U 5      -   5      e[        X!X4S[        S5      $ )ay  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 KMAC128r5   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&   lenr7   strr   r	   )rD   r   r   r   r   s        r!   r6   r6      s    ( **UD
!CC==899
3x"}LMM::fd#DjjB'G{<==ZZ#&F.V<==Ty#FFr$   N)binasciir   Crypto.Util.py3compatr   r   r   Crypto.Randomr   r.   r	   r
   r   r   r   objectr   r6   rC   r$   r!   <module>rW      s1   >  9 9 * ! ; ;c cL%Gr$   