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
8# Copyright 2025 Google LLC8# Copyright 2025 Google LLC
9 9
10import cryptography.hazmat.primitives.ciphers10import cryptography.hazmat.primitives.ciphers
11import cryptography.hazmat.primitives.ciphers.aead
11import cryptography.hazmat.primitives.cmac12import cryptography.hazmat.primitives.cmac
12import hashlib13import hashlib
13import hmac14import hmac
@@ -32,12 +33,14 @@ def print_header(file): · 18 unmodified lines
32 33
33def gen_aes_test_data(file):34def gen_aes_test_data(file):
34 fips_test_data = b"fips test data\0\0"35 fips_test_data = b"fips test data\0\0"
36 fips_test_ad = b"fips test ad\0\0\0\0"
35 fips_test_iv = b"fips test iv\0\0\0\0"37 fips_test_iv = b"fips test iv\0\0\0\0"
36 fips_test_key = b"fips test key\0\0\0"38 fips_test_key = b"fips test key\0\0\0"
37 fips_test_xts_key = b"key1" + (b"\0" * 12) + b"key2" + (b"\0" * 12)39 fips_test_xts_key = b"key1" + (b"\0" * 12) + b"key2" + (b"\0" * 12)
38 40
39 print_header(file)41 print_header(file)
40 print_static_u8_array_definition(file, "fips_test_data", fips_test_data)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 print_static_u8_array_definition(file, "fips_test_iv", fips_test_iv)44 print_static_u8_array_definition(file, "fips_test_iv", fips_test_iv)
42 print_static_u8_array_definition(file, "fips_test_key", fips_test_key)45 print_static_u8_array_definition(file, "fips_test_key", fips_test_key)
43 print_static_u8_array_definition(file, "fips_test_xts_key", fips_test_xts_key)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 ctext = encryptor.update(fips_test_data) + encryptor.finalize()96 ctext = encryptor.update(fips_test_data) + encryptor.finalize()
94 print_static_u8_array_definition(file, "fips_test_aes_xts_ctext", ctext)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
97def gen_sha_test_data(file):120def gen_sha_test_data(file):
98 fips_test_data = b"fips test data\0\0"121 fips_test_data = b"fips test data\0\0"