o
    5h                     @   sZ   d dl mZ d dlmZ ddlmZ dd ZdZdZdZ	d	Z
G d
d deZdddZdS )    )long_to_bytes)bchr   )TurboSHAKE128c                 C   s$   | dkrdS t | }|tt| S )Nr       )r   r   len)xS r
   n/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/Crypto/Hash/KangarooTwelve.py_length_encode$   s   r            c                   @   s2   e Zd ZdZdd Zdd Zdd Zdd
dZdS )K12_XOFzeA KangarooTwelve hash object.
    Do not instantiate directly.
    Use the :func:`new` function.
    c                 C   sf   |d krd}|t t| | _t| _d | _tjdd| _d| _	d | _
d| _d| _|r1| | d S d S )N    r   domainr   )r   r   _custom	SHORT_MSG_state_paddingr   new_hash1_length1_hash2_length2_ctrupdateselfdatacustomr
   r
   r   __init__9   s   zK12_XOF.__init__c           
      C   s  | j tkr	td| j tkr,| jt| }|t| j dkr)|| _| j| | S t	| _ | j t	krt
|}| jdk s<J tt|d| j }| j|d|  |  j|7  _| jdk r^| S | jdkseJ d}| j| |  jd7  _tjdd| _d| _d	| _t| _ | ||d S | j tksJ d}t|}t
|}||k rt|d | j |}| j|||  |  j|| 7  _|}| jdkr| jd
}	| j|	 |  jd
7  _| j  d| _|  jd	7  _||k s| 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_ir
   r
   r   r   Q   sX   





zK12_XOF.updatec                 C   s   d}| j tkr| j| j d| _t| _ | j tkr(| | j d}| j tks(J | j tkrq|s5| | j | j	dkr\| j
d}| j| |  jd7  _| j
  d| _	|  jd7  _t| jd d }| 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)   r,   r   r   r-   r   r.   r   r   _domain)r    lengthcustom_was_consumedr6   trailerr
   r
   r   r-      s2   





zK12_XOF.readNr   c                 C   s   t | ||S )N)typer   r
   r
   r   r      s   zK12_XOF.new)Nr   )__name__
__module____qualname____doc__r#   r   r-   r   r
   r
   r
   r   r   3   s    I1r   Nc                 C   s
   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"   r
   r
   r   r      s   
r   )NN)Crypto.Util.numberr   Crypto.Util.py3compatr    r   r   r   r)   r,   r'   objectr   r   r
   r
   r
   r   <module>   s   	 