Add a KUnit test suite for the AES-GCM library API. It consists of: - All the shared test cases from aead-test-template.h. These include extensive consistency tests, a "Monte-Carlo test", and a benchmark. - Tests against hardcoded AES-GCM test vectors from external sources.
Showing the changes to scripts (1 of 5 files). Show all
Unified · Split
| @@ -41,6 +41,15 @@ def gen_monte_carlo_checksum(alg): · 40 unmodified lines | |||
| 41 | key, tag_length=tag_len | 41 | key, tag_length=tag_len |
| 42 | ) | 42 | ) |
| 43 | ct_and_tag = ccm.encrypt(nonce, pt, ad) | 43 | ct_and_tag = ccm.encrypt(nonce, pt, ad) |
| 44 | elif alg == "aes-gcm": | ||
| 45 | key_len = [16, 24, 32][data_len % 3] | ||
| 46 | key = rand_bytes(key_len) | ||
| 47 | nonce = rand_bytes(12) | ||
| 48 | tag_len = [4, 8, 12, 13, 14, 15, 16][data_len % 7] | ||
| 49 | gcm = cryptography.hazmat.primitives.ciphers.aead.AESGCM(key) | ||
| 50 | # python-cryptography supports only 16-byte GCM tags. However, in | ||
| 51 | # GCM, shorter tags are simply truncated. Do that below. | ||
| 52 | ct_and_tag = gcm.encrypt(nonce, pt, ad)[: data_len + tag_len] | ||
| 44 | 53 | ||
| 45 | blake2s.update(ct_and_tag) | 54 | blake2s.update(ct_and_tag) |
| 46 | 55 | ||
| @@ -53,8 +62,8 @@ def gen_monte_carlo_checksum(alg): · 6 unmodified lines | |||
| 53 | print("};") | 62 | print("};") |
| 54 | 63 | ||
| 55 | 64 | ||
| 56 | if len(sys.argv) != 2 or sys.argv[1] not in ("aes-ccm"): | 65 | if len(sys.argv) != 2 or sys.argv[1] not in ("aes-ccm", "aes-gcm"): |
| 57 | sys.stderr.write("Usage: gen-aead-testvecs.py [aes-ccm]\n") | 66 | sys.stderr.write("Usage: gen-aead-testvecs.py [aes-ccm|aes-gcm]\n") |
| 58 | sys.exit(1) | 67 | sys.exit(1) |
| 59 | 68 | ||
| 60 | gen_monte_carlo_checksum(sys.argv[1]) | 69 | gen_monte_carlo_checksum(sys.argv[1]) |