Skip to content

Commit f261f94

Browse files
Add test case that verifies that ChaCha20 produces a reversible ciphertext
1 parent a2cfcbf commit f261f94

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crypto/tests/test_chacha20.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_invalid_nonce_size():
4040
assert "Nonce must be exactly 12 bytes" in str(e)
4141
else:
4242
assert False, "ValueError was not raised for long nonce"
43-
43+
4444
def test_invalid_counter_values():
4545
"""Test invalid counter values for ChaCha20."""
4646
for invalid_counter in [-1, -100, -999999]:
@@ -50,3 +50,12 @@ def test_invalid_counter_values():
5050
assert "Counter must be a non-negative integer" in str(e)
5151
else:
5252
assert False, f"ValueError not raised for counter={invalid_counter}"
53+
54+
def test_encrypt_decrypt():
55+
"""Test encryption and decryption are symmetric."""
56+
cipher = ChaCha20(VALID_KEY, VALID_NONCE)
57+
plaintext = b"Hello, ChaCha20!"
58+
ciphertext = cipher.encrypt(plaintext)
59+
decrypted = cipher.decrypt(ciphertext)
60+
61+
assert decrypted == plaintext, "Decryption failed. Plaintext does not match."

0 commit comments

Comments
 (0)