
    ¿ig                     p    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dlmZ  G d de          Zd Zd	S )
    )VoidPointerSmartPointercreate_string_bufferget_raw_bufferc_size_tc_uint8_ptrc_ubyte)long_to_bytes)bchr   )_raw_keccak_libc                   2    e Zd ZdZd Zd Zd ZddZd ZdS )	
TurboSHAKEzaA TurboSHAKE hash object.
    Do not instantiate directly.
    Use the :func:`new` function.
    c                    t                      }t          j        |                                t	          |          t          d                    }|rt          d|z            t          |                                t          j	                  | _
        d| _        || _        || _        |r|                     |           d S d S )N   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         Y/var/www/html/afkarena/venv/lib/python3.11/site-packages/Cryptodome/Hash/TurboSHAKE128.py__init__zTurboSHAKE.__init__   s     ,U-=-=-?-?-5h-?-?-4R[[: :  	'F%& ' ' '"599;;0NOO"!( 	KK	 	    c           	         | j         rt          d          t          j        | j                                        t          |          t          t          |                              }|rt          d|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 TurboSHAKE state)
r   	TypeErrorr   keccak_absorbr   r   r   r   lenr   )r   r   r!   s      r"   r   zTurboSHAKE.update%   s      	OMNNN .t{/@/@/:4/@/@/7D		/B/BD D  	'G%& ' ' 'r$   c                    d| _         t          |          }t          j        | j                                        |t          |          t          | j                            }|rt          d|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 TurboSHAKE)r   r   r   keccak_squeezer   r   r   r	   r   r   r   )r   lengthbfrr!   s       r"   readzTurboSHAKE.read7   s     ""6** /0A0A03080@0@070E0EG G  	'H%& ' ' ' c"""r$   Nc                 J     t          |           | j        | j        |          S N)typer   r   )r   r   s     r"   newzTurboSHAKE.newR   s     tDzz$.$,===r$   c                     t          j        | j                                                  }|rt	          d|z            d| _        d S )Nz)Error %d while resetting TurboSHAKE stateF)r   keccak_resetr   r   r   r   )r   r!   s     r"   _resetzTurboSHAKE._resetU   sQ     -dkoo.?.?@@ 	'H%& ' ' '"r$   r/   )	__name__
__module____qualname____doc__r#   r   r-   r1   r4    r$   r"   r   r      sn         
  &  $# # #6> > > ># # # # #r$   r   c                      |                      dd          }d|cxk    rdk    sn t          d|z            |                      d          }t          d||          S )	a  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"   r1   r1   ]   s|     

8T22%--------A*+ , , 	,::fDb+$7777r$   N)Cryptodome.Util._raw_apir   r   r   r   r   r   r	   Cryptodome.Util.numberr
   Cryptodome.Util.py3compatr   keccakr   objectr   r1   r9   r$   r"   <module>rE      s   8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
 1 0 0 0 0 0 * * * * * * # # # # # #N# N# N# N# N# N# N# N#b8 8 8 8 8r$   