Skip to content

Commit 8d46eaf

Browse files
alexreaperhulk
authored andcommitted
Updated wycheproof tests for new upstream vectors (pyca#4378)
* updated tests for upstream wycheproof changes * Updated AES tests * oops, flake8
1 parent c37d11e commit 8d46eaf

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

tests/wycheproof/test_aes.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import pytest
1010

11+
from cryptography.exceptions import InvalidTag
1112
from cryptography.hazmat.backends.interfaces import CipherBackend
1213
from cryptography.hazmat.primitives import padding
1314
from cryptography.hazmat.primitives.ciphers import (
@@ -67,11 +68,19 @@ def test_aes_gcm(backend, wycheproof):
6768
dec.authenticate_additional_data(aad)
6869
computed_msg = dec.update(ct) + dec.finalize()
6970
assert computed_msg == msg
70-
else:
71-
# All invalid GCM tests are IV len 0 right now
72-
assert len(iv) == 0
71+
elif len(iv) == 0:
7372
with pytest.raises(ValueError):
7473
Cipher(algorithms.AES(key), modes.GCM(iv), backend)
74+
else:
75+
dec = Cipher(
76+
algorithms.AES(key),
77+
modes.GCM(iv, tag, min_tag_length=len(tag)),
78+
backend
79+
).decryptor()
80+
dec.authenticate_additional_data(aad)
81+
dec.update(ct)
82+
with pytest.raises(InvalidTag):
83+
dec.finalize()
7584

7685

7786
@pytest.mark.requires_backend_interface(interface=CipherBackend)
@@ -89,8 +98,9 @@ def test_aes_gcm_aead_api(backend, wycheproof):
8998
assert computed_ct == ct + tag
9099
computed_msg = aesgcm.decrypt(iv, ct + tag, aad)
91100
assert computed_msg == msg
92-
else:
93-
# All invalid GCM tests are IV len 0 right now
94-
assert len(iv) == 0
101+
elif len(iv) == 0:
95102
with pytest.raises(ValueError):
96103
aesgcm.encrypt(iv, msg, aad)
104+
else:
105+
with pytest.raises(InvalidTag):
106+
aesgcm.decrypt(iv, ct + tag, aad)

tests/wycheproof/test_ecdh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
"ecdh_secp521r1_test.json",
5151
)
5252
def test_ecdh(backend, wycheproof):
53-
curve = _CURVES[wycheproof.testcase["curve"]]
53+
curve = _CURVES[wycheproof.testgroup["curve"]]
5454
if curve is None:
5555
pytest.skip(
56-
"Unsupported curve ({})".format(wycheproof.testcase["curve"])
56+
"Unsupported curve ({})".format(wycheproof.testgroup["curve"])
5757
)
5858
_skip_exchange_algorithm_unsupported(backend, ec.ECDH(), curve)
5959

0 commit comments

Comments
 (0)