From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
To: mptcp@lists.linux.dev, Mat Martineau <martineau@kernel.org>,
Geliang Tang <geliang@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org,
"Matthieu Baerts (NGI0)" <matttbe@kernel.org>,
Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH net-next 1/6] mptcp: use HMAC-SHA256 library instead of open-coded HMAC
Date: Mon, 01 Sep 2025 11:39:10 +0200 [thread overview]
Message-ID: <20250901-net-next-mptcp-misc-feat-6-18-v1-1-80ae80d2b903@kernel.org> (raw)
In-Reply-To: <20250901-net-next-mptcp-misc-feat-6-18-v1-0-80ae80d2b903@kernel.org>
From: Eric Biggers <ebiggers@kernel.org>
Now that there are easy-to-use HMAC-SHA256 library functions, use these
in net/mptcp/crypto.c instead of open-coding the HMAC algorithm.
Remove the WARN_ON_ONCE() for messages longer than SHA256_DIGEST_SIZE.
The new implementation handles all message lengths correctly.
The mptcp-crypto KUnit test still passes after this change.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/crypto.c | 35 ++---------------------------------
1 file changed, 2 insertions(+), 33 deletions(-)
diff --git a/net/mptcp/crypto.c b/net/mptcp/crypto.c
index b08ba959ac4fd485bb833043ff58d4c8bac8a37a..31948e18d97da7ee0ee2ae9e4f7c9ca0e3b330a7 100644
--- a/net/mptcp/crypto.c
+++ b/net/mptcp/crypto.c
@@ -22,7 +22,6 @@
#include <linux/kernel.h>
#include <crypto/sha2.h>
-#include <linux/unaligned.h>
#include "protocol.h"
@@ -43,39 +42,9 @@ void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn)
void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac)
{
- u8 input[SHA256_BLOCK_SIZE + SHA256_DIGEST_SIZE];
- u8 key1be[8];
- u8 key2be[8];
- int i;
+ __be64 key[2] = { cpu_to_be64(key1), cpu_to_be64(key2) };
- if (WARN_ON_ONCE(len > SHA256_DIGEST_SIZE))
- len = SHA256_DIGEST_SIZE;
-
- put_unaligned_be64(key1, key1be);
- put_unaligned_be64(key2, key2be);
-
- /* Generate key xored with ipad */
- memset(input, 0x36, SHA256_BLOCK_SIZE);
- for (i = 0; i < 8; i++)
- input[i] ^= key1be[i];
- for (i = 0; i < 8; i++)
- input[i + 8] ^= key2be[i];
-
- memcpy(&input[SHA256_BLOCK_SIZE], msg, len);
-
- /* emit sha256(K1 || msg) on the second input block, so we can
- * reuse 'input' for the last hashing
- */
- sha256(input, SHA256_BLOCK_SIZE + len, &input[SHA256_BLOCK_SIZE]);
-
- /* Prepare second part of hmac */
- memset(input, 0x5C, SHA256_BLOCK_SIZE);
- for (i = 0; i < 8; i++)
- input[i] ^= key1be[i];
- for (i = 0; i < 8; i++)
- input[i + 8] ^= key2be[i];
-
- sha256(input, SHA256_BLOCK_SIZE + SHA256_DIGEST_SIZE, hmac);
+ hmac_sha256_usingrawkey((const u8 *)key, sizeof(key), msg, len, hmac);
}
#if IS_MODULE(CONFIG_MPTCP_KUNIT_TEST)
--
2.50.1
next prev parent reply other threads:[~2025-09-01 9:40 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-01 9:39 [PATCH net-next 0/6] mptcp: misc. features for v6.18 Matthieu Baerts (NGI0)
2025-09-01 9:39 ` Matthieu Baerts (NGI0) [this message]
2025-09-01 9:39 ` [PATCH net-next 2/6] mptcp: make ADD_ADDR retransmission timeout adaptive Matthieu Baerts (NGI0)
2025-09-01 9:39 ` [PATCH net-next 3/6] selftests: mptcp: remove add_addr_timeout settings Matthieu Baerts (NGI0)
2025-09-01 9:39 ` [PATCH net-next 4/6] selftests: mptcp: add checks for fallback counters Matthieu Baerts (NGI0)
2025-09-01 9:39 ` [PATCH net-next 5/6] net: Add rfs_needed() helper Matthieu Baerts (NGI0)
2025-09-01 9:39 ` [PATCH net-next 6/6] mptcp: record subflows in RPS table Matthieu Baerts (NGI0)
2025-09-02 14:26 ` [PATCH net-next 0/6] mptcp: misc. features for v6.18 Jakub Kicinski
2025-09-02 14:51 ` Matthieu Baerts
2025-09-02 15:27 ` Jakub Kicinski
2025-09-02 18:25 ` Catalin Marinas
2025-09-02 18:50 ` Matthieu Baerts
2025-09-02 21:18 ` Catalin Marinas
2025-09-02 21:38 ` Matthieu Baerts
2025-09-02 22:21 ` Christoph Paasch
2025-09-02 14:29 ` Matthieu Baerts
2025-09-02 19:09 ` Jakub Kicinski
2025-09-02 19:25 ` Matthieu Baerts
2025-09-02 20:53 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250901-net-next-mptcp-misc-feat-6-18-v1-1-80ae80d2b903@kernel.org \
--to=matttbe@kernel.org \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=ebiggers@kernel.org \
--cc=edumazet@google.com \
--cc=geliang@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martineau@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).