All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/crypto: tests: Test some longer lengths in skcipher tests
@ 2026-12-06  6:58 Eric Biggers
  2026-12-06  7:07 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2026-12-06  6:58 UTC (permalink / raw)
  To: linux-crypto
  Cc: Ard Biesheuvel, Jason A . Donenfeld, Herbert Xu, Eric Biggers

Make test_skcipher_monte_carlo() test some data lengths up to 65536
bytes.  Previously, it just tested data lengths up to 1024 bytes.

This is needed to properly test arch-optimized implementations that
process data in a non-preemptible context which they yield occasionally.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 lib/crypto/tests/aes_cbc_cts_kunit.c      |  6 +++---
 lib/crypto/tests/aes_cbc_kunit.c          |  6 +++---
 lib/crypto/tests/aes_ctr_kunit.c          |  6 +++---
 lib/crypto/tests/aes_ecb_kunit.c          |  6 +++---
 lib/crypto/tests/aes_xctr_kunit.c         |  6 +++---
 lib/crypto/tests/aes_xts_kunit.c          |  6 +++---
 lib/crypto/tests/skcipher-test-template.h | 20 +++++++++++++-------
 scripts/crypto/gen-skcipher-testvecs.py   | 18 +++++++++++++++++-
 8 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/lib/crypto/tests/aes_cbc_cts_kunit.c b/lib/crypto/tests/aes_cbc_cts_kunit.c
index 2890515ded0f7..8e586c22f3b43 100644
--- a/lib/crypto/tests/aes_cbc_cts_kunit.c
+++ b/lib/crypto/tests/aes_cbc_cts_kunit.c
@@ -39,9 +39,9 @@ static const size_t aes_cbc_cts_valid_key_lens[] = { AES_KEYSIZE_128,
 
 /* This value was generated by gen-skcipher-testvecs.py. */
 static const u8 aes_cbc_cts_monte_carlo_checksum[BLAKE2S_HASH_SIZE] = {
-	0x9a, 0xc5, 0x99, 0xaf, 0x25, 0x2d, 0x56, 0x52, 0xd6, 0x50, 0x14,
-	0x33, 0x61, 0x0b, 0xb6, 0x40, 0x5e, 0xc5, 0x9c, 0x8e, 0xfd, 0x6c,
-	0xae, 0xa1, 0x1d, 0x47, 0x43, 0xd4, 0x19, 0x01, 0xc9, 0x6b,
+	0xca, 0x23, 0x11, 0xfa, 0x5a, 0x6a, 0xcd, 0x8d, 0x81, 0xbe, 0xe4,
+	0x6c, 0xb0, 0x7f, 0x32, 0x7a, 0x94, 0x7a, 0x30, 0x88, 0xbf, 0x43,
+	0x46, 0x91, 0x22, 0xac, 0x99, 0x52, 0xd8, 0x8b, 0x8c, 0xbe,
 };
 #define SKCIPHER_MONTE_CARLO_CHECKSUM aes_cbc_cts_monte_carlo_checksum
 
diff --git a/lib/crypto/tests/aes_cbc_kunit.c b/lib/crypto/tests/aes_cbc_kunit.c
index 775a67b483593..4eed43e58a0fd 100644
--- a/lib/crypto/tests/aes_cbc_kunit.c
+++ b/lib/crypto/tests/aes_cbc_kunit.c
@@ -42,9 +42,9 @@ static const size_t aes_cbc_valid_key_lens[] = { AES_KEYSIZE_128,
 
 /* This value was generated by gen-skcipher-testvecs.py. */
 static const u8 aes_cbc_monte_carlo_checksum[BLAKE2S_HASH_SIZE] = {
-	0x87, 0xfd, 0xb4, 0x92, 0xde, 0x3e, 0x69, 0xac, 0xe2, 0x78, 0xdf,
-	0x23, 0xbe, 0x6f, 0x2f, 0xcc, 0x32, 0x98, 0x10, 0x89, 0x63, 0x64,
-	0x1c, 0xff, 0x76, 0xe5, 0x4f, 0x31, 0x90, 0xf3, 0x2c, 0x7a,
+	0xce, 0x8e, 0x34, 0x8f, 0x3e, 0x04, 0xd1, 0x40, 0x26, 0x43, 0xc7,
+	0xf4, 0x3b, 0xa2, 0x3b, 0x17, 0xfd, 0xd6, 0x45, 0x92, 0x4d, 0x8c,
+	0x2f, 0xc3, 0x25, 0xe8, 0x05, 0xcd, 0x38, 0xaa, 0xde, 0xb1,
 };
 #define SKCIPHER_MONTE_CARLO_CHECKSUM aes_cbc_monte_carlo_checksum
 
diff --git a/lib/crypto/tests/aes_ctr_kunit.c b/lib/crypto/tests/aes_ctr_kunit.c
index 344fc9e9571db..8e62621698f73 100644
--- a/lib/crypto/tests/aes_ctr_kunit.c
+++ b/lib/crypto/tests/aes_ctr_kunit.c
@@ -37,9 +37,9 @@ static const size_t aes_ctr_valid_key_lens[] = { AES_KEYSIZE_128,
 
 /* This value was generated by gen-skcipher-testvecs.py. */
 static const u8 aes_ctr_monte_carlo_checksum[BLAKE2S_HASH_SIZE] = {
-	0x1e, 0x14, 0xcd, 0x03, 0x44, 0x7d, 0x85, 0xa3, 0x4b, 0xdc, 0x97,
-	0xd4, 0xb8, 0x0d, 0x06, 0xd8, 0x53, 0x66, 0x75, 0xde, 0x62, 0xd5,
-	0x4e, 0x01, 0xc8, 0xf0, 0x1b, 0xb6, 0xbd, 0xc6, 0xd8, 0x9e,
+	0x0e, 0xc1, 0xfb, 0xb4, 0x40, 0xf6, 0xfa, 0x54, 0x40, 0xd7, 0x50,
+	0x5f, 0xc5, 0xc3, 0x15, 0x0f, 0x69, 0x85, 0x8a, 0xc3, 0x61, 0x6d,
+	0xc7, 0xd3, 0xba, 0xd8, 0x11, 0x00, 0x8d, 0x67, 0xc0, 0xfc,
 };
 #define SKCIPHER_MONTE_CARLO_CHECKSUM aes_ctr_monte_carlo_checksum
 
diff --git a/lib/crypto/tests/aes_ecb_kunit.c b/lib/crypto/tests/aes_ecb_kunit.c
index b73e2c7f725a4..a9e1194267a0c 100644
--- a/lib/crypto/tests/aes_ecb_kunit.c
+++ b/lib/crypto/tests/aes_ecb_kunit.c
@@ -42,9 +42,9 @@ static const size_t aes_ecb_valid_key_lens[] = { AES_KEYSIZE_128,
 
 /* This value was generated by gen-skcipher-testvecs.py. */
 static const u8 aes_ecb_monte_carlo_checksum[BLAKE2S_HASH_SIZE] = {
-	0xf7, 0x96, 0x84, 0x87, 0xc7, 0xcb, 0x57, 0xb5, 0xb3, 0x5a, 0xbe,
-	0x57, 0xf6, 0x0e, 0x90, 0x3a, 0x8e, 0x64, 0xd8, 0x7f, 0xbc, 0x3e,
-	0x8f, 0x6f, 0x57, 0x32, 0xc2, 0x56, 0x73, 0x44, 0xf1, 0x9a,
+	0xb7, 0x08, 0x5a, 0x02, 0x46, 0x4c, 0x97, 0x36, 0x06, 0x61, 0x0f,
+	0x88, 0x1e, 0x0b, 0x74, 0xe9, 0x49, 0x29, 0x0b, 0x97, 0x5b, 0x4e,
+	0xe6, 0x8e, 0xf2, 0x49, 0x57, 0x0e, 0xad, 0x47, 0xea, 0x13,
 };
 #define SKCIPHER_MONTE_CARLO_CHECKSUM aes_ecb_monte_carlo_checksum
 
diff --git a/lib/crypto/tests/aes_xctr_kunit.c b/lib/crypto/tests/aes_xctr_kunit.c
index 86fe4356cb66e..20056d192d5ce 100644
--- a/lib/crypto/tests/aes_xctr_kunit.c
+++ b/lib/crypto/tests/aes_xctr_kunit.c
@@ -48,9 +48,9 @@ static const size_t aes_xctr_valid_key_lens[] = { AES_KEYSIZE_128,
 
 /* This value was generated by gen-skcipher-testvecs.py. */
 static const u8 aes_xctr_monte_carlo_checksum[BLAKE2S_HASH_SIZE] = {
-	0x40, 0xc0, 0x13, 0x02, 0xc6, 0x12, 0x5c, 0x86, 0xce, 0x85, 0x9d,
-	0xcb, 0x8f, 0x9b, 0xda, 0x17, 0x6f, 0x15, 0x73, 0x71, 0x0f, 0x6c,
-	0x68, 0x41, 0xb5, 0x7d, 0x29, 0xe9, 0xb1, 0xb5, 0xa4, 0xb5,
+	0xb8, 0xea, 0x04, 0xc7, 0xbc, 0xf2, 0x45, 0x35, 0x23, 0x69, 0x3a,
+	0x45, 0xec, 0xca, 0xe3, 0x3e, 0xcc, 0xd1, 0x3d, 0xb0, 0x6d, 0xc9,
+	0x2f, 0xe6, 0x80, 0xf1, 0xe5, 0x07, 0x96, 0xa9, 0x97, 0xa2,
 };
 #define SKCIPHER_MONTE_CARLO_CHECKSUM aes_xctr_monte_carlo_checksum
 
diff --git a/lib/crypto/tests/aes_xts_kunit.c b/lib/crypto/tests/aes_xts_kunit.c
index b45741567d2f6..3c699950604ab 100644
--- a/lib/crypto/tests/aes_xts_kunit.c
+++ b/lib/crypto/tests/aes_xts_kunit.c
@@ -41,9 +41,9 @@ static const size_t aes_xts_valid_key_lens[] = { 2 * AES_KEYSIZE_128,
 
 /* This value was generated by gen-skcipher-testvecs.py. */
 static const u8 aes_xts_monte_carlo_checksum[BLAKE2S_HASH_SIZE] = {
-	0x24, 0x93, 0x8f, 0x89, 0x72, 0x6f, 0xfb, 0x59, 0x4a, 0xea, 0x32,
-	0x74, 0x15, 0x6a, 0x8f, 0x9a, 0xba, 0xde, 0x9e, 0xc3, 0x5c, 0x58,
-	0x98, 0xa9, 0xb6, 0x9f, 0xeb, 0xe5, 0xfb, 0x3a, 0xf0, 0x87,
+	0x42, 0x47, 0xac, 0xd1, 0x0c, 0x0d, 0x0b, 0x14, 0x8e, 0xcb, 0x04,
+	0x9b, 0x74, 0xc6, 0xee, 0xe1, 0xff, 0xe4, 0x86, 0xed, 0x38, 0x93,
+	0xba, 0xde, 0x61, 0x58, 0x83, 0x34, 0xb5, 0xe2, 0x4d, 0x84,
 };
 #define SKCIPHER_MONTE_CARLO_CHECKSUM aes_xts_monte_carlo_checksum
 
diff --git a/lib/crypto/tests/skcipher-test-template.h b/lib/crypto/tests/skcipher-test-template.h
index e68be28b003b9..268af5f381426 100644
--- a/lib/crypto/tests/skcipher-test-template.h
+++ b/lib/crypto/tests/skcipher-test-template.h
@@ -394,15 +394,20 @@ static void test_skcipher_all_key_lens(struct kunit *test)
 
 /*
  * Monte-Carlo test.  This deterministically generates random inputs for every
- * valid data length up to 1024 bytes, encrypts them, verifies decryption, and
- * computes and verifies the checksum of all the computed ciphertexts.  The
- * expected checksum was computed using an independent implementation of the
- * algorithm (see scripts/crypto/gen-skcipher-testvecs.py), so this test
- * provides known-answer test coverage for many inputs at once.
+ * valid data length up to 1024 bytes as well as some longer lengths up to 64
+ * KiB, encrypts them, verifies decryption, and computes and verifies the
+ * checksum of all the computed ciphertexts.  The expected checksum was computed
+ * using an independent implementation of the algorithm (see
+ * scripts/crypto/gen-skcipher-testvecs.py), so this test provides known-answer
+ * test coverage for many inputs at once.
  */
 static void test_skcipher_monte_carlo(struct kunit *test)
 {
-	const size_t max_data_len = 1024;
+	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;
 	u8 raw_key[SKCIPHER_MAX_KEY_LEN];
 	u8 orig_iv[SKCIPHER_IV_BUF_SIZE];
 	u8 iv[SKCIPHER_IV_BUF_SIZE];
@@ -428,7 +433,8 @@ static void test_skcipher_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++) {
+	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 key_len;
 
 		if (!skcipher_is_data_len_valid(data_len))
diff --git a/scripts/crypto/gen-skcipher-testvecs.py b/scripts/crypto/gen-skcipher-testvecs.py
index 8e2d8c6be59b3..e97a51183de22 100755
--- a/scripts/crypto/gen-skcipher-testvecs.py
+++ b/scripts/crypto/gen-skcipher-testvecs.py
@@ -141,7 +141,23 @@ MODES = {
 def gen_monte_carlo_checksum(alg):
     encrypt, key_lens, iv_size, min_data_len, data_len_align = MODES[alg]
     blake2s = hashlib.blake2s()
-    for data_len in range(1025):
+    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:
         if data_len < min_data_len or data_len % data_len_align != 0:
             continue
         rng = Rng(data_len)

base-commit: 84a878a7122a3d341e8ec2675cf9ad2d65217c6e
-- 
2.98.0.rc0.2.g460126620f


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-06  7:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06  6:58 [PATCH] lib/crypto: tests: Test some longer lengths in skcipher tests Eric Biggers
2026-12-06  7:07 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.