MCPcopy
hub / github.com/pyca/cryptography / test_vectors_invalid

Method test_vectors_invalid

tests/hazmat/primitives/test_aead.py:1355–1386  ·  view source on GitHub ↗
(self, backend, subtests)

Source from the content-addressed store, hash-verified

1353 assert computed_pt == pt
1354
1355 def test_vectors_invalid(self, backend, subtests):
1356 vectors = _load_all_params(
1357 os.path.join("ciphers", "AES", "GCM-SIV"),
1358 [
1359 "openssl.txt",
1360 "aes-192-gcm-siv.txt",
1361 ],
1362 load_nist_vectors,
1363 )
1364 for vector in vectors:
1365 with subtests.test():
1366 key = binascii.unhexlify(vector["key"])
1367 nonce = binascii.unhexlify(vector["iv"])
1368 aad = binascii.unhexlify(vector.get("aad", b""))
1369 ct = binascii.unhexlify(vector["ciphertext"])
1370
1371 # AWS-LC and BoringSSL only support AES-GCM-SIV with
1372 # 128- and 256-bit keys
1373 if len(key) == 24 and (
1374 rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
1375 or rust_openssl.CRYPTOGRAPHY_IS_AWSLC
1376 ):
1377 continue
1378
1379 aesgcmsiv = AESGCMSIV(key)
1380 with pytest.raises(InvalidTag):
1381 badkey = AESGCMSIV(AESGCMSIV.generate_key(256))
1382 badkey.decrypt(nonce, ct, aad)
1383 with pytest.raises(InvalidTag):
1384 aesgcmsiv.decrypt(nonce, ct, b"nonsense")
1385 with pytest.raises(InvalidTag):
1386 aesgcmsiv.decrypt(nonce, b"nonsense", aad)
1387
1388 @pytest.mark.parametrize(
1389 ("nonce", "data", "associated_data"),

Callers

nothing calls this directly

Calls 5

_load_all_paramsFunction · 0.85
testMethod · 0.80
unhexlifyMethod · 0.80
generate_keyMethod · 0.80
decryptMethod · 0.45

Tested by

no test coverage detected