
    i                     h    S SK JrJrJrJrJrJrJr  S SKJ	r	  S SK
Jr  SSKJr   " S S\5      rS rg	)
    )VoidPointerSmartPointercreate_string_bufferget_raw_bufferc_size_tc_uint8_ptrc_ubyte)long_to_bytes)bchr   )_raw_keccak_libc                   :    \ rS rSrSrS rS rS rS
S jrS r	S	r
g)
TurboSHAKE   zUA TurboSHAKE hash object.
Do not instantiate directly.
Use the :func:`new` function.
c                 d   [        5       n[        R                  " UR                  5       [	        U5      [        S5      5      nU(       a  [        SU-  5      e[        UR                  5       [        R                  5      U l
        SU l        Xl        X l        U(       a  U R                  U5        g g )Nr   z'Error %d while instantiating TurboSHAKEF)r   r   keccak_init
address_ofr   r	   
ValueErrorr   getkeccak_destroy_state_is_squeezing	_capacity_domainupdate)selfcapacitydomain_separationdatastateresults         T/var/www/html/trading/venv/lib/python3.13/site-packages/Crypto/Hash/TurboSHAKE128.py__init__TurboSHAKE.__init__   s     ,,U-=-=-?-5h-?-4R[: F%& ' '"599;0N0NO"!(KK     c           	          U R                   (       a  [        S5      e[        R                  " U R                  R                  5       [        U5      [        [        U5      5      5      nU(       a  [        SU-  5      eU $ )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 TurboSHAKE state)
r   	TypeErrorr   keccak_absorbr   r   r   r   lenr   )r   r   r!   s      r"   r   TurboSHAKE.update%   sm     MNN ..t{{/@/:4/@/7D	/BD G%& ' 'r%   c                     SU l         [        U5      n[        R                  " U R                  R                  5       U[        U5      [        U R                  5      5      nU(       a  [        SU-  5      e[        U5      $ )a   
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 TurboSHAKE)r   r   r   keccak_squeezer   r   r   r	   r   r   r   )r   lengthbfrr!   s       r"   readTurboSHAKE.read7   su     ""6* //0A03080@070EG H%& ' ' c""r%   Nc                 P    [        U 5      " U R                  U R                  U5      $ N)typer   r   )r   r   s     r"   newTurboSHAKE.newR   s    Dz$..$,,==r%   c                     [         R                  " U R                  R                  5       5      nU(       a  [	        SU-  5      eSU l        g )Nz)Error %d while resetting TurboSHAKE stateF)r   keccak_resetr   r   r   r   )r   r!   s     r"   _resetTurboSHAKE._resetU   s@     --dkkoo.?@H%& ' '"r%   )r   r   r   r   r2   )__name__
__module____qualname____firstlineno____doc__r#   r   r/   r4   r8   __static_attributes__ r%   r"   r   r      s     
&$#6>#r%   r   c                      U R                  SS5      nSUs=::  a  S::  d  O  [        SU-  5      eU R                  S5      n[        SXS9$ )	ab  Create a new TurboSHAKE128 object.

Args:
   domain (integer):
     Optional - A domain separation byte, between 0x01 and 0x7F.
     The default value is 0x1F.
   data (bytes/bytearray/memoryview):
    Optional - The very first chunk of the message to hash.
    It is equivalent to an early call to :meth:`update`.

:Return: A :class:`TurboSHAKE` object
domain   r      z&Incorrect domain separation value (%d)r       )r   )r   r   r   )kwargsr   r   s      r"   r4   r4   ]   sW     

8T2%--A*+ , 	,::fDb+77r%   N)Crypto.Util._raw_apir   r   r   r   r   r   r	   Crypto.Util.numberr
   Crypto.Util.py3compatr   keccakr   objectr   r4   r@   r%   r"   <module>rL      s3   8 8 8
 - & #N# N#b8r%   