All of lore.kernel.org
 help / color / mirror / Atom feed
* [MPTCP] [PATCH v5 4/5] mptcp: v1 ADD_ADDR changes: add subflow_generate_hmac()
@ 2020-03-16 18:39 Peter Krystad
  0 siblings, 0 replies; only message in thread
From: Peter Krystad @ 2020-03-16 18:39 UTC (permalink / raw)
  To: mptcp 

[-- Attachment #1: Type: text/plain, Size: 2348 bytes --]

Add subflow_generate_hmac() to generate hmac from nonces.

squash-to: Add handling of incoming MP_JOIN requests

Signed-off-by: Peter Krystad <peter.krystad(a)linux.intel.com>
---
 include/linux/tcp.h |  2 +-
 net/mptcp/subflow.c | 19 +++++++++++++++----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 4cf39e002a19..67f314907c60 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -94,11 +94,11 @@ struct mptcp_options_received {
 		family : 4,
 		echo : 1,
 		backup : 1;
-	u8	join_id;
 	u32	token;
 	u32	nonce;
 	u64	thmac;
 	u8	hmac[20];
+	u8	join_id;
 	u8	use_map:1,
 		dsn64:1,
 		data_fin:1,
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 574391d014ac..82060fb2433a 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -48,6 +48,17 @@ static void subflow_req_destructor(struct request_sock *req)
 	tcp_request_sock_ops.destructor(req);
 }
 
+static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
+				  void *hmac)
+{
+	u8 msg[8];
+
+	put_unaligned_be32(nonce1, &msg[0]);
+	put_unaligned_be32(nonce2, &msg[4]);
+
+	mptcp_crypto_hmac_sha(key1, key2, msg, 8, hmac);
+}
+
 /* validate received token and create truncated hmac and nonce for SYN-ACK */
 static bool subflow_token_join_request(struct request_sock *req,
 				       const struct sk_buff *skb)
@@ -73,9 +84,9 @@ static bool subflow_token_join_request(struct request_sock *req,
 
 	get_random_bytes(&subflow_req->local_nonce, sizeof(u32));
 
-	mptcp_crypto_hmac_sha(msk->local_key, msk->remote_key,
+	subflow_generate_hmac(msk->local_key, msk->remote_key,
 			      subflow_req->local_nonce,
-			      subflow_req->remote_nonce, (u32 *)hmac);
+			      subflow_req->remote_nonce, hmac);
 
 	subflow_req->thmac = get_unaligned_be64(hmac);
 
@@ -238,9 +249,9 @@ static bool subflow_hmac_valid(const struct request_sock *req,
 	if (!msk)
 		return false;
 
-	mptcp_crypto_hmac_sha(msk->remote_key, msk->local_key,
+	subflow_generate_hmac(msk->remote_key, msk->local_key,
 			      subflow_req->remote_nonce,
-			      subflow_req->local_nonce, (u32 *)hmac);
+			      subflow_req->local_nonce, hmac);
 
 	ret = true;
 	if (crypto_memneq(hmac, rx_opt->mptcp.hmac, sizeof(hmac)))
-- 
2.17.2

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-03-16 18:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-16 18:39 [MPTCP] [PATCH v5 4/5] mptcp: v1 ADD_ADDR changes: add subflow_generate_hmac() Peter Krystad

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.