@@ -40,9 +40,9 @@ def __repr__(self):
4040 """Returns a string representation of the object for debugging."""
4141 return f"<ChaCha20(key={ self .key [:4 ].hex ()} ..., nonce={ self .nonce .hex ()} , counter={ self .counter } )>"
4242
43-
43+
4444 def _quarter_round (self , state : np .ndarray , a : tuple , b : tuple , c : tuple , d : tuple ):
45-
45+
4646 """
4747 Performs the ChaCha20 quarter-round operation on the 4x4 state matrix.
4848
@@ -54,7 +54,7 @@ def _quarter_round(self, state: np.ndarray, a: tuple, b: tuple, c: tuple, d: tup
5454 -----------
5555 state : np.ndarray
5656 A 4x4 matrix (NumPy array) representing the ChaCha20 state.
57-
57+
5858 a, b, c, d : tuple
5959 Each tuple represents the (row, column) indices of four elements in the state matrix
6060 to be processed in the quarter-round.
@@ -71,31 +71,31 @@ def _quarter_round(self, state: np.ndarray, a: tuple, b: tuple, c: tuple, d: tup
7171 2. c += d; b ^= c; b <<<= 12
7272 3. a += b; d ^= a; d <<<= 8
7373 4. c += d; b ^= c; b <<<= 7
74-
74+
7575 """
7676 ax , ay = a
7777 bx , by = b
7878 cx , cy = c
7979 dx , dy = d
80-
80+
8181 state [ax , ay ] = (state [ax , ay ] + state [bx , by ]) % (2 ** 32 )
8282 state [dx , dy ] ^= state [ax , ay ]
8383 state [dx , dy ] = ((state [dx , dy ] << 16 ) | (state [dx , dy ] >> 16 )) % (2 ** 32 )
84-
84+
8585 state [cx , cy ] = (state [cx , cy ] + state [dx , dy ]) % (2 ** 32 )
8686 state [bx , by ] ^= state [cx , cy ]
8787 state [bx , by ] = ((state [bx , by ] << 12 ) | (state [bx , by ] >> 20 )) % (2 ** 32 )
88-
88+
8989 state [ax , ay ] = (state [ax , ay ] + state [bx , by ]) % (2 ** 32 )
9090 state [dx , dy ] ^= state [ax , ay ]
9191 state [dx , dy ] = ((state [dx , dy ] << 8 ) | (state [dx , dy ] >> 24 )) % (2 ** 32 )
92-
92+
9393 state [cx , cy ] = (state [cx , cy ] + state [dx , dy ]) % (2 ** 32 )
9494 state [bx , by ] ^= state [cx , cy ]
9595 state [bx , by ] = ((state [bx , by ] << 7 ) | (state [bx , by ] >> 25 )) % (2 ** 32 )
96-
96+
9797 def _double_round (self , state : np .ndarray ):
98-
98+
9999 self ._quarter_round (state , (0 , 0 ), (1 , 0 ), (2 , 0 ), (3 , 0 ))
100100 self ._quarter_round (state , (0 , 1 ), (1 , 1 ), (2 , 1 ), (3 , 1 ))
101101 self ._quarter_round (state , (0 , 2 ), (1 , 2 ), (2 , 2 ), (3 , 2 ))
@@ -105,7 +105,7 @@ def _double_round(self, state: np.ndarray):
105105 self ._quarter_round (state , (0 , 1 ), (1 , 2 ), (2 , 3 ), (3 , 0 ))
106106 self ._quarter_round (state , (0 , 2 ), (1 , 3 ), (2 , 0 ), (3 , 1 ))
107107 self ._quarter_round (state , (0 , 3 ), (1 , 0 ), (2 , 1 ), (3 , 2 ))
108-
108+
109109
110110 def _chacha20_block (self , counter : int ) -> bytes :
111111 """
0 commit comments