
    1xh
                     d    d dl mZ d dlmZ ddlmZ d ZdZdZdZ	dZ
 G d	 d
e          ZddZdS )    )long_to_bytes)bchr   )TurboSHAKE128c                 n    | dk    rdS t          |           }|t          t          |                    z   S )Nr       )r   r   len)xSs     Z/home/visionen/capture/venv/lib/python3.11/site-packages/Cryptodome/Hash/KangarooTwelve.py_length_encoder   $   s4    AvvwaAtCFF||             c                   ,    e Zd ZdZd Zd Zd ZddZdS )	K12_XOFzeA KangarooTwelve hash object.
    Do not instantiate directly.
    Use the :func:`new` function.
    c                 "   |d k    rd}|t          t          |                    z   | _        t          | _        d | _        t          j        d          | _        d| _	        d | _
        d| _        d| _        |r|                     |           d S d S )Nr   r   domainr   )r   r	   _custom	SHORT_MSG_state_paddingr   new_hash1_length1_hash2_length2_ctrupdateselfdatacustoms      r   __init__zK12_XOF.__init__9   s    T>>Fs6{{ ; ;; $'q111  	 	KK	 	r   c                 z   | j         t          k    rt          d          | j         t          k    ra| j        t          |          z   }|t          | j                  z   dk    r#|| _        | j                            |           | S t          | _         | j         t          k    r
t          |          }| j        dk     sJ t          t          |          d| j        z
            }| j                            |d|                    | xj        |z  c_        | j        dk     r| S | j        dk    sJ d}| j                            |           | xj        dz  c_        t          j        d          | _        d| _        d	| _        t"          | _         |                     ||d                   S | j         t"          k    sJ d}t          |          }t          |          }||k     rt          |dz   | j        z
  |          }| j                            |||                    | xj        ||z
  z  c_        |}| j        dk    rt| j                            d
          }	| j                            |	           | xj        d
z  c_        | j                                         d| _        | xj        d	z  c_        ||k     | S )a
  Hash the next piece of data.

        .. note::
            For better performance, submit chunks with a length multiple of 8192 bytes.

        Args:
            data (byte string/byte array/memoryview): The next chunk of the
              message to hash.
        z/You cannot call 'update' after the first 'read'i    Ns                r   r   r       )r   	SQUEEZING	TypeErrorr   r   r	   r   r   r!   LONG_MSG_S0
memoryviewminr   r   r   r   r    LONG_MSG_SXread_reset)
r#   r$   next_lengthdata_memdtcdividerindexlen_data	new_indexcv_is
             r   r!   zK12_XOF.updateQ   s    ;)##MNNN;)##-#d))3KS...$66 +""4((( &DK;+%%!$''H=4''''c$ii!566CKx~...MMS MM}t## =D((((+GKw'''MMQMM'+4888DKDMDI%DK;;x~... {k))))t99 d##hEDL4=8(CCIKxi8999MMY..MME}$${''++""4(((#""$$$ !		Q		 h r   c                 @   d}| j         t          k    r2| j                            | j                   d| _        t          | _         | j         t          k    r.|                     | j                   d}| j         t          k    sJ | j         t          k    r|s|                     | j                   | j	        dk    rt| j
                            d          }| j                            |           | xj        dz  c_        | j
                                         d| _	        | xj        dz  c_        t          | j        dz
            dz   }| j                            |           d| _        t          | _         | j        | j        _        | j                            |          S )	ad  
        Produce more bytes of the digest.

        .. 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
        F   Tr   r*   r   s      )r   r   r   r!   r   r   r+   r-   r0   r   r   r1   r   r2   r    r   _domain)r#   lengthcustom_was_consumedr:   trailers        r   r1   zK12_XOF.read   sr    $;)##Kt|,,, DM#DK;+%%KK%%%"&;+----;+%%& *DL))) }q  {''++""4(((#""$$$ !		Q		$TY]33kAGKw''' DM#DK"m{'''r   Nr   c                 4     t          |           ||          S )N)typer"   s      r   r   zK12_XOF.new   s    tDzz$'''r   )Nr   )__name__
__module____qualname____doc__r&   r!   r1   r    r   r   r   r   3   sd         
  0G G GR/( /( /(b( ( ( ( ( (r   r   Nc                 "    t          | |          S )ag  Return a fresh instance of a KangarooTwelve 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 byte string.

    :Return: A :class:`K12_XOF` object
    )r   )r$   r%   s     r   r   r      s     4   r   )NN)Cryptodome.Util.numberr   Cryptodome.Util.py3compatr    r   r   r   r-   r0   r+   objectr   r   rH   r   r   <module>rN      s   > 1 0 0 0 0 0 * * * * * *         		Y( Y( Y( Y( Y(f Y( Y( Y(x! ! ! ! ! !r   