Commit 37a183d
tcp: Convert tcp-md5 to use MD5 library instead of crypto_ahash
Make tcp-md5 use the MD5 library API (added in 6.18) instead of the
crypto_ahash API. This is much simpler and also more efficient:
- The library API just operates on struct md5_ctx. Just allocate this
struct on the stack instead of using a pool of pre-allocated
crypto_ahash and ahash_request objects.
- The library API accepts standard pointers and doesn't require
scatterlists. So, for hashing the headers just use an on-stack buffer
instead of a pool of pre-allocated kmalloc'ed scratch buffers.
- The library API never fails. Therefore, checking for MD5 hashing
errors is no longer necessary. Update tcp_v4_md5_hash_skb(),
tcp_v6_md5_hash_skb(), tcp_v4_md5_hash_hdr(), tcp_v6_md5_hash_hdr(),
tcp_md5_hash_key(), tcp_sock_af_ops::calc_md5_hash, and
tcp_request_sock_ops::calc_md5_hash to return void instead of int.
- The library API provides direct access to the MD5 code, eliminating
unnecessary overhead such as indirect function calls and scatterlist
management. Microbenchmarks of tcp_v4_md5_hash_skb() on x86_64 show a
speedup from 7518 to 7041 cycles (6% fewer) with skb->len == 1440, or
from 1020 to 678 cycles (33% fewer) with skb->len == 140.
Since tcp_sigpool_hash_skb_data() can no longer be used, add a function
tcp_md5_hash_skb_data() which is specialized to MD5. Of course, to the
extent that this duplicates any code, it's well worth it.
To preserve the existing behavior of TCP-MD5 support being disabled when
the kernel is booted with "fips=1", make tcp_md5_do_add() check
fips_enabled itself. Previously it relied on the error from
crypto_alloc_ahash("md5") being bubbled up. I don't know for sure that
this is actually needed, but this preserves the existing behavior.
Tested with bidirectional TCP-MD5, both IPv4 and IPv6, between a kernel
that includes this commit and a kernel that doesn't include this commit.
(Side note: please don't use TCP-MD5! It's cryptographically weak. But
as long as Linux supports it, it might as well be implemented properly.)
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Link: https://patch.msgid.link/20251014215836.115616-1-ebiggers@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>1 parent f578ff4 commit 37a183d
File tree
6 files changed
+121
-240
lines changed- include/net
- net
- ipv4
- ipv6
6 files changed
+121
-240
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1898 | 1898 | | |
1899 | 1899 | | |
1900 | 1900 | | |
1901 | | - | |
1902 | | - | |
1903 | | - | |
1904 | | - | |
1905 | | - | |
1906 | | - | |
1907 | | - | |
1908 | 1901 | | |
1909 | 1902 | | |
1910 | 1903 | | |
| |||
1939 | 1932 | | |
1940 | 1933 | | |
1941 | 1934 | | |
1942 | | - | |
1943 | | - | |
| 1935 | + | |
| 1936 | + | |
1944 | 1937 | | |
1945 | 1938 | | |
1946 | 1939 | | |
| |||
1999 | 1992 | | |
2000 | 1993 | | |
2001 | 1994 | | |
2002 | | - | |
2003 | | - | |
2004 | | - | |
2005 | | - | |
2006 | | - | |
2007 | | - | |
2008 | | - | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
2009 | 1999 | | |
2010 | 2000 | | |
2011 | 2001 | | |
| |||
2355 | 2345 | | |
2356 | 2346 | | |
2357 | 2347 | | |
2358 | | - | |
| 2348 | + | |
2359 | 2349 | | |
2360 | 2350 | | |
2361 | 2351 | | |
| |||
2383 | 2373 | | |
2384 | 2374 | | |
2385 | 2375 | | |
2386 | | - | |
| 2376 | + | |
2387 | 2377 | | |
2388 | 2378 | | |
2389 | 2379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
760 | 760 | | |
761 | 761 | | |
762 | 762 | | |
763 | | - | |
764 | | - | |
765 | | - | |
| 763 | + | |
766 | 764 | | |
767 | 765 | | |
768 | 766 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
| 246 | + | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
257 | 256 | | |
258 | 257 | | |
259 | 258 | | |
| |||
425 | 424 | | |
426 | 425 | | |
427 | 426 | | |
428 | | - | |
429 | 427 | | |
430 | 428 | | |
431 | 429 | | |
| |||
4838 | 4836 | | |
4839 | 4837 | | |
4840 | 4838 | | |
4841 | | - | |
4842 | | - | |
4843 | | - | |
4844 | | - | |
| 4839 | + | |
| 4840 | + | |
4845 | 4841 | | |
4846 | | - | |
4847 | | - | |
| 4842 | + | |
| 4843 | + | |
| 4844 | + | |
| 4845 | + | |
| 4846 | + | |
4848 | 4847 | | |
4849 | | - | |
4850 | | - | |
4851 | | - | |
4852 | | - | |
4853 | | - | |
4854 | | - | |
4855 | | - | |
4856 | | - | |
4857 | | - | |
4858 | | - | |
4859 | | - | |
4860 | | - | |
4861 | | - | |
4862 | | - | |
| 4848 | + | |
4863 | 4849 | | |
4864 | | - | |
4865 | | - | |
4866 | | - | |
4867 | | - | |
| 4850 | + | |
| 4851 | + | |
| 4852 | + | |
| 4853 | + | |
| 4854 | + | |
4868 | 4855 | | |
4869 | | - | |
4870 | | - | |
4871 | | - | |
| 4856 | + | |
| 4857 | + | |
| 4858 | + | |
| 4859 | + | |
| 4860 | + | |
| 4861 | + | |
| 4862 | + | |
| 4863 | + | |
| 4864 | + | |
| 4865 | + | |
4872 | 4866 | | |
| 4867 | + | |
4873 | 4868 | | |
4874 | | - | |
4875 | | - | |
| 4869 | + | |
| 4870 | + | |
4876 | 4871 | | |
4877 | 4872 | | |
4878 | | - | |
4879 | | - | |
4880 | | - | |
4881 | | - | |
4882 | 4873 | | |
4883 | 4874 | | |
4884 | 4875 | | |
4885 | 4876 | | |
4886 | | - | |
| 4877 | + | |
4887 | 4878 | | |
4888 | 4879 | | |
4889 | 4880 | | |
| |||
4902 | 4893 | | |
4903 | 4894 | | |
4904 | 4895 | | |
4905 | | - | |
4906 | 4896 | | |
4907 | 4897 | | |
4908 | 4898 | | |
| |||
4917 | 4907 | | |
4918 | 4908 | | |
4919 | 4909 | | |
4920 | | - | |
| 4910 | + | |
4921 | 4911 | | |
4922 | | - | |
4923 | | - | |
4924 | | - | |
| 4912 | + | |
| 4913 | + | |
4925 | 4914 | | |
4926 | 4915 | | |
4927 | 4916 | | |
| |||
0 commit comments