Upcoming changes will wire up architecture-optimized implementations of GCM and CCM. FIPS labs can consider such designs to meet the threshold for separate self-tests to be needed. Therefore, add FIPS self-tests for encryption and decryption in these modes.
Showing the changes to scripts (1 of 3 files). Show all
Unified · Split
| @@ -8,6 +8,7 @@ · 7 unmodified lines | ||
| 8 | 8 | # Copyright 2025 Google LLC |
| 9 | 9 | |
| 10 | 10 | import cryptography.hazmat.primitives.ciphers |
| 11 | +import cryptography.hazmat.primitives.ciphers.aead | |
| 11 | 12 | import cryptography.hazmat.primitives.cmac |
| 12 | 13 | import hashlib |
| 13 | 14 | import hmac |
| @@ -32,12 +33,14 @@ def print_header(file): · 18 unmodified lines | ||
| 32 | 33 | |
| 33 | 34 | def gen_aes_test_data(file): |
| 34 | 35 | fips_test_data = b"fips test data\0\0" |
| 36 | + fips_test_ad = b"fips test ad\0\0\0\0" | |
| 35 | 37 | fips_test_iv = b"fips test iv\0\0\0\0" |
| 36 | 38 | fips_test_key = b"fips test key\0\0\0" |
| 37 | 39 | fips_test_xts_key = b"key1" + (b"\0" * 12) + b"key2" + (b"\0" * 12) |
| 38 | 40 | |
| 39 | 41 | print_header(file) |
| 40 | 42 | print_static_u8_array_definition(file, "fips_test_data", fips_test_data) |
| 43 | + print_static_u8_array_definition(file, "fips_test_ad", fips_test_ad) | |
| 41 | 44 | print_static_u8_array_definition(file, "fips_test_iv", fips_test_iv) |
| 42 | 45 | print_static_u8_array_definition(file, "fips_test_key", fips_test_key) |
| 43 | 46 | print_static_u8_array_definition(file, "fips_test_xts_key", fips_test_xts_key) |
| @@ -93,6 +96,26 @@ def gen_aes_test_data(file): · 49 unmodified lines | ||
| 93 | 96 | ctext = encryptor.update(fips_test_data) + encryptor.finalize() |
| 94 | 97 | print_static_u8_array_definition(file, "fips_test_aes_xts_ctext", ctext) |
| 95 | 98 | |
| 99 | + # AES-GCM | |
| 100 | + cipher = cryptography.hazmat.primitives.ciphers.aead.AESGCM(fips_test_key) | |
| 101 | + ct_and_tag = cipher.encrypt( | |
| 102 | + nonce=fips_test_iv[:12], data=fips_test_data, associated_data=fips_test_ad | |
| 103 | + ) | |
| 104 | + print_static_u8_array_definition( | |
| 105 | + file, "fips_test_aes_gcm_ctext_and_tag", ct_and_tag | |
| 106 | + ) | |
| 107 | + | |
| 108 | + # AES-CCM | |
| 109 | + cipher = cryptography.hazmat.primitives.ciphers.aead.AESCCM( | |
| 110 | + fips_test_key, tag_length=16 | |
| 111 | + ) | |
| 112 | + ct_and_tag = cipher.encrypt( | |
| 113 | + nonce=fips_test_iv[:13], data=fips_test_data, associated_data=fips_test_ad | |
| 114 | + ) | |
| 115 | + print_static_u8_array_definition( | |
| 116 | + file, "fips_test_aes_ccm_ctext_and_tag", ct_and_tag | |
| 117 | + ) | |
| 118 | + | |
| 96 | 119 | |
| 97 | 120 | def gen_sha_test_data(file): |
| 98 | 121 | fips_test_data = b"fips test data\0\0" |