fix: Make inc_nonce overflow at the correct value
This commit is contained in:
parent
c8b07ef913
commit
9ea816f832
@ -35,7 +35,7 @@ def inc_nonce(nonce: bytes) -> bytes:
|
||||
|
||||
num = bytes_to_long(nonce) + 1
|
||||
|
||||
if num > 2**MAX_NONCE:
|
||||
if num > 2**MAX_NONCE - 1:
|
||||
num = 0
|
||||
|
||||
bnum = long_to_bytes(num)
|
||||
|
@ -33,7 +33,13 @@ from secret_handshake.util import bytes_to_long, inc_nonce, long_to_bytes, split
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("in_,out", ((b"\x00\x00\x00\x00", b"\x00" * 23 + b"\x01"),))
|
||||
@pytest.mark.parametrize(
|
||||
"in_,out",
|
||||
(
|
||||
(b"\x00\x00\x00\x00", b"\x00" * 23 + b"\x01"),
|
||||
(b"\xff" * 24, b"\x00" * 24),
|
||||
),
|
||||
)
|
||||
def test_inc_nonce(in_: bytes, out: bytes) -> None:
|
||||
"""Test the inc_nonce function"""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user