
    ,h                         d dl mZmZ d dlmZmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZ d Zd Zd Zd Z G d	 d
e      Zd ZddZy)    )bchrconcat_buffers)VoidPointerSmartPointercreate_string_bufferget_raw_bufferc_size_tc_uint8_ptrc_ubyte)long_to_bytes)_raw_keccak_libc                     | ddz  k  r| dk\  sJ | dk(  rdn| j                         dz   dz  }t        |      t        |       z   S )z2Left encode function as defined in NIST SP 800-185     r         )
bit_lengthr   r   xnums     W/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/Crypto/Hash/cSHAKE128.py_left_encoder   +   sK     dOQ' Av!ALLNQ.14C9}Q'''    c                     | ddz  k  r| dk\  sJ | dk(  rdn| j                         dz   dz  }t        |       t        |      z   S )z3Right encode function as defined in NIST SP 800-185r   r   r   r   r   )r   r   r   r   s     r   _right_encoder   6   sK     dOQ' Av!ALLNQ.14Cd3i''r   c                 n    t        |       dz  }|ddz  k\  rt        d      t        t        |      |       S )z4Encode string function as defined in NIST SP 800-185r   r   r   z$String too large to encode in cSHAKE)len
ValueErrorr   r   )r   bitlens     r   _encode_strr    A   s;     VaZF!t)?@@,v.22r   c                 d    t        t        |      |       }|t        |      |z  z
  |z  }|d|z  z   S )z2Zero pad byte string as defined in NIST SP 800-185    )r   r   r   )r   lengthto_padnpads       r   _bytepadr&   K   s>     L0!4F S[6))V3DGdN""r   c                   "    e Zd ZdZd Zd Zd Zy)
cSHAKE_XOFz]A cSHAKE hash object.
    Do not instantiate directly.
    Use the :func:`new` function.
    c                    t               }|s|r1t        |      t        |      z   }t        |d|z
  dz        }d| _        n	d }d| _        t	        j
                  |j                         t        |dz        t        d            }|rt        d|z        t        |j                         t        j                        | _        d| _        |r| j                  |       |r| j                  |       y y )Ni@  r            z#Error %d while instantiating cSHAKEF)r   r    r&   _paddingr   keccak_init
address_ofr	   r   r   r   getkeccak_destroy_state_is_squeezingupdate)	selfdatacustomcapacityfunctionstateprefix_unpadprefixresults	            r   __init__zcSHAKE_XOF.__init__]   s    X&x0;v3FFLlTH_q,@AF DMF DM ,,U-=-=-?-5hk-B-4R[: B%& ' '"599;#2#A#AC"KKKK r   c           	          | j                   rt        d      t        j                  | j                  j                         t        |      t        t        |                  }|rt        d|| j                  fz        | S )zContinue hashing of a message by consuming the next chunk of data.

        Args:
            data (byte string/byte array/memoryview): The next chunk of the message being hashed.
        z/You cannot call 'update' after the first 'read'z Error %d while updating %s state)r3   	TypeErrorr   keccak_absorbr2   r0   r
   r	   r   r   name)r5   r6   r=   s      r   r4   zcSHAKE_XOF.updatex   sv     MNN ..t{{/@/:4/@/7D	/BD ? &		23 4 4r   c                    d| _         t        |      }t        j                  | j                  j                         |t        |      t        | j                              }|rt        d|| j                  fz        t        |      S )ah  
        Compute the next piece of XOF output.

        .. note::
            You cannot use :meth:`update` anymore after the first call to
            :meth:`read`.

        Args:
            length (integer): the amount of bytes this method must return

        :return: the next piece of XOF output (of the given length)
        :rtype: byte string
        Tz!Error %d while extracting from %s)r3   r   r   keccak_squeezer2   r0   r	   r   r-   r   rB   r   )r5   r#   bfrr=   s       r   readzcSHAKE_XOF.read   s~     ""6* //0A03080@070FH @ &		23 4 4 c""r   N)__name__
__module____qualname____doc__r>   r4   rF    r   r   r(   r(   W   s    
6$#r   r(   c                     t        | |d|      S )N   r(   )r6   r7   r9   s      r   _newrO      s    dFC22r   Nc                     t        | |dd      S )az  Return a fresh instance of a cSHAKE128 object.

    Args:
       data (bytes/bytearray/memoryview):
        Optional.
        The very first chunk of the message to hash.
        It is equivalent to an early call to :meth:`update`.
       custom (bytes):
        Optional.
        A customization bytestring (``S`` in SP 800-185).

    :Return: A :class:`cSHAKE_XOF` object
    rM   r   rN   )r6   r7   s     r   newrQ      s      dFC--r   )NN)Crypto.Util.py3compatr   r   Crypto.Util._raw_apir   r   r   r   r	   r
   r   Crypto.Util.numberr   Crypto.Hash.keccakr   r   r   r    r&   objectr(   rO   rQ   rK   r   r   <module>rW      sN   > 78 8 8
 - .((3	#L# L#^3
.r   