Test our implementation against Cryptography module's

This commit is contained in:
2023-10-29 10:59:32 +00:00
parent 8e38985bf8
commit baf3ef31a5
4 changed files with 22 additions and 4 deletions
+16
View File
@@ -7,6 +7,7 @@ from randquik import cha
def test_cipherstreams_fullblocks():
"""Requests in multiple of ChaCha20 block size 64 bytes"""
key = token_bytes(32)
nonce = token_bytes(16)
c0 = Cipher(ChaCha20(key, nonce), None, None).encryptor()
@@ -21,6 +22,7 @@ def test_cipherstreams_fullblocks():
def test_cipherstreams_partial_updates():
"""Odd-sized requests that retain leftover buffers"""
key = token_bytes(32)
nonce = token_bytes(16)
c0 = Cipher(ChaCha20(key, nonce), None, None).encryptor()
@@ -32,3 +34,17 @@ def test_cipherstreams_partial_updates():
ct1 = c1(bytearray(N))
assert len(ct0) == len(ct1)
assert ct0.hex() == ct1.hex()
def test_cipherstreams_32leftover():
"""Test the special case where the second response comes entirely from the leftover buffer"""
key = token_bytes(32)
nonce = token_bytes(16)
c0 = Cipher(ChaCha20(key, nonce), None, None).encryptor()
c1 = cha.Cha(key, nonce)
for N in [512 - 32, 32]:
ct0 = c0.update(bytes(N))
ct1 = c1(bytearray(N))
assert len(ct0) == len(ct1)
assert ct0.hex() == ct1.hex()