diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2015-07-03 03:52:39 -0400 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2015-07-03 03:52:39 -0400 |
commit | 53a36a1f8cd7c6bf243d5a5ad5522b0a592bba3d (patch) | |
tree | 6e8ec078cf59bd7d7ea2f94747aba82175298688 /tests/hazmat/primitives/test_aes.py | |
parent | f5a4519f7ead73cbca826f3d7c815dd8963efb0a (diff) | |
parent | 23cafe861f4da2d7261a41bc57801b226e6b8c1b (diff) | |
download | cryptography-53a36a1f8cd7c6bf243d5a5ad5522b0a592bba3d.tar.gz cryptography-53a36a1f8cd7c6bf243d5a5ad5522b0a592bba3d.tar.bz2 cryptography-53a36a1f8cd7c6bf243d5a5ad5522b0a592bba3d.zip |
Merge branch 'master' into encode-san
Diffstat (limited to 'tests/hazmat/primitives/test_aes.py')
-rw-r--r-- | tests/hazmat/primitives/test_aes.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_aes.py b/tests/hazmat/primitives/test_aes.py index 4d48e8ad..2c3e5f90 100644 --- a/tests/hazmat/primitives/test_aes.py +++ b/tests/hazmat/primitives/test_aes.py @@ -253,3 +253,53 @@ class TestAESModeGCM(object): computed_ct = encryptor.update(pt) + encryptor.finalize() assert computed_ct == ct assert encryptor.tag == tag + + def test_gcm_ciphertext_limit(self, backend): + encryptor = base.Cipher( + algorithms.AES(b"\x00" * 16), + modes.GCM(b"\x01" * 16), + backend=backend + ).encryptor() + encryptor._bytes_processed = modes.GCM._MAX_ENCRYPTED_BYTES - 16 + encryptor.update(b"0" * 16) + assert ( + encryptor._bytes_processed == modes.GCM._MAX_ENCRYPTED_BYTES + ) + with pytest.raises(ValueError): + encryptor.update(b"0") + + def test_gcm_aad_limit(self, backend): + encryptor = base.Cipher( + algorithms.AES(b"\x00" * 16), + modes.GCM(b"\x01" * 16), + backend=backend + ).encryptor() + encryptor._aad_bytes_processed = modes.GCM._MAX_AAD_BYTES - 16 + encryptor.authenticate_additional_data(b"0" * 16) + assert encryptor._aad_bytes_processed == modes.GCM._MAX_AAD_BYTES + with pytest.raises(ValueError): + encryptor.authenticate_additional_data(b"0") + + def test_gcm_ciphertext_increments(self, backend): + encryptor = base.Cipher( + algorithms.AES(b"\x00" * 16), + modes.GCM(b"\x01" * 16), + backend=backend + ).encryptor() + encryptor.update(b"0" * 8) + assert encryptor._bytes_processed == 8 + encryptor.update(b"0" * 7) + assert encryptor._bytes_processed == 15 + encryptor.update(b"0" * 18) + assert encryptor._bytes_processed == 33 + + def test_gcm_aad_increments(self, backend): + encryptor = base.Cipher( + algorithms.AES(b"\x00" * 16), + modes.GCM(b"\x01" * 16), + backend=backend + ).encryptor() + encryptor.authenticate_additional_data(b"0" * 8) + assert encryptor._aad_bytes_processed == 8 + encryptor.authenticate_additional_data(b"0" * 18) + assert encryptor._aad_bytes_processed == 26 |