o
    6d                  	   @   s   d Z zddlZedd dd ZW dS  eefyE   ddlmZm	Z	 d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd ZY dS w )z5
Implementation of the SHAKE-256 algorithm for Ed448
    Nshake256@   c                 C   s   t d| |S )Nr   )hashlibnewdigestmsgZoutlen r	   bC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\ecdsa/_sha3.py	shake_256
   s   r      )bytes_to_intint_to_bytesc                 C   s   t | ddS )Nlittle	byteorder)r   )sr	   r	   r
   _from_le   s   r   c                 C   s   | |> | d| ? B d@ S )Nr   l    r	   )xbr	   r	   r
   _rol   s   r   c           
      C   s  g d}g d}g d}t ddD ]}dgd }dgd }t ddD ]}||d   | | N  < q"t ddD ]}||d d  t||d	 d  d	A ||< q6t ddD ]}| |  ||d  N  < qSt ddD ]}t| | || | |< qg| |d  }t dt|d	 D ]}| ||d	   | || < q|| |d
 < t dddD ]@}| | | |d	  | |d  | |d  | |d  | | | |d	  g}t ddD ]}	||	 ||	d	   ||	d  @ A | ||	 < qq| d  || N  < qd S )N)r   r   >         $   ,      7         
   +      '   )   -                  =   8      )r   r   	      r-   r   r*               r&         r'   r(         r   r)            r    )r   i  l          l          i                  l   	             l   	   l   
    l      l           l          l          l          l           i
  l   
       r<   l          r;   l         r   r5   r7   r"   r4   r   r*   r   )ranger   len)
r   Z	ROTATIONSZPERMUTATIONRCZrndcditjr	   r	   r
   _sha3_transform   s@   

,




	,rH   c              	   C   sD   t dt|d D ]}| |  t|d| d| d  N  < q	d S )Nr   r(   )r@   rA   r   )r   r   rG   r	   r	   r
   _reinterpret_to_words_and_xor   s   *rI   c                 C   s4   t  }tdt| D ]}|t| | ddd7 }q
|S )Nr   r(   r   r   )	bytearrayr@   rA   r   )wmprG   r	   r	   r
   _reinterpret_to_octets   s   rM   c                 C   s  d| }dgd }d}t | | }td|D ]}t|| |||   ||7 }t| qt| |d }	|	| t |	|k rJ|	d t |	|k s?|	t |	d   dO  < t||	 t| t }
t |
|k r||
t|d| 7 }
t| t |
|k sh|
d| S )z!Semi-generic SHA-3 implementationr(   r   r"   Nr      )rA   r@   rI   rH   rJ   appendrM   )r   Zr_wZo_pZe_bZr_br   idxblocksrE   moutr	   r	   r
   	_sha3_raw   s,   




rT   c                 C   s   t | dd|S )Nr8      )rT   r   r	   r	   r
   r      s   )__doc__r   r   r   r   	TypeError
ValueErrorZ_compatr   r   r   r   rH   rI   rM   rT   r	   r	   r	   r
   <module>   s     t 