lib/crypto: tests: Migrate ChaCha20Poly1305 self-test to KUnit
Subsystems (2)
Eric Biggers
maintainerPATCH 1/1 lib/crypto: tests: Migrate ChaCha20Poly1305 self-test to KUnit
Move the ChaCha20Poly1305 test from an ad-hoc self-test to a KUnit test.
Keep the same test logic for now, just translated to KUnit.
Moving to KUnit has multiple benefits, such as:
- Consistency with the rest of the lib/crypto/ tests.
- Kernel developers familiar with KUnit, which is used kernel-wide, can quickly understand the test and how to enable and run it.
- The test will be automatically run by anyone using lib/crypto/.kunitconfig or KUnit's all_tests.config.
- Results are reported using the standard KUnit mechanism.
- It eliminates one of the few remaining back-references to crypto/ from lib/crypto/, specifically a reference to CONFIG_CRYPTO_SELFTESTS.
---
include/crypto/chacha20poly1305.h | 2 -
lib/crypto/.kunitconfig | 1 +
lib/crypto/Makefile | 1 -
lib/crypto/chacha20poly1305.c | 14 -
lib/crypto/tests/Kconfig | 10 +
lib/crypto/tests/Makefile | 1 +
.../chacha20poly1305_kunit.c} | 1493 +++++++++--------
7 files changed, 760 insertions(+), 762 deletions(-)
rename lib/crypto/{chacha20poly1305-selftest.c => tests/chacha20poly1305_kunit.c} (91%)include/crypto/chacha20poly1305.h +0 -2
@@ -44,8 +44,6 @@ bool chacha20poly1305_encrypt_sg_inplace(struct scatterlist *src, size_t src_lenbool chacha20poly1305_decrypt_sg_inplace (struct scatterlist *src,size_t src_len,const u8 *ad,const size_t ad_len,const u64 nonce, const u8 key[at_least CHACHA20POLY1305_KEY_SIZE]); -bool chacha20poly1305_selftest (void ); -#endif /* __CHACHA20POLY1305_H */
lib/crypto/.kunitconfig +1 -0
@@ -3,10 +3,11 @@ CONFIG_KUNIT=y CONFIG_CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT=y CONFIG_CRYPTO_LIB_AES_CBC_MACS_KUNIT_TEST=y CONFIG_CRYPTO_LIB_BLAKE2B_KUNIT_TEST=y CONFIG_CRYPTO_LIB_BLAKE2S_KUNIT_TEST=y +CONFIG_CRYPTO_LIB_CHACHA20POLY1305_KUNIT_TEST=y CONFIG_CRYPTO_LIB_CURVE25519_KUNIT_TEST=y CONFIG_CRYPTO_LIB_GHASH_KUNIT_TEST=y CONFIG_CRYPTO_LIB_MD5_KUNIT_TEST=y CONFIG_CRYPTO_LIB_MLDSA_KUNIT_TEST=y CONFIG_CRYPTO_LIB_NH_KUNIT_TEST=y
lib/crypto/Makefile +0 -1
@@ -120,11 +120,10 @@ endif # CONFIG_CRYPTO_LIB_CHACHA_ARCH ################################################################################ obj-$(CONFIG_CRYPTO_LIB_CHACHA20POLY1305) += libchacha20poly1305.o libchacha20poly1305-y += chacha20poly1305.o -libchacha20poly1305-$(CONFIG_CRYPTO_SELFTESTS) += chacha20poly1305-selftest.o ################################################################################ obj-$(CONFIG_CRYPTO_LIB_CURVE25519) += libcurve25519.o libcurve25519-y := curve25519.o
lib/crypto/chacha20poly1305.c +0 -14
@@ -354,22 +354,8 @@ bool chacha20poly1305_decrypt_sg_inplace(struct scatterlist *src, size_t src_len src_len -POLY1305_DIGEST_SIZE , ad, ad_len, nonce, key, 0); }EXPORT_SYMBOL (chacha20poly1305_decrypt_sg_inplace); -static int __init chacha20poly1305_init (void ) -{ -if (IS_ENABLED (CONFIG_CRYPTO_SELFTESTS ) && -WARN_ON (!chacha20poly1305_selftest ())) -return -ENODEV ; -return 0 ; -} - -static void __exit chacha20poly1305_exit(void) -{ -} - -module_init (chacha20poly1305_init); -module_exit (chacha20poly1305_exit);MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("ChaCha20Poly1305 AEAD construction" );MODULE_AUTHOR ("Jason A. Donenfeld <[email protected]>" );
lib/crypto/tests/Kconfig +10 -0
@@ -25,10 +25,19 @@ config CRYPTO_LIB_BLAKE2S_KUNIT_TEST # No need to depend on CRYPTO_LIB_BLAKE2S here, as that option doesn't # exist; the BLAKE2s code is always built-in for the /dev/random driver. help KUnit tests for the BLAKE2s cryptographic hash function. +config CRYPTO_LIB_CHACHA20POLY1305_KUNIT_TEST + tristate "KUnit tests for ChaCha20Poly1305" if !KUNIT_ALL_TESTS + depends on KUNIT && CRYPTO_LIB_CHACHA20POLY1305 + default KUNIT_ALL_TESTS + select CRYPTO_LIB_BENCHMARK_VISIBLE + help + KUnit tests for the ChaCha20Poly1305 authenticated encryption + algorithm. + config CRYPTO_LIB_CURVE25519_KUNIT_TEST tristate "KUnit tests for Curve25519" if !KUNIT_ALL_TESTS depends on KUNIT && CRYPTO_LIB_CURVE25519 default KUNIT_ALL_TESTS select CRYPTO_LIB_BENCHMARK_VISIBLE
@@ -135,10 +144,11 @@ config CRYPTO_LIB_SM3_KUNIT_TEST config CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT tristate "Enable all crypto library code for KUnit tests" depends on KUNIT select CRYPTO_LIB_AES_CBC_MACS select CRYPTO_LIB_BLAKE2B + select CRYPTO_LIB_CHACHA20POLY1305 select CRYPTO_LIB_CURVE25519 select CRYPTO_LIB_GF128HASH select CRYPTO_LIB_MD5 select CRYPTO_LIB_MLDSA select CRYPTO_LIB_NH
lib/crypto/tests/Makefile +1 -0
@@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0-or-later obj-$(CONFIG_CRYPTO_LIB_AES_CBC_MACS_KUNIT_TEST) += aes_cbc_macs_kunit.o obj-$(CONFIG_CRYPTO_LIB_BLAKE2B_KUNIT_TEST) += blake2b_kunit.o obj-$(CONFIG_CRYPTO_LIB_BLAKE2S_KUNIT_TEST) += blake2s_kunit.o +obj-$(CONFIG_CRYPTO_LIB_CHACHA20POLY1305_KUNIT_TEST) += chacha20poly1305_kunit.o obj-$(CONFIG_CRYPTO_LIB_CURVE25519_KUNIT_TEST) += curve25519_kunit.o obj-$(CONFIG_CRYPTO_LIB_GHASH_KUNIT_TEST) += ghash_kunit.o obj-$(CONFIG_CRYPTO_LIB_MD5_KUNIT_TEST) += md5_kunit.o obj-$(CONFIG_CRYPTO_LIB_MLDSA_KUNIT_TEST) += mldsa_kunit.o obj-$(CONFIG_CRYPTO_LIB_NH_KUNIT_TEST) += nh_kunit.o
lib/crypto/tests/chacha20poly1305_kunit.c renamed from lib/crypto/chacha20poly1305-selftest.c +748 -745
2,907 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
base-commit: 7ac21b4032e5b9b8a6a312b6f1d54f4ba24d1c16
Signature · 1 line
2.53.0
Part of the diff is not shown here. View the raw message.
Quoted 30 lines · Eric Biggers
Move the ChaCha20Poly1305 test from an ad-hoc self-test to a KUnit test.
Keep the same test logic for now, just translated to KUnit.
Moving to KUnit has multiple benefits, such as:
- Consistency with the rest of the
lib/crypto/tests.- Kernel developers familiar with KUnit, which is used kernel-wide, can quickly understand the test and how to enable and run it.
- The test will be automatically run by anyone using
lib/crypto/.kunitconfigor KUnit's all_tests.config.- Results are reported using the standard KUnit mechanism.
- It eliminates one of the few remaining back-references to
crypto/fromlib/crypto/, specifically a reference toCONFIG_CRYPTO_SELFTESTS.Signed-off-by Eric Biggers <[email protected]>--- include/crypto/chacha20poly1305.h | 2 - lib/crypto/.kunitconfig | 1 + lib/crypto/Makefile | 1 - lib/crypto/chacha20poly1305.c | 14 - lib/crypto/tests/Kconfig | 10 + lib/crypto/tests/Makefile | 1 + .../chacha20poly1305_kunit.c} | 1493 +++++++++-------- 7 files changed, 760 insertions(+), 762 deletions(-) rename lib/crypto/{chacha20poly1305-selftest.c =>
Quoted 2 lines
tests/chacha20poly1305_kunit.c} (91%)
Quoted 20 lines · Eric Biggers
Move the ChaCha20Poly1305 test from an ad-hoc self-test to a KUnit test.
Keep the same test logic for now, just translated to KUnit.
Moving to KUnit has multiple benefits, such as:
- Consistency with the rest of the
lib/crypto/tests.- Kernel developers familiar with KUnit, which is used kernel-wide, can quickly understand the test and how to enable and run it.
- The test will be automatically run by anyone using
lib/crypto/.kunitconfigor KUnit's all_tests.config.- Results are reported using the standard KUnit mechanism.
- It eliminates one of the few remaining back-references to
crypto/fromlib/crypto/, specifically a reference toCONFIG_CRYPTO_SELFTESTS.Signed-off-by Eric Biggers <[email protected]>
Quoted 10 lines
---
include/crypto/chacha20poly1305.h | 2 -
lib/crypto/.kunitconfig | 1 +
lib/crypto/Makefile | 1 -
lib/crypto/chacha20poly1305.c | 14 -
lib/crypto/tests/Kconfig | 10 +
lib/crypto/tests/Makefile | 1 +
.../chacha20poly1305_kunit.c} | 1493 +++++++++--------
7 files changed, 760 insertions(+), 762 deletions(-)
rename lib/crypto/{chacha20poly1305-selftest.c => tests/chacha20poly1305_kunit.c} (91%)Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next
- Eric