From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
"Jason A . Donenfeld" <Jason@zx2c4.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH] lib/crypto: tests: Test some longer lengths in AEAD tests
Date: Sat, 5 Dec 2026 22:58:47 -0800 [thread overview]
Message-ID: <20261206065847.452749-1-ebiggers@kernel.org> (raw)
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 <ebiggers@kernel.org>
---
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
next reply other threads:[~2026-12-06 6:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 6:58 Eric Biggers [this message]
2026-12-06 7:08 ` [PATCH] lib/crypto: tests: Test some longer lengths in AEAD tests sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261206065847.452749-1-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox