
    ":h                         d Z d Zd Zd Zy)u  keccakf1600.py

Keccak is a family of hash functions based on the sponge construction. It was
chosen by NIST to become the SHA-3 standard. This code implements the
Keccak-f[1600] permutation. Detailed information about this function can be
found on the official site [1]. Original implementation [2] by the Keccak Team.

Some caveats about the implementation:
    * width `b` of permutation is fixed as 1600 (5 * 5 * 64), which means
    the number of rounds is 24 (12 + 2ℓ, ℓ = log_2(b / 25))
    * ρ step could have its offsets pre-computed as the array `r`.
    * ι step could have its round constants pre-computed as the array `RC`.

[1] http://keccak.noekeon.org/
[2] https://git.io/vKfkb
c                 0   d }d }d }t        d      D cg c]  }t        d      D cg c]  }d c} }}t        d      D ]1  }t        d      D ]!  }d|d|z  z   z  } || ||dz          ||   |<   # 3 d}	t        d      D ]  }t        d      D cg c].  }||   d   ||   d   z  ||   d	   z  ||   d
   z  ||   d   z  0 }
}t        d      D cg c]   }|
|dz
  dz      ||
|dz   dz     d      z  " }}t        d      D cg c]'  }t        d      D cg c]  }||   |   ||   z   c}) }}}dd|d   d   }}}t        d      D ]8  }|d	|z  d
|z  z   dz  }}|dz   |d	z   z  d	z  }||   |    |||      c}||   |<   : t        d      D ]T  }t        d      D cg c]
  }||   |    }}t        d      D ]&  }||   ||dz   dz      ||d	z   dz     z  z  ||   |<   ( V t        d      D ]2  }|	dz  |	dz	  dz  z  dz  }	|	d	z  s|d   dxx   dd|z  dz
  z  z  cc<   4  t        d      D ]1  }t        d      D ]!  }d|d|z  z   z  } |||   |         | ||dz    # 3 | S c c}w c c}w c c}w c c}w c c}w c c}}w c c}w )u  The inner permutation for the Keccak sponge function.

    The Keccak-f permutation is an iterated construction consisting of a
    sequence of almost identical rounds. It operates on a state array with
    each of the twenty-four rounds performing five steps, described below
    with detail.

    The loops above and below the core of the permutation are used to save and
    restore the state array to a stream of bytes, used outside the permutation.
    The original state array has three dimensions, whereas this characteristic
    can be cleverly optimized to a 5x5 matrix with 64-bit words. As such, this
    implementation makes use of this trick and stores an entire lane (a z-axis
    set of bits within the state) as a single word.

    The θ step diffuses the bits alongside the state array by calculating the
    parity of nearby columns relative to a lane.

    The ρ and π steps are merged; together, they move more bits around
    according to two alike recurrence relations.

    The χ step is similar to an S-box permutation; it makes the whole round
    non-linear with a few logic operations on bits inside a line.

    The ι step is a simple LFSR that breaks the symmetry of the rounds. It
    generates constants by doing computations according to the round number
    and its previous output, modulo polynomials over GF(2)[x].

    Args:
        state:  square matrix of order 5 that holds the input bytes.

    Returns:
        state:  bytes permuted by Keccak-f[1600].
    c                 >     t         fdt        d      D              S )z
        Saves each byte on its respective position within a 64-bit word.

        Args:
            b:  partial list of bytes from input.

        Returns:
            Sum of list with numbers shifted.
        c              3   4   K   | ]  }|   d |z  z    yw)   N ).0ibs     `/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/static_dependencies/keccak/keccak.py	<genexpr>z0keccak_f_1600.<locals>.load64.<locals>.<genexpr>C   s     7AaDQUO7   r   )sumrange)r	   s   `r
   load64zkeccak_f_1600.<locals>.load649   s     7eAh777    c                 >     t         fdt        d      D              S )z
        Transforms a 64-bit word into a list of bytes.

        Args:
            a:  64-bit word.

        Returns:
            List of bytes separated by position on the word.
        c              3   4   K   | ]  }d |z  z	  dz    yw)r      Nr   )r   r   as     r
   r   z1keccak_f_1600.<locals>.store64.<locals>.<genexpr>O   s     ;QQ1q5\S(;r   r   )listr   )r   s   `r
   store64zkeccak_f_1600.<locals>.store64E   s     ;%(;;;r   c                 0    | d|dz  z
  z	  | |dz  z  z   dz  S )a=  
        Denotes the bitwise cyclic shift operation, moving bit at position
        `i` into position `i + n` (modulo the lane size).

        Args:
            a:  lane with a 64-bit word, or elements from the state array.
            n:  offset for rotation.

        Returns:
            The rotated lane.
        @   l            r   )r   ns     r
   rotatezkeccak_f_1600.<locals>.rotateQ   s)     rQV}%!B-8WEEr          r                     q   r   )r   )stater   r   r   _Axyr   RCDcurrenttoffsetTjs                    r
   keccak_f_1600r1      s;   F
8
<F ).a11U1X	!	1A11X /q 	/AQQYAU1q1u-.AaDG	//
 	
A2Y /FKAhOQqT!WqtAw1a(1Q472QqT!W<OOAFqJAQA{^fQA{^Q77JJ9>qBAeAh/ad1g!n/BB1ad1gg1r 	@Aq1uq1u})qA1uQ'A-F tAww(?GQqT!W	@
 q 	FA"'(+Q1a+A+1X FA$Aq1ukN?aQ!n"DE!QF	F
 q 	/Aq&a1f_-4A1u!Q1!q&A..	/!/* 1X 0q 	0AQQYA&qtAw/E!a!e	00
 LC 
1 PJ/B ,s?   I9	I4
I93I>%JJJ4J)J4I9Jc                    t        | |z   dz        }| dz  dd}}}|t        |      k  rat        t        |      |z
  |      }t        |      D ]  }	||	xx   ||	|z      z  cc<    ||z  }||k(  rt	        |      }d}|t        |      k  ra||xx   |z  cc<   |dz  r||dz
  k(  rt	        |      }||dz
  xx   dz  cc<   t	        |      }t               }
|r)t        ||      }|
|d| z  }
||z  }|rt	        |      }|r)|
S )a  
    The general sponge function, consisting of the inner permutation and a
    padding rule (`pad10*1`). It consists of three main parts.
        * absorbing, where the input will be permuted repeatedly every time
            it is divided into a block of size `r + c`.
        * padding, where an oddly sized last block will be filled with bits
            until it can be fed into the permutation.
        * squeezing, where the output's blocks will be permuted more times
            until they are concatenated to the desired size.

    Args:
        r:          rate, or the number of input bits processed or output bits
                    generated per invocation of the underlying function
        c:          capacity, or the width of the underlying function minus
                    the rate
        _input:     list of bytes containing the desired object to be hashed
        suffix:     distinguishes the inputs arising from SHA-3/SHAKE functions
        output_len: length of hash output.

    Returns:
        Hash of the input bytes.
    r   r      r   N)	bytearraylenminr   r1   )rc_inputsuffix
output_lenr$   
rate_bytesblockr.   r   outputs              r
   Keccakr?      s3   . q1ul#E !Q1vJ
3v;
CK&(*5u 	+A!Hq6z**H	+%J!%(EE 3v;
 
%LFLEj1n5e$	*q.T!% E[F
J
+%-e
!%(E  Mr   c                 @    d}d}t        d|dz  z
  |dz  | ||dz        S )a  
    FIPS 202 generalized instance of the SHA-3 hash function.

    Args:
        size:   instance of desired SHA3 algorithm.
        _input: list of bytes to compute a hash from.

    Returns:
        Instance of the Keccak permutation that calculates the hash.
    r   r   i@  r   r   )r?   )r9   sizepaddings      r
   SHA3rC      s1     DG$/4!8VWdaiHHr   N)__doc__r1   r?   rC   r   r   r
   <module>rE      s   $jZ1hIr   