3
¬ �e  ã               @   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
   úa/var/www/html/wholesaler-api-python-env/lib/python3.6/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   sb   |d krd}|t t|ƒƒ | _t| _d | _tjdd�| _d| _	d | _
d| _d| _|r^| j|ƒ 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rX| jt|ƒ }|t| jƒ dkrR|| _| jj|ƒ | S t	| _ | j t	k�rt
|ƒ}| jdk szt‚tt|ƒd| j ƒ}| jj|d|… ƒ |  j|7  _| jdk r¾| S | jdksÌt‚d}| jj|ƒ |  jd7  _tjdd	�| _d
| _d| _t| _ | j||d… ƒS | j tk�s,t‚d
}t|ƒ}t
|ƒ}xž||k �rÞt|d | j |ƒ}| jj|||… ƒ |  j|| 7  _|}| jdk�rB| jjdƒ}	| jj|	ƒ |  jd7  _| jjƒ  d
| _|  jd7  _�qBW | 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    Nó   r   é   é   é   )r   r   r   é    s          s          )r   Ú	SQUEEZINGÚ	TypeErrorr   r   r   r   r   r   ÚLONG_MSG_S0Ú
memoryviewÚAssertionErrorÚminr   r   r   r   r   ÚLONG_MSG_SXÚreadÚ_reset)
r   r   Znext_lengthZdata_memZdtcZdividerÚindexZlen_dataZ	new_indexÚcv_ir
   r
   r   r   Q   sV    



zK12_XOF.updatec             C   sø   d}| j tkr(| jj| jƒ d| _t| _ | j tkrP| j| jƒ d}| j tksPt	‚| j tkrâ|sj| j| jƒ | j
dkr¸| jjdƒ}| jj|ƒ |  jd7  _| jjƒ  d| _
|  jd7  _t| jd ƒd }| jj|ƒ d| _t| _ | j| 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
        Fr#   Tr   r&   r   s   ÿÿé   )r   r   r   r   r   r   r'   r)   r-   r+   r   r   r.   r   r/   r   r   Z_domain)r   ÚlengthZcustom_was_consumedr1   Útrailerr
   r
   r   r.   š   s2    





zK12_XOF.readNr   c             C   s   t | ƒ||ƒS )N)Útype)r   r   r    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)ZCrypto.Util.numberr   ZCrypto.Util.py3compatr   Ú r   r   r   r)   r-   r'   Úobjectr   r   r
   r
   r
   r   Ú<module>   s   	 