
    E#i                         S r S rS rS rg)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                 \   S nS nS n[        S5       Vs/ s H  n[        S5       Vs/ s H  nSPM     snPM!     nn[        S5       H2  n[        S5       H   nSUSU-  -   -  nU" XUS-    5      XV   U'   M"     M4     Sn	[        S5       GH  n[        S5       Vs/ s H*  oeU   S   XV   S   -  XV   S	   -  XV   S
   -  XV   S   -  PM,     n
n[        S5       Vs/ s H  ojUS-
  S-     U" XS-   S-     S5      -  PM!     nn[        S5       VVs/ s H)  n[        S5       Vs/ s H  ouU   U   X   -  PM     snPM+     nnnSSUS   S   pn[        S5       H5  nUS	U-  S
U-  -   S-  pvUS-   US	-   -  S	-  nXV   U   U" X5      soU   U'   M7     [        S5       HU  n[        S5       Vs/ s H
  oeU   U   PM     nn[        S5       H#  nX   XS-   S-     ) XS	-   S-     -  -  XV   U'   M%     MW     [        S5       H9  nU	S-  U	S-	  S-  -  S-  n	U	S	-  (       d  M   US   S==   SSU-  S-
  -  -  ss'   M;     GM     [        S5       H2  n[        S5       H   nSUSU-  -   -  nU" XV   U   5      XUS-   & M"     M4     U $ s  snf s  snf s  snf s  snf s  snf s  snnf s  snf )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                 @   ^  [        U 4S j[        S5       5       5      $ )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   :   >#    U  H  nTU   S U-  -  v   M     g7f)   N ).0ibs     `/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/static_dependencies/keccak/keccak.py	<genexpr>0keccak_f_1600.<locals>.load64.<locals>.<genexpr>C   s     7hAaDQUOh   r   )sumrange)r	   s   `r
   load64keccak_f_1600.<locals>.load649   s     7eAh777    c                 @   ^  [        U 4S j[        S5       5       5      $ )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   :   >#    U  H  nTS U-  -	  S-  v   M     g7f)r      Nr   )r   r   as     r
   r   1keccak_f_1600.<locals>.store64.<locals>.<genexpr>O   s     ;(QQ1q5\S((r   r   )listr   )r   s   `r
   store64keccak_f_1600.<locals>.store64E   s     ;%(;;;r   c                 .    U SUS-  -
  -	  XS-  -  -   S-  $ )z
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
   rotate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_1600r6      s   F
8
<F ).a11U1X	X!X	A11XqAQQYAUq1u-.ADG  
 	
A2YFKAhOhqT!WqtAwa(1472QT!W<hOAFqJAA{^fQA{^Q77J9>qBAeAh/hd1gnh/B1ad1ggrAq1uq1u})q1uQ'A-F tAww(?GqT!W 
 qA"'(+(Q1a(A+1X$A1ukN?aQ!n"DEQ  
 qAq&a1f_-4A1uu!Q1!q&A.. ! * 1XqAQQYA&qtAw/Ea!e  
 LC 
1 PJ/B ,s?   JJ

J1J&JJ#'J=J#1J)
JJ#c                 "   [        X-   S-  5      nU S-  SSpnU[        U5      :  ab  [        [        U5      U-
  U5      n[        U5       H  n	XY==   X)U-      -  ss'   M     X-  nXv:X  a  [	        U5      nSnU[        U5      :  a  Mb  XW==   U-  ss'   US-  (       a  XvS-
  :X  a  [	        U5      nXVS-
  ==   S-  ss'   [	        U5      n[        5       n
U(       a1  [        XF5      nXSU -  n
XG-  nU(       a  [	        U5      nU(       a  M1  U
$ )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   r6   )rc_inputsuffix
output_lenr)   
rate_bytesblockr3   r   outputs              r
   KeccakrD      s   . qul#E !Q1vJ
3v;
CK&(*5uAH6z**H !%(EE 3v;
 
LFLE1n5e$	q.T!% E[F
J+-
!%(E * Mr   c                 >    SnSn[        SUS-  -
  US-  XUS-  5      $ )z
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   )rD   )r>   sizepaddings      r
   SHA3rH      s/     DG$/4!8VdaiHHr   N)__doc__r6   rD   rH   r   r   r
   <module>rJ      s   $jZ1hIr   