lib: Move SipHash into lib/crypto/
Subsystems (7)
Eric Biggers
maintainerPATCH 1/1 lib: Move SipHash into lib/crypto/
The addition of SipHash to lib/ predated the existence of the lib/crypto/ directory. Since it's a cryptographic algorithm, move it from the top-level lib/ directory to lib/crypto/.
Specifically:
- Move both siphash.c and siphash_kunit.c. Keep the header <linux/siphash.h> as-is for now.
- Keep the dedicated MAINTAINERS entry for SipHash. Just update the file paths it references.
- Move the kconfig option that controls the KUnit test. Put "CRYPTO_LIB" in its name and update the prompt to make it consistent with the other crypto library test options.
- Enable the KUnit test in lib/crypto/.kunitconfig.
- Link to siphash.rst from the appropriate place in libcrypto-hash.rst.
- Use obj-y instead of lib-y, for consistency with the fact that currently lib/crypto/ doesn't use kbuild's support for library file goals. We could keep it as lib-y, but virtually every kernel needs SipHash support anyway (with vsprintf, printk, IPv4, IPv6, etc. depending on it) so there is no practical difference in this case.
---
This patch is targeting libcrypto-next
Documentation/crypto/libcrypto-hash.rst | 5 +++++
MAINTAINERS | 4 ++--
lib/Kconfig.debug | 11 -----------
lib/Makefile | 2 +-
lib/crypto/.kunitconfig | 1 +
lib/crypto/Makefile | 2 ++
lib/{ => crypto}/siphash.c | 0
lib/crypto/tests/Kconfig | 11 +++++++++++
lib/crypto/tests/Makefile | 1 +
lib/{ => crypto}/tests/siphash_kunit.c | 0
lib/tests/Makefile | 1 -
tools/testing/selftests/bpf/progs/test_siphash.h | 2 +-
12 files changed, 24 insertions(+), 16 deletions(-)
rename lib/{ => crypto}/siphash.c (100%)
rename lib/{ => crypto}/tests/siphash_kunit.c (100%)Documentation/crypto/libcrypto-hash.rst +5 -0
@@ -80,6 +80,11 @@ SHA-3 The SHA-3 API is documented in :ref:`sha3`. +SipHash +------- + +The SipHash API is documented in Documentation/security/siphash.rst. + SM3 ---
MAINTAINERS +2 -2
@@ -25117,8 +25117,8 @@ SIPHASH PRF ROUTINES M: Jason A. Donenfeld <[email protected]> S: Maintained F: include/linux/siphash.h -F: lib/siphash.c -F: lib/tests/siphash_kunit.c +F: lib/crypto/siphash.c +F: lib/crypto/tests/siphash_kunit.c SIS 190 ETHERNET DRIVER M: Francois Romieu <[email protected]>
lib/Kconfig.debug +0 -11
@@ -3075,17 +3075,6 @@ config HW_BREAKPOINT_KUNIT_TEST source "lib/crypto/tests/Kconfig" -config SIPHASH_KUNIT_TEST - tristate "Perform selftest on siphash functions" if !KUNIT_ALL_TESTS - depends on KUNIT - default KUNIT_ALL_TESTS - help - Enable this option to test the kernel's siphash (<linux/siphash.h>) hash - functions on boot (or module load). - - This is intended to help people writing architecture-specific - optimized versions. If unsure, say N. - config USERCOPY_KUNIT_TEST tristate "KUnit Test for user/kernel boundary protections" depends on KUNIT
lib/Makefile +1 -1
@@ -38,7 +38,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ maple_tree.o idr.o extable.o irq_regs.o argv_split.o \ flex_proportions.o ratelimit.o \ is_single_threaded.o plist.o decompress.o kobject_uevent.o \ - earlycpio.o seq_buf.o siphash.o dec_and_lock.o \ + earlycpio.o seq_buf.o dec_and_lock.o \ nmi_backtrace.o win_minmax.o memcat_p.o \ buildid.o objpool.o iomem_copy.o sys_info.o
lib/crypto/.kunitconfig +1 -0
@@ -19,4 +19,5 @@ CONFIG_CRYPTO_LIB_SHA1_KUNIT_TEST=y CONFIG_CRYPTO_LIB_SHA256_KUNIT_TEST=y CONFIG_CRYPTO_LIB_SHA512_KUNIT_TEST=y CONFIG_CRYPTO_LIB_SHA3_KUNIT_TEST=y +CONFIG_CRYPTO_LIB_SIPHASH_KUNIT_TEST=y CONFIG_CRYPTO_LIB_SM3_KUNIT_TEST=y
lib/crypto/Makefile +2 -0
@@ -12,6 +12,8 @@ ppc64-perlasm-flavour-y := linux-ppc64 ppc64-perlasm-flavour-$(CONFIG_PPC64_ELF_ABI_V2) := linux-ppc64-elfv2 ppc64-perlasm-flavour-$(CONFIG_CPU_LITTLE_ENDIAN) := linux-ppc64le +obj-y += siphash.o + obj-$(CONFIG_KUNIT) += tests/ obj-$(CONFIG_CRYPTO_HASH_INFO) += hash_info.o
lib/crypto/siphash.c renamed from lib/siphash.c +0 -0
lib/crypto/tests/Kconfig +11 -0
@@ -151,6 +151,17 @@ config CRYPTO_LIB_SHA3_KUNIT_TEST including SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128 and SHAKE256. +config CRYPTO_LIB_SIPHASH_KUNIT_TEST + tristate "KUnit tests for SipHash" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Enable this option to test the kernel's siphash (<linux/siphash.h>) + hash functions on boot (or module load). + + This is intended to help people writing architecture-specific + optimized versions. If unsure, say N. + config CRYPTO_LIB_SM3_KUNIT_TEST tristate "KUnit tests for SM3" if !KUNIT_ALL_TESTS depends on KUNIT && CRYPTO_LIB_SM3
lib/crypto/tests/Makefile +1 -0
@@ -17,4 +17,5 @@ obj-$(CONFIG_CRYPTO_LIB_SHA1_KUNIT_TEST) += sha1_kunit.o obj-$(CONFIG_CRYPTO_LIB_SHA256_KUNIT_TEST) += sha224_kunit.o sha256_kunit.o obj-$(CONFIG_CRYPTO_LIB_SHA512_KUNIT_TEST) += sha384_kunit.o sha512_kunit.o obj-$(CONFIG_CRYPTO_LIB_SHA3_KUNIT_TEST) += sha3_kunit.o +obj-$(CONFIG_CRYPTO_LIB_SIPHASH_KUNIT_TEST) += siphash_kunit.o obj-$(CONFIG_CRYPTO_LIB_SM3_KUNIT_TEST) += sm3_kunit.o
lib/crypto/tests/siphash_kunit.c renamed from lib/tests/siphash_kunit.c +0 -0
lib/tests/Makefile +0 -1
@@ -46,7 +46,6 @@ obj-$(CONFIG_PRINTF_KUNIT_TEST) += printf_kunit.o obj-$(CONFIG_RANDSTRUCT_KUNIT_TEST) += randstruct_kunit.o obj-$(CONFIG_SCANF_KUNIT_TEST) += scanf_kunit.o obj-$(CONFIG_SEQ_BUF_KUNIT_TEST) += seq_buf_kunit.o -obj-$(CONFIG_SIPHASH_KUNIT_TEST) += siphash_kunit.o obj-$(CONFIG_SLUB_KUNIT_TEST) += slub_kunit.o obj-$(CONFIG_TEST_SORT) += test_sort.o CFLAGS_stackinit_kunit.o += $(call cc-disable-warning, switch-unreachable)
tools/testing/selftests/bpf/progs/test_siphash.h +1 -1
@@ -22,7 +22,7 @@ static inline u64 rol64(u64 word, unsigned int shift)#define SIPHASH_CONST_2 0x6c7967656e657261ULL#define SIPHASH_CONST_3 0x7465646279746573ULL -/* lib/siphash.c */ +/* lib/crypto/siphash.c */ #define SIPROUND SIPHASH_PERMUTATION(v0, v1, v2, v3)#define PREAMBLE (len) \
base-commit: 9ca77aa621027149c43551308112eba06b1de3af
Signature · 1 line
2.56.0
Quoted 11 lines · Eric Biggers
The addition of SipHash to
lib/predated the existence of thelib/crypto/directory. Since it's a cryptographic algorithm, move it from the top-levellib/directory tolib/crypto/.Specifically:
- Move both
siphash.candsiphash_kunit.c. Keep the header <linux/siphash.h> as-is for now.- Keep the dedicated
MAINTAINERSentry for SipHash. Just update the file paths it references.
Given that I'm also listed in the crypto section, I think we may as well delete the whole separate entry.
The only downside of this change is that those hsiphash functions are, erm, a bit less than cryptographic-strength. But maybe such concerns don't really matter any more at this stage, and we might as well group it all in lib/crypto/ where it all belonged originally anyway.
Jason
Quoted 16 lines · Jason A. Donenfeld
Quoted 11 lines · Eric Biggers
The addition of SipHash to
lib/predated the existence of thelib/crypto/directory. Since it's a cryptographic algorithm, move it from the top-levellib/directory tolib/crypto/.Specifically:
- Move both
siphash.candsiphash_kunit.c. Keep the header <linux/siphash.h> as-is for now.- Keep the dedicated
MAINTAINERSentry for SipHash. Just update the file paths it references.Given that I'm also listed in the crypto section, I think we may as well delete the whole separate entry.
Quoted 7 lines
The only downside of this change is that those hsiphash functions are, erm, a bit less than cryptographic-strength. But maybe such concerns don't really matter any more at this stage, and we might as well group it all in
lib/crypto/where it all belonged originally anyway.
Either works for me.
Eric Biggers
maintainerQuoted 23 lines · Ard Biesheuvel
Quoted 21 lines · Jason A. Donenfeld
Quoted 11 lines · Eric Biggers
The addition of SipHash to
lib/predated the existence of thelib/crypto/directory. Since it's a cryptographic algorithm, move it from the top-levellib/directory tolib/crypto/.Specifically:
- Move both
siphash.candsiphash_kunit.c. Keep the header <linux/siphash.h> as-is for now.- Keep the dedicated
MAINTAINERSentry for SipHash. Just update the file paths it references.Given that I'm also listed in the crypto section, I think we may as well delete the whole separate entry.
The only downside of this change is that those hsiphash functions are, erm, a bit less than cryptographic-strength. But maybe such concerns don't really matter any more at this stage, and we might as well group it all in
lib/crypto/where it all belonged originally anyway.
Quoted 6 lines
Quoted 2 lines
Either works for me.
Acked-by Ard Biesheuvel <[email protected]>
Makes sense. v2 removes the separate MAINTAINERS entry.
- Eric