o
    Þý°j
  ã                   @   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
   ú‘/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/Cryptodome/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r�t
|ƒ}| 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s”J ‚d}t|ƒ}t
|ƒ}||k rìt|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)ÚCryptodome.Util.numberr   ÚCryptodome.Util.py3compatr   Ú r   r   r   r)   r,   r'   Úobjectr   r   r
   r
   r
   r   Ú<module>   s   	 