diff options
| author | Eric Biggers <ebiggers@kernel.org> | 2026-08-02 15:24:08 -0700 |
|---|---|---|
| committer | Eric Biggers <ebiggers@kernel.org> | 2026-08-10 20:17:56 -0700 |
| commit | fbdb43c0007b37e574fa0ca76afd13bed96db8f6 (patch) | |
| tree | fafe26a7c50c3bbabc245b28f7c3d7375a1ee9aa /scripts | |
| parent | e967fa98f7618e98b50b3d49a1768deba8981a98 (diff) | |
| download | linux-next-fbdb43c0007b37e574fa0ca76afd13bed96db8f6.tar.gz linux-next-fbdb43c0007b37e574fa0ca76afd13bed96db8f6.zip | |
lib/crypto: aes: Add FIPS self-tests for GCM and CCM
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.
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://patch.msgid.link/20260802222408.91757-4-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/crypto/gen-fips-testvecs.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/scripts/crypto/gen-fips-testvecs.py b/scripts/crypto/gen-fips-testvecs.py index a79eaf081c26..b8c8a78cb8a8 100755 --- a/scripts/crypto/gen-fips-testvecs.py +++ b/scripts/crypto/gen-fips-testvecs.py @@ -8,6 +8,7 @@ # Copyright 2025 Google LLC import cryptography.hazmat.primitives.ciphers +import cryptography.hazmat.primitives.ciphers.aead import cryptography.hazmat.primitives.cmac import hashlib import hmac @@ -32,12 +33,14 @@ def print_header(file): def gen_aes_test_data(file): fips_test_data = b"fips test data\0\0" + fips_test_ad = b"fips test ad\0\0\0\0" fips_test_iv = b"fips test iv\0\0\0\0" fips_test_key = b"fips test key\0\0\0" fips_test_xts_key = b"key1" + (b"\0" * 12) + b"key2" + (b"\0" * 12) print_header(file) print_static_u8_array_definition(file, "fips_test_data", fips_test_data) + print_static_u8_array_definition(file, "fips_test_ad", fips_test_ad) print_static_u8_array_definition(file, "fips_test_iv", fips_test_iv) print_static_u8_array_definition(file, "fips_test_key", fips_test_key) print_static_u8_array_definition(file, "fips_test_xts_key", fips_test_xts_key) @@ -93,6 +96,26 @@ def gen_aes_test_data(file): ctext = encryptor.update(fips_test_data) + encryptor.finalize() print_static_u8_array_definition(file, "fips_test_aes_xts_ctext", ctext) + # AES-GCM + cipher = cryptography.hazmat.primitives.ciphers.aead.AESGCM(fips_test_key) + ct_and_tag = cipher.encrypt( + nonce=fips_test_iv[:12], data=fips_test_data, associated_data=fips_test_ad + ) + print_static_u8_array_definition( + file, "fips_test_aes_gcm_ctext_and_tag", ct_and_tag + ) + + # AES-CCM + cipher = cryptography.hazmat.primitives.ciphers.aead.AESCCM( + fips_test_key, tag_length=16 + ) + ct_and_tag = cipher.encrypt( + nonce=fips_test_iv[:13], data=fips_test_data, associated_data=fips_test_ad + ) + print_static_u8_array_definition( + file, "fips_test_aes_ccm_ctext_and_tag", ct_and_tag + ) + def gen_sha_test_data(file): fips_test_data = b"fips test data\0\0" |
