From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796540333; b=nyjWWKvIjSvdlvkSMmdwMRri1/Hf5NiVVOocu5pDVRMkUdtayv8GOubStGVYgzzhRlBz UaF0cyX79Uhg0HRyNlwtcpsSs+xrGkTecI7n6HG+k77rxOuMmln1YFW7a3JBfMrWrnw2p elinvA7ZN+aXC+c/R2V30ONb4Kiogcw6UHkq7c0eyhjRGuPHxh9qxjzDW9Bb7eckNxRek p7le5j+YF1MWf+52JpIwX4zvh3tzGJLqnzzXwO9P4Wk/aDT0NtZ1MVuIinEAzNISqlybw tAa2CSm11bTv+90XREzTzC2Xsa65+338E9khsre0lam8xGcOvCf4j96Xaj/eIrtwJ+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796540333; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=nJhw1lsXuZ0fWi266ERDad1qVjuKeypjeHC2RAiFcFE=; b=5pr3uP3KYg+hKOjexU8fMeXgi9uUqeILVUH3TD9vbKcsNP+ArxfQb9weZQ6hp2NgIod0 ekTNGZ4BEgwB1tCprMfzultMvZjIX/YBLBQmkz54EsgF0G39ywEiHEQIDxBLwhU+qPB4T WNaJEB4w8oxJMYyTZrTu1Eh3216oyNslkQNt95CklfGxyfESNrq+K8xCgPpifGEU6ZyK2 Yj7w/MeRMgtM8kgtY+iky+bA8oTVg6gGL9NlrtTuNhKNy3ruFLOvSYwteq2a1F4/BXxLu b4/SYeiA3B0XW6ex+u1btcD3uAN0PVVV1TIfailv5dwX/A+QkXYPCegy8erciom9u/w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OT9cgp1J; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A389606A31F for ; Sun, 6 Dec 2026 06:58:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OT9cgp1J Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0524E1F0093B; Sun, 6 Dec 2026 06:58:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796540333; bh=nJhw1lsXuZ0fWi266ERDad1qVjuKeypjeHC2RAiFcFE=; h=From:To:Cc:Subject:Date; b=OT9cgp1JsP/Una1ikaxOD6Uz/oO5MYOXZdju61UJFK0OxnHJH6NInCS1FZ/g3sRnw 0tatx/ALmLIxZLLIYSCVxU3mtyg01NWEzWjds3dVjOqiayEM4sffGDdNqSJZmUASoi AVpcAPNuSZpwoEsCkt3HaoBmqGLJwW7wvcnlIBGhLBrwZSNSjoNKQxLsB1V8IZa/ma b7i00no54VsREgs8gw8cKVPUec58B5iTXXBDB4NTthh0izyVqcaliPN27tYqGE3KCH KAxRt23PN3P6SIRcsNa7SXG95njMUAp7iuJXS0AE7Uw8smMSDYbN7I9rw/yHg8vNEh n5JWXLxFNyjhQ== From: Eric Biggers To: linux-crypto@vger.kernel.org Cc: Ard Biesheuvel , "Jason A . Donenfeld" , Herbert Xu , Eric Biggers Subject: [PATCH] lib/crypto: tests: Test some longer lengths in AEAD tests Date: Sat, 5 Dec 2026 22:58:47 -0800 Message-ID: <20261206065847.452749-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.98.0.rc0.2.g460126620f X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Make test_aead_monte_carlo() test some en/decrypted and associated data lengths up to 65536 bytes. Previously, it just tested en/decrypted data lengths up to 1024 bytes and associated data lengths up to 292 bytes. This is needed to properly test arch-optimized implementations that process data in a non-preemptible context which they yield occasionally, such as the x86 AES-GCM code. Signed-off-by: Eric Biggers --- lib/crypto/tests/aead-test-template.h | 21 +++++++++++++++------ lib/crypto/tests/aes_ccm_kunit.c | 6 +++--- lib/crypto/tests/aes_gcm_kunit.c | 6 +++--- scripts/crypto/gen-aead-testvecs.py | 20 ++++++++++++++++++-- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/lib/crypto/tests/aead-test-template.h b/lib/crypto/tests/aead-test-template.h index 7689567c86f9b..a841a51bc3426 100644 --- a/lib/crypto/tests/aead-test-template.h +++ b/lib/crypto/tests/aead-test-template.h @@ -738,13 +738,21 @@ static void test_aead_inplace(struct kunit *test) /* * Monte-Carlo test for AEAD algorithms. This deterministically generates - * random AEAD inputs, encrypts them, verifies decryption, and computes and - * verifies the checksum of all computed (ciphertext, tag) pairs. + * random AEAD inputs for every en/decrypted data length up to 1024 bytes and + * every associated data length up to 292 bytes as well as some longer lengths + * up to 64 KiB for both, encrypts them, verifies decryption, and computes and + * verifies the checksum of all computed (ciphertext, tag) pairs. The expected + * checksum was computed using an independent implementation of the algorithm + * (see scripts/crypto/gen-aead-testvecs.py). */ static void test_aead_monte_carlo(struct kunit *test) { - const size_t max_data_len = 1024; - const size_t max_ad_len = 293; + static const size_t extra_lens[] = { + 4096, 4111, 8192, 16384, 16400, 32752, 32767, + 32768, 32769, 32784, 49152, 65520, 65535, 65536, + }; + const size_t max_data_len = 65536; + const size_t max_ad_len = 65536; u8 raw_key[AEAD_MAX_KEY_LEN]; u8 nonce[AEAD_MAX_NONCE_LEN]; u8 tag[AEAD_MAX_TAG_LEN]; @@ -759,8 +767,9 @@ static void test_aead_monte_carlo(struct kunit *test) blake2s_init(&checksum_ctx, BLAKE2S_HASH_SIZE); - for (size_t data_len = 0; data_len <= max_data_len; data_len++) { - size_t ad_len = data_len % max_ad_len; + for (size_t i = 0; i < 1025 + ARRAY_SIZE(extra_lens); i++) { + size_t data_len = i <= 1024 ? i : extra_lens[i - 1025]; + size_t ad_len = data_len <= 1024 ? data_len % 293 : data_len; size_t key_len = AEAD_VALID_KEY_LENS[data_len % ARRAY_SIZE(AEAD_VALID_KEY_LENS)]; diff --git a/lib/crypto/tests/aes_ccm_kunit.c b/lib/crypto/tests/aes_ccm_kunit.c index e8f2b34460173..497c95d051d31 100644 --- a/lib/crypto/tests/aes_ccm_kunit.c +++ b/lib/crypto/tests/aes_ccm_kunit.c @@ -251,9 +251,9 @@ static const size_t aes_ccm_valid_tag_lens[] = { 4, 6, 8, 10, 12, 14, 16 }; /* This value was generated by gen-aead-testvecs.py. */ static const u8 aes_ccm_monte_carlo_checksum[BLAKE2S_HASH_SIZE] = { - 0x70, 0x1c, 0xde, 0xa4, 0xe2, 0x03, 0x50, 0xb2, 0xf5, 0x9e, 0x61, - 0x66, 0xe4, 0xe5, 0x13, 0x1a, 0x00, 0x95, 0x34, 0x03, 0xb7, 0x61, - 0x2c, 0xdb, 0xc3, 0x15, 0x36, 0x84, 0x93, 0x7f, 0xb4, 0x5b, + 0x71, 0xed, 0x72, 0xa2, 0x5a, 0xdf, 0xd3, 0xe6, 0x79, 0x17, 0x82, + 0xf7, 0x83, 0x97, 0x22, 0x4a, 0xe2, 0x11, 0xf9, 0xff, 0x9c, 0x0a, + 0x56, 0xc2, 0x8e, 0x12, 0xfb, 0x41, 0xbc, 0xff, 0xe1, 0x53, }; #define AEAD_MONTE_CARLO_CHECKSUM aes_ccm_monte_carlo_checksum diff --git a/lib/crypto/tests/aes_gcm_kunit.c b/lib/crypto/tests/aes_gcm_kunit.c index 6959d86b316a7..6e73327833d9a 100644 --- a/lib/crypto/tests/aes_gcm_kunit.c +++ b/lib/crypto/tests/aes_gcm_kunit.c @@ -448,9 +448,9 @@ static const size_t aes_gcm_valid_tag_lens[] = { 4, 8, 12, 13, 14, 15, 16 }; /* This value was generated by gen-aead-testvecs.py. */ static const u8 aes_gcm_monte_carlo_checksum[BLAKE2S_HASH_SIZE] = { - 0x6d, 0xd0, 0x6e, 0x6b, 0xde, 0x3e, 0x92, 0x9f, 0xae, 0x1f, 0xf1, - 0x84, 0x99, 0x5a, 0x9e, 0x7b, 0xfe, 0x20, 0x9e, 0x22, 0x7c, 0x5f, - 0x15, 0xb3, 0x59, 0x89, 0xd0, 0xb7, 0x74, 0x5d, 0xd2, 0xa5, + 0x03, 0xd7, 0xff, 0xd2, 0x7d, 0x77, 0x15, 0xdc, 0x4a, 0x72, 0x85, + 0xbf, 0x03, 0x42, 0xa9, 0x06, 0x63, 0x98, 0x76, 0x52, 0xf1, 0x03, + 0x92, 0x8f, 0x09, 0xf5, 0xd4, 0x01, 0xdd, 0x72, 0x66, 0x73, }; #define AEAD_MONTE_CARLO_CHECKSUM aes_gcm_monte_carlo_checksum diff --git a/scripts/crypto/gen-aead-testvecs.py b/scripts/crypto/gen-aead-testvecs.py index d77d646f75b54..73728fb21feaa 100755 --- a/scripts/crypto/gen-aead-testvecs.py +++ b/scripts/crypto/gen-aead-testvecs.py @@ -28,8 +28,24 @@ def rand_bytes(length): # pairs concatenated to each other; and print the checksum as a C struct. def gen_monte_carlo_checksum(alg): blake2s = hashlib.blake2s() - for data_len in range(1025): - ad_len = data_len % 293 + extra_lens = [ + 4096, + 4111, + 8192, + 16384, + 16400, + 32752, + 32767, + 32768, + 32769, + 32784, + 49152, + 65520, + 65535, + 65536, + ] + for data_len in list(range(1025)) + extra_lens: + ad_len = data_len % 293 if data_len <= 1024 else data_len pt = rand_bytes(data_len) ad = rand_bytes(ad_len) if alg == "aes-ccm": base-commit: 84a878a7122a3d341e8ec2675cf9ad2d65217c6e -- 2.98.0.rc0.2.g460126620f