All of lore.kernel.org
 help / color / mirror / Atom feed
* [MPTCP] [RFC PATCH 15/16] mptcp: More efficient byte order handling
@ 2018-03-28 23:18 Mat Martineau
  0 siblings, 0 replies; only message in thread
From: Mat Martineau @ 2018-03-28 23:18 UTC (permalink / raw)
  To: mptcp

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

crypto_key_sha1() was reordering bytes in words that were discarded, and
the initial data sequence number (IDSN) was returned in a way that
required additional byte swapping. Now only the token is returned with
its bytes swapped, and the IDSN is returned in host order so it is ready
for comparison and addition.

Signed-off-by: Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 net/mptcp/crypto.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/net/mptcp/crypto.c b/net/mptcp/crypto.c
index 0ba35449c4a0..8f575974dfce 100644
--- a/net/mptcp/crypto.c
+++ b/net/mptcp/crypto.c
@@ -106,7 +106,6 @@ void crypto_key_sha1(u64 key, u32 *token, u64 *idsn)
 	u32 workspace[SHA_WORKSPACE_WORDS];
 	u32 mptcp_hashed_key[SHA_DIGEST_WORDS];
 	u8 input[64];
-	int i;
 
 	memset(workspace, 0, sizeof(workspace));
 
@@ -121,13 +120,10 @@ void crypto_key_sha1(u64 key, u32 *token, u64 *idsn)
 	sha_init(mptcp_hashed_key);
 	sha_transform(mptcp_hashed_key, input, workspace);
 
-	for (i = 0; i < 5; i++)
-		mptcp_hashed_key[i] = cpu_to_be32(mptcp_hashed_key[i]);
-
 	if (token)
-		*token = mptcp_hashed_key[0];
+		*token = htonl(mptcp_hashed_key[0]);
 	if (idsn)
-		*idsn = *((u64 *)&mptcp_hashed_key[3]);
+		*idsn = ((u64)mptcp_hashed_key[3] << 32) + mptcp_hashed_key[4];
 }
 
 void crypto_hmac_sha1(const u8 *key_1, const u8 *key_2, u32 *hash_out,
-- 
2.16.3


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

only message in thread, other threads:[~2018-03-28 23:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-28 23:18 [MPTCP] [RFC PATCH 15/16] mptcp: More efficient byte order handling Mat Martineau

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.