History

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.

Eric Biggers committed 3 months ago

Commit fbdb43c1 parent e967fa93 files · +113 −10Browse files

Showing the changes to scripts (1 of 3 files). Show all

Unified · Split

scripts/crypto/gen-fips-testvecs.py+23−0
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 # Copyright 2025 Google LLC
99
1010 import cryptography.hazmat.primitives.ciphers
11+import cryptography.hazmat.primitives.ciphers.aead
1112 import cryptography.hazmat.primitives.cmac
1213 import hashlib
1314 import hmac
@@ -32,12 +33,14 @@ def print_header(file): · 18 unmodified lines
3233
3334 def gen_aes_test_data(file):
3435 fips_test_data = b"fips test data\0\0"
36+ fips_test_ad = b"fips test ad\0\0\0\0"
3537 fips_test_iv = b"fips test iv\0\0\0\0"
3638 fips_test_key = b"fips test key\0\0\0"
3739 fips_test_xts_key = b"key1" + (b"\0" * 12) + b"key2" + (b"\0" * 12)
3840
3941 print_header(file)
4042 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)
4144 print_static_u8_array_definition(file, "fips_test_iv", fips_test_iv)
4245 print_static_u8_array_definition(file, "fips_test_key", fips_test_key)
4346 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
9396 ctext = encryptor.update(fips_test_data) + encryptor.finalize()
9497 print_static_u8_array_definition(file, "fips_test_aes_xts_ctext", ctext)
9598
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+
96119
97120 def gen_sha_test_data(file):
98121 fips_test_data = b"fips test data\0\0"