Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'libcrypto-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux

Pull crypto library fixes from Eric Biggers:

- Several test fixes:

- Fix flakiness in the interrupt context tests in certain VMs

- Make the lib/crypto/ KUnit tests depend on the corresponding
library options rather than selecting them. This follows the
standard KUnit convention, and it fixes an issue where enabling
CONFIG_KUNIT_ALL_TESTS pulled in all the crypto library code

- Add a kunitconfig file for lib/crypto/

- Fix a couple stale references to "aes-generic" that made it in
concurrently with the rename to "aes-lib"

- Update the help text for several CRYPTO kconfig options to remove
outdated information about users that now use the library instead

* tag 'libcrypto-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux:
crypto: testmgr - Fix stale references to aes-generic
crypto: Clean up help text for CRYPTO_CRC32
crypto: Clean up help text for CRYPTO_CRC32C
crypto: Clean up help text for CRYPTO_XXHASH
crypto: Clean up help text for CRYPTO_SHA256
crypto: Clean up help text for CRYPTO_BLAKE2B
lib/crypto: tests: Add a .kunitconfig file
lib/crypto: tests: Depend on library options rather than selecting them
kunit: irq: Ensure timer doesn't fire too frequently

+76 -50
-9
crypto/Kconfig
··· 876 - blake2b-384 877 - blake2b-512 878 879 - Used by the btrfs filesystem. 880 - 881 See https://blake2.net for further information. 882 883 config CRYPTO_CMAC ··· 963 10118-3), including HMAC support. 964 965 This is required for IPsec AH (XFRM_AH) and IPsec ESP (XFRM_ESP). 966 - Used by the btrfs filesystem, Ceph, NFS, and SMB. 967 968 config CRYPTO_SHA512 969 tristate "SHA-384 and SHA-512" ··· 1036 1037 Extremely fast, working at speeds close to RAM limits. 1038 1039 - Used by the btrfs filesystem. 1040 - 1041 endmenu 1042 1043 menu "CRCs (cyclic redundancy checks)" ··· 1053 on Communications, Vol. 41, No. 6, June 1993, selected for use with 1054 iSCSI. 1055 1056 - Used by btrfs, ext4, jbd2, NVMeoF/TCP, and iSCSI. 1057 - 1058 config CRYPTO_CRC32 1059 tristate "CRC32" 1060 select CRYPTO_HASH 1061 select CRC32 1062 help 1063 CRC32 CRC algorithm (IEEE 802.3) 1064 - 1065 - Used by RoCEv2 and f2fs. 1066 1067 endmenu 1068
··· 876 - blake2b-384 877 - blake2b-512 878 879 See https://blake2.net for further information. 880 881 config CRYPTO_CMAC ··· 965 10118-3), including HMAC support. 966 967 This is required for IPsec AH (XFRM_AH) and IPsec ESP (XFRM_ESP). 968 969 config CRYPTO_SHA512 970 tristate "SHA-384 and SHA-512" ··· 1039 1040 Extremely fast, working at speeds close to RAM limits. 1041 1042 endmenu 1043 1044 menu "CRCs (cyclic redundancy checks)" ··· 1058 on Communications, Vol. 41, No. 6, June 1993, selected for use with 1059 iSCSI. 1060 1061 config CRYPTO_CRC32 1062 tristate "CRC32" 1063 select CRYPTO_HASH 1064 select CRC32 1065 help 1066 CRC32 CRC algorithm (IEEE 802.3) 1067 1068 endmenu 1069
+2 -2
crypto/testmgr.c
··· 4132 .fips_allowed = 1, 4133 }, { 4134 .alg = "authenc(hmac(sha224),cbc(aes))", 4135 - .generic_driver = "authenc(hmac-sha224-lib,cbc(aes-generic))", 4136 .test = alg_test_aead, 4137 .suite = { 4138 .aead = __VECS(hmac_sha224_aes_cbc_tv_temp) ··· 4194 .fips_allowed = 1, 4195 }, { 4196 .alg = "authenc(hmac(sha384),cbc(aes))", 4197 - .generic_driver = "authenc(hmac-sha384-lib,cbc(aes-generic))", 4198 .test = alg_test_aead, 4199 .suite = { 4200 .aead = __VECS(hmac_sha384_aes_cbc_tv_temp)
··· 4132 .fips_allowed = 1, 4133 }, { 4134 .alg = "authenc(hmac(sha224),cbc(aes))", 4135 + .generic_driver = "authenc(hmac-sha224-lib,cbc(aes-lib))", 4136 .test = alg_test_aead, 4137 .suite = { 4138 .aead = __VECS(hmac_sha224_aes_cbc_tv_temp) ··· 4194 .fips_allowed = 1, 4195 }, { 4196 .alg = "authenc(hmac(sha384),cbc(aes))", 4197 + .generic_driver = "authenc(hmac-sha384-lib,cbc(aes-lib))", 4198 .test = alg_test_aead, 4199 .suite = { 4200 .aead = __VECS(hmac_sha384_aes_cbc_tv_temp)
+28 -16
include/kunit/run-in-irq-context.h
··· 12 #include <linux/hrtimer.h> 13 #include <linux/workqueue.h> 14 15 - #define KUNIT_IRQ_TEST_HRTIMER_INTERVAL us_to_ktime(5) 16 - 17 struct kunit_irq_test_state { 18 bool (*func)(void *test_specific_state); 19 void *test_specific_state; 20 bool task_func_reported_failure; 21 bool hardirq_func_reported_failure; 22 bool softirq_func_reported_failure; 23 atomic_t hardirq_func_calls; 24 atomic_t softirq_func_calls; 25 struct hrtimer timer; 26 struct work_struct bh_work; 27 }; ··· 30 { 31 struct kunit_irq_test_state *state = 32 container_of(timer, typeof(*state), timer); 33 34 WARN_ON_ONCE(!in_hardirq()); 35 - atomic_inc(&state->hardirq_func_calls); 36 37 if (!state->func(state->test_specific_state)) 38 state->hardirq_func_reported_failure = true; 39 40 - hrtimer_forward_now(&state->timer, KUNIT_IRQ_TEST_HRTIMER_INTERVAL); 41 queue_work(system_bh_wq, &state->bh_work); 42 return HRTIMER_RESTART; 43 } ··· 97 struct kunit_irq_test_state state = { 98 .func = func, 99 .test_specific_state = test_specific_state, 100 }; 101 unsigned long end_jiffies; 102 - int hardirq_calls, softirq_calls; 103 - bool allctx = false; 104 105 /* 106 * Set up a hrtimer (the way we access hardirq context) and a work ··· 119 * and hardirq), or 1 second, whichever comes first. 120 */ 121 end_jiffies = jiffies + HZ; 122 - hrtimer_start(&state.timer, KUNIT_IRQ_TEST_HRTIMER_INTERVAL, 123 - HRTIMER_MODE_REL_HARD); 124 - for (int task_calls = 0, calls = 0; 125 - ((calls < max_iterations) || !allctx) && 126 - !time_after(jiffies, end_jiffies); 127 - task_calls++) { 128 if (!func(test_specific_state)) 129 state.task_func_reported_failure = true; 130 131 hardirq_calls = atomic_read(&state.hardirq_func_calls); 132 softirq_calls = atomic_read(&state.softirq_func_calls); 133 - calls = task_calls + hardirq_calls + softirq_calls; 134 - allctx = (task_calls > 0) && (hardirq_calls > 0) && 135 - (softirq_calls > 0); 136 - } 137 138 /* Cancel the timer and work. */ 139 hrtimer_cancel(&state.timer);
··· 12 #include <linux/hrtimer.h> 13 #include <linux/workqueue.h> 14 15 struct kunit_irq_test_state { 16 bool (*func)(void *test_specific_state); 17 void *test_specific_state; 18 bool task_func_reported_failure; 19 bool hardirq_func_reported_failure; 20 bool softirq_func_reported_failure; 21 + atomic_t task_func_calls; 22 atomic_t hardirq_func_calls; 23 atomic_t softirq_func_calls; 24 + ktime_t interval; 25 struct hrtimer timer; 26 struct work_struct bh_work; 27 }; ··· 30 { 31 struct kunit_irq_test_state *state = 32 container_of(timer, typeof(*state), timer); 33 + int task_calls, hardirq_calls, softirq_calls; 34 35 WARN_ON_ONCE(!in_hardirq()); 36 + task_calls = atomic_read(&state->task_func_calls); 37 + hardirq_calls = atomic_inc_return(&state->hardirq_func_calls); 38 + softirq_calls = atomic_read(&state->softirq_func_calls); 39 + 40 + /* 41 + * If the timer is firing too often for the softirq or task to ever have 42 + * a chance to run, increase the timer interval. This is needed on very 43 + * slow systems. 44 + */ 45 + if (hardirq_calls >= 20 && (softirq_calls == 0 || task_calls == 0)) 46 + state->interval = ktime_add_ns(state->interval, 250); 47 48 if (!state->func(state->test_specific_state)) 49 state->hardirq_func_reported_failure = true; 50 51 + hrtimer_forward_now(&state->timer, state->interval); 52 queue_work(system_bh_wq, &state->bh_work); 53 return HRTIMER_RESTART; 54 } ··· 86 struct kunit_irq_test_state state = { 87 .func = func, 88 .test_specific_state = test_specific_state, 89 + /* 90 + * Start with a 5us timer interval. If the system can't keep 91 + * up, kunit_irq_test_timer_func() will increase it. 92 + */ 93 + .interval = us_to_ktime(5), 94 }; 95 unsigned long end_jiffies; 96 + int task_calls, hardirq_calls, softirq_calls; 97 98 /* 99 * Set up a hrtimer (the way we access hardirq context) and a work ··· 104 * and hardirq), or 1 second, whichever comes first. 105 */ 106 end_jiffies = jiffies + HZ; 107 + hrtimer_start(&state.timer, state.interval, HRTIMER_MODE_REL_HARD); 108 + do { 109 if (!func(test_specific_state)) 110 state.task_func_reported_failure = true; 111 112 + task_calls = atomic_inc_return(&state.task_func_calls); 113 hardirq_calls = atomic_read(&state.hardirq_func_calls); 114 softirq_calls = atomic_read(&state.softirq_func_calls); 115 + } while ((task_calls + hardirq_calls + softirq_calls < max_iterations || 116 + (task_calls == 0 || hardirq_calls == 0 || 117 + softirq_calls == 0)) && 118 + !time_after(jiffies, end_jiffies)); 119 120 /* Cancel the timer and work. */ 121 hrtimer_cancel(&state.timer);
+34
lib/crypto/.kunitconfig
···
··· 1 + CONFIG_KUNIT=y 2 + 3 + # These kconfig options select all the CONFIG_CRYPTO_LIB_* symbols that have a 4 + # corresponding KUnit test. Those symbols cannot be directly enabled here, 5 + # since they are hidden symbols. 6 + CONFIG_CRYPTO=y 7 + CONFIG_CRYPTO_ADIANTUM=y 8 + CONFIG_CRYPTO_BLAKE2B=y 9 + CONFIG_CRYPTO_CHACHA20POLY1305=y 10 + CONFIG_CRYPTO_HCTR2=y 11 + CONFIG_CRYPTO_MD5=y 12 + CONFIG_CRYPTO_MLDSA=y 13 + CONFIG_CRYPTO_SHA1=y 14 + CONFIG_CRYPTO_SHA256=y 15 + CONFIG_CRYPTO_SHA512=y 16 + CONFIG_CRYPTO_SHA3=y 17 + CONFIG_INET=y 18 + CONFIG_IPV6=y 19 + CONFIG_NET=y 20 + CONFIG_NETDEVICES=y 21 + CONFIG_WIREGUARD=y 22 + 23 + CONFIG_CRYPTO_LIB_BLAKE2B_KUNIT_TEST=y 24 + CONFIG_CRYPTO_LIB_BLAKE2S_KUNIT_TEST=y 25 + CONFIG_CRYPTO_LIB_CURVE25519_KUNIT_TEST=y 26 + CONFIG_CRYPTO_LIB_MD5_KUNIT_TEST=y 27 + CONFIG_CRYPTO_LIB_MLDSA_KUNIT_TEST=y 28 + CONFIG_CRYPTO_LIB_NH_KUNIT_TEST=y 29 + CONFIG_CRYPTO_LIB_POLY1305_KUNIT_TEST=y 30 + CONFIG_CRYPTO_LIB_POLYVAL_KUNIT_TEST=y 31 + CONFIG_CRYPTO_LIB_SHA1_KUNIT_TEST=y 32 + CONFIG_CRYPTO_LIB_SHA256_KUNIT_TEST=y 33 + CONFIG_CRYPTO_LIB_SHA512_KUNIT_TEST=y 34 + CONFIG_CRYPTO_LIB_SHA3_KUNIT_TEST=y
+12 -23
lib/crypto/tests/Kconfig
··· 2 3 config CRYPTO_LIB_BLAKE2B_KUNIT_TEST 4 tristate "KUnit tests for BLAKE2b" if !KUNIT_ALL_TESTS 5 - depends on KUNIT 6 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 7 select CRYPTO_LIB_BENCHMARK_VISIBLE 8 - select CRYPTO_LIB_BLAKE2B 9 help 10 KUnit tests for the BLAKE2b cryptographic hash function. 11 ··· 13 depends on KUNIT 14 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 15 select CRYPTO_LIB_BENCHMARK_VISIBLE 16 - # No need to select CRYPTO_LIB_BLAKE2S here, as that option doesn't 17 # exist; the BLAKE2s code is always built-in for the /dev/random driver. 18 help 19 KUnit tests for the BLAKE2s cryptographic hash function. 20 21 config CRYPTO_LIB_CURVE25519_KUNIT_TEST 22 tristate "KUnit tests for Curve25519" if !KUNIT_ALL_TESTS 23 - depends on KUNIT 24 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 25 select CRYPTO_LIB_BENCHMARK_VISIBLE 26 - select CRYPTO_LIB_CURVE25519 27 help 28 KUnit tests for the Curve25519 Diffie-Hellman function. 29 30 config CRYPTO_LIB_MD5_KUNIT_TEST 31 tristate "KUnit tests for MD5" if !KUNIT_ALL_TESTS 32 - depends on KUNIT 33 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 34 select CRYPTO_LIB_BENCHMARK_VISIBLE 35 - select CRYPTO_LIB_MD5 36 help 37 KUnit tests for the MD5 cryptographic hash function and its 38 corresponding HMAC. 39 40 config CRYPTO_LIB_MLDSA_KUNIT_TEST 41 tristate "KUnit tests for ML-DSA" if !KUNIT_ALL_TESTS 42 - depends on KUNIT 43 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 44 select CRYPTO_LIB_BENCHMARK_VISIBLE 45 - select CRYPTO_LIB_MLDSA 46 help 47 KUnit tests for the ML-DSA digital signature algorithm. 48 49 config CRYPTO_LIB_NH_KUNIT_TEST 50 tristate "KUnit tests for NH" if !KUNIT_ALL_TESTS 51 - depends on KUNIT 52 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 53 - select CRYPTO_LIB_NH 54 help 55 KUnit tests for the NH almost-universal hash function. 56 57 config CRYPTO_LIB_POLY1305_KUNIT_TEST 58 tristate "KUnit tests for Poly1305" if !KUNIT_ALL_TESTS 59 - depends on KUNIT 60 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 61 select CRYPTO_LIB_BENCHMARK_VISIBLE 62 - select CRYPTO_LIB_POLY1305 63 help 64 KUnit tests for the Poly1305 library functions. 65 66 config CRYPTO_LIB_POLYVAL_KUNIT_TEST 67 tristate "KUnit tests for POLYVAL" if !KUNIT_ALL_TESTS 68 - depends on KUNIT 69 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 70 select CRYPTO_LIB_BENCHMARK_VISIBLE 71 - select CRYPTO_LIB_POLYVAL 72 help 73 KUnit tests for the POLYVAL library functions. 74 75 config CRYPTO_LIB_SHA1_KUNIT_TEST 76 tristate "KUnit tests for SHA-1" if !KUNIT_ALL_TESTS 77 - depends on KUNIT 78 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 79 select CRYPTO_LIB_BENCHMARK_VISIBLE 80 - select CRYPTO_LIB_SHA1 81 help 82 KUnit tests for the SHA-1 cryptographic hash function and its 83 corresponding HMAC. ··· 79 # included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA256). 80 config CRYPTO_LIB_SHA256_KUNIT_TEST 81 tristate "KUnit tests for SHA-224 and SHA-256" if !KUNIT_ALL_TESTS 82 - depends on KUNIT 83 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 84 select CRYPTO_LIB_BENCHMARK_VISIBLE 85 - select CRYPTO_LIB_SHA256 86 help 87 KUnit tests for the SHA-224 and SHA-256 cryptographic hash functions 88 and their corresponding HMACs. ··· 90 # included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA512). 91 config CRYPTO_LIB_SHA512_KUNIT_TEST 92 tristate "KUnit tests for SHA-384 and SHA-512" if !KUNIT_ALL_TESTS 93 - depends on KUNIT 94 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 95 select CRYPTO_LIB_BENCHMARK_VISIBLE 96 - select CRYPTO_LIB_SHA512 97 help 98 KUnit tests for the SHA-384 and SHA-512 cryptographic hash functions 99 and their corresponding HMACs. 100 101 config CRYPTO_LIB_SHA3_KUNIT_TEST 102 tristate "KUnit tests for SHA-3" if !KUNIT_ALL_TESTS 103 - depends on KUNIT 104 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 105 select CRYPTO_LIB_BENCHMARK_VISIBLE 106 - select CRYPTO_LIB_SHA3 107 help 108 KUnit tests for the SHA3 cryptographic hash and XOF functions, 109 including SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128 and
··· 2 3 config CRYPTO_LIB_BLAKE2B_KUNIT_TEST 4 tristate "KUnit tests for BLAKE2b" if !KUNIT_ALL_TESTS 5 + depends on KUNIT && CRYPTO_LIB_BLAKE2B 6 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 7 select CRYPTO_LIB_BENCHMARK_VISIBLE 8 help 9 KUnit tests for the BLAKE2b cryptographic hash function. 10 ··· 14 depends on KUNIT 15 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 16 select CRYPTO_LIB_BENCHMARK_VISIBLE 17 + # No need to depend on CRYPTO_LIB_BLAKE2S here, as that option doesn't 18 # exist; the BLAKE2s code is always built-in for the /dev/random driver. 19 help 20 KUnit tests for the BLAKE2s cryptographic hash function. 21 22 config CRYPTO_LIB_CURVE25519_KUNIT_TEST 23 tristate "KUnit tests for Curve25519" if !KUNIT_ALL_TESTS 24 + depends on KUNIT && CRYPTO_LIB_CURVE25519 25 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 26 select CRYPTO_LIB_BENCHMARK_VISIBLE 27 help 28 KUnit tests for the Curve25519 Diffie-Hellman function. 29 30 config CRYPTO_LIB_MD5_KUNIT_TEST 31 tristate "KUnit tests for MD5" if !KUNIT_ALL_TESTS 32 + depends on KUNIT && CRYPTO_LIB_MD5 33 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 34 select CRYPTO_LIB_BENCHMARK_VISIBLE 35 help 36 KUnit tests for the MD5 cryptographic hash function and its 37 corresponding HMAC. 38 39 config CRYPTO_LIB_MLDSA_KUNIT_TEST 40 tristate "KUnit tests for ML-DSA" if !KUNIT_ALL_TESTS 41 + depends on KUNIT && CRYPTO_LIB_MLDSA 42 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 43 select CRYPTO_LIB_BENCHMARK_VISIBLE 44 help 45 KUnit tests for the ML-DSA digital signature algorithm. 46 47 config CRYPTO_LIB_NH_KUNIT_TEST 48 tristate "KUnit tests for NH" if !KUNIT_ALL_TESTS 49 + depends on KUNIT && CRYPTO_LIB_NH 50 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 51 help 52 KUnit tests for the NH almost-universal hash function. 53 54 config CRYPTO_LIB_POLY1305_KUNIT_TEST 55 tristate "KUnit tests for Poly1305" if !KUNIT_ALL_TESTS 56 + depends on KUNIT && CRYPTO_LIB_POLY1305 57 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 58 select CRYPTO_LIB_BENCHMARK_VISIBLE 59 help 60 KUnit tests for the Poly1305 library functions. 61 62 config CRYPTO_LIB_POLYVAL_KUNIT_TEST 63 tristate "KUnit tests for POLYVAL" if !KUNIT_ALL_TESTS 64 + depends on KUNIT && CRYPTO_LIB_POLYVAL 65 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 66 select CRYPTO_LIB_BENCHMARK_VISIBLE 67 help 68 KUnit tests for the POLYVAL library functions. 69 70 config CRYPTO_LIB_SHA1_KUNIT_TEST 71 tristate "KUnit tests for SHA-1" if !KUNIT_ALL_TESTS 72 + depends on KUNIT && CRYPTO_LIB_SHA1 73 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 74 select CRYPTO_LIB_BENCHMARK_VISIBLE 75 help 76 KUnit tests for the SHA-1 cryptographic hash function and its 77 corresponding HMAC. ··· 87 # included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA256). 88 config CRYPTO_LIB_SHA256_KUNIT_TEST 89 tristate "KUnit tests for SHA-224 and SHA-256" if !KUNIT_ALL_TESTS 90 + depends on KUNIT && CRYPTO_LIB_SHA256 91 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 92 select CRYPTO_LIB_BENCHMARK_VISIBLE 93 help 94 KUnit tests for the SHA-224 and SHA-256 cryptographic hash functions 95 and their corresponding HMACs. ··· 99 # included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA512). 100 config CRYPTO_LIB_SHA512_KUNIT_TEST 101 tristate "KUnit tests for SHA-384 and SHA-512" if !KUNIT_ALL_TESTS 102 + depends on KUNIT && CRYPTO_LIB_SHA512 103 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 104 select CRYPTO_LIB_BENCHMARK_VISIBLE 105 help 106 KUnit tests for the SHA-384 and SHA-512 cryptographic hash functions 107 and their corresponding HMACs. 108 109 config CRYPTO_LIB_SHA3_KUNIT_TEST 110 tristate "KUnit tests for SHA-3" if !KUNIT_ALL_TESTS 111 + depends on KUNIT && CRYPTO_LIB_SHA3 112 default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 113 select CRYPTO_LIB_BENCHMARK_VISIBLE 114 help 115 KUnit tests for the SHA3 cryptographic hash and XOF functions, 116 including SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128 and