All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mat Martineau <mathew.j.martineau at linux.intel.com>
To: mptcp at lists.01.org
Subject: [MPTCP] [RFC PATCH 15/16] mptcp: More efficient byte order handling
Date: Wed, 28 Mar 2018 16:18:39 -0700	[thread overview]
Message-ID: <20180328231840.12410-16-mathew.j.martineau@linux.intel.com> (raw)
In-Reply-To: 20180328231840.12410-1-mathew.j.martineau@linux.intel.com

[-- 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


                 reply	other threads:[~2018-03-28 23:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180328231840.12410-16-mathew.j.martineau@linux.intel.com \
    --to=unknown@example.com \
    /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 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.