5
5
from itertools import chain , product
6
6
from math import log2
7
7
from operator import xor
8
- from typing import List , Protocol , Reversible , Sequence
8
+ from typing import List , Literal , Protocol , Reversible , Sequence
9
9
10
10
from ..utils import chunked
11
11
from .conversion import bit , bitlist_to_bytes , ints_to_bitlist
@@ -95,14 +95,13 @@ def __call__(self, s: List[List[int]]) -> None:
95
95
96
96
97
97
class keccak_p :
98
- def __init__ (self , b : int , nr : int ) -> None :
98
+ def __init__ (self , b : Literal [ 25 , 50 , 100 , 200 , 400 , 800 , 1600 ] , nr : int ) -> None :
99
99
"""Keccak-p permutation function as defined in NIST.FIPS.202 3.3
100
100
101
101
Args:
102
- b (int ): width of the permutation
102
+ b (Literal[25, 50, 100, 200, 400, 800, 1600] ): width of the permutation
103
103
nr (int): number of rounds
104
104
"""
105
- assert b in {25 , 50 , 100 , 200 , 400 , 800 , 1600 }
106
105
self .b = b
107
106
self .nr = nr
108
107
self ._W = self .b // 25
@@ -140,11 +139,11 @@ def __call__(self, s: List[List[int]]) -> None:
140
139
self .round (s , ir )
141
140
142
141
143
- def keccak_f (b : int ):
142
+ def keccak_f (b : Literal [ 25 , 50 , 100 , 200 , 400 , 800 , 1600 ] ):
144
143
"""Keccak-f permutation function as defined in NIST.FIPS.202 3.4
145
144
146
145
Args:
147
- b (int ): width of the permutation
146
+ b (Literal[25, 50, 100, 200, 400, 800, 1600] ): width of the permutation
148
147
149
148
Returns:
150
149
the permutation function keccak-f
@@ -289,11 +288,11 @@ def pad10s1(x: int, m: int) -> List[bit]:
289
288
return [bit (1 )] + [bit (0 )] * j + [bit (1 )]
290
289
291
290
292
- def keccak (b : int ):
293
- """KECCAK sponge as defined in NIST.FIPS.202 6 .2
291
+ def keccak (b : Literal [ 25 , 50 , 100 , 200 , 400 , 800 , 1600 ] ):
292
+ """KECCAK sponge as defined in NIST.FIPS.202 5 .2
294
293
295
294
Args:
296
- b (int ): width of the permutation
295
+ b (Literal[25, 50, 100, 200, 400, 800, 1600] ): width of the permutation
297
296
"""
298
297
299
298
def call (r : int ):
@@ -303,7 +302,7 @@ def call(r: int):
303
302
304
303
305
304
def keccak_c (c : int ):
306
- """KECCAK[c] sponge as defined in NIST.FIPS.202 6 .2
305
+ """KECCAK[c] sponge as defined in NIST.FIPS.202 5 .2
307
306
308
307
Args:
309
308
c (int): capacity
0 commit comments