From: Harvey Harrison <harvey.harrison@gmail.com>
To: Jiri Benc <jbenc@suse.cz>
Cc: linux-wireless <linux-wireless@vger.kernel.org>
Subject: [PATCH 3/5] mac80211: replace Mk16 helper with le16_to_cpup
Date: Sat, 08 Mar 2008 01:23:07 -0800 [thread overview]
Message-ID: <1204968187.23455.39.camel@brick> (raw)
Opencoded byte-swapping could just use the kernel helper.
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
net/mac80211/tkip.c | 47 ++++++++++++++++++++++-------------------------
1 files changed, 22 insertions(+), 25 deletions(-)
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c
index 90c11e7..9a36e83 100644
--- a/net/mac80211/tkip.c
+++ b/net/mac80211/tkip.c
@@ -60,13 +60,6 @@ static const u16 tkip_sbox[256] =
0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A,
};
-
-static inline u16 Mk16(u8 x, u8 y)
-{
- return ((u16) x << 8) | (u16) y;
-}
-
-
static inline u8 Hi8(u16 v)
{
return v >> 8;
@@ -107,20 +100,22 @@ static void tkip_mixing_phase1(const u8 *ta, const u8 *tk, u32 tsc_IV32,
u16 *p1k)
{
int i, j;
+ __le16 *leptr = (__le16 *)ta;
p1k[0] = Lo16(tsc_IV32);
p1k[1] = Hi16(tsc_IV32);
- p1k[2] = Mk16(ta[1], ta[0]);
- p1k[3] = Mk16(ta[3], ta[2]);
- p1k[4] = Mk16(ta[5], ta[4]);
+ p1k[2] = le16_to_cpup(leptr++);
+ p1k[3] = le16_to_cpup(leptr++);
+ p1k[4] = le16_to_cpup(leptr++);
+ leptr = (__le16 *)tk;
for (i = 0; i < PHASE1_LOOP_COUNT; i++) {
- j = 2 * (i & 1);
- p1k[0] += tkip_S(p1k[4] ^ Mk16(tk[ 1 + j], tk[ 0 + j]));
- p1k[1] += tkip_S(p1k[0] ^ Mk16(tk[ 5 + j], tk[ 4 + j]));
- p1k[2] += tkip_S(p1k[1] ^ Mk16(tk[ 9 + j], tk[ 8 + j]));
- p1k[3] += tkip_S(p1k[2] ^ Mk16(tk[13 + j], tk[12 + j]));
- p1k[4] += tkip_S(p1k[3] ^ Mk16(tk[ 1 + j], tk[ 0 + j])) + i;
+ j = (i & 1);
+ p1k[0] += tkip_S(p1k[4] ^ le16_to_cpup(leptr + 0 + j));
+ p1k[1] += tkip_S(p1k[0] ^ le16_to_cpup(leptr + 2 + j));
+ p1k[2] += tkip_S(p1k[1] ^ le16_to_cpup(leptr + 4 + j));
+ p1k[3] += tkip_S(p1k[2] ^ le16_to_cpup(leptr + 6 + j));
+ p1k[4] += tkip_S(p1k[3] ^ le16_to_cpup(leptr + 0 + j)) + i;
}
}
@@ -130,6 +125,7 @@ static void tkip_mixing_phase2(const u16 *p1k, const u8 *tk, u16 tsc_IV16,
{
u16 ppk[6];
int i;
+ __le16 *leptr = (__le16 *)tk;
ppk[0] = p1k[0];
ppk[1] = p1k[1];
@@ -138,23 +134,24 @@ static void tkip_mixing_phase2(const u16 *p1k, const u8 *tk, u16 tsc_IV16,
ppk[4] = p1k[4];
ppk[5] = p1k[4] + tsc_IV16;
- ppk[0] += tkip_S(ppk[5] ^ Mk16(tk[ 1], tk[ 0]));
- ppk[1] += tkip_S(ppk[0] ^ Mk16(tk[ 3], tk[ 2]));
- ppk[2] += tkip_S(ppk[1] ^ Mk16(tk[ 5], tk[ 4]));
- ppk[3] += tkip_S(ppk[2] ^ Mk16(tk[ 7], tk[ 6]));
- ppk[4] += tkip_S(ppk[3] ^ Mk16(tk[ 9], tk[ 8]));
- ppk[5] += tkip_S(ppk[4] ^ Mk16(tk[11], tk[10]));
- ppk[0] += ror16(ppk[5] ^ Mk16(tk[13], tk[12]), 1);
- ppk[1] += ror16(ppk[0] ^ Mk16(tk[15], tk[14]), 1);
+ ppk[0] += tkip_S(ppk[5] ^ le16_to_cpup(leptr++));
+ ppk[1] += tkip_S(ppk[0] ^ le16_to_cpup(leptr++));
+ ppk[2] += tkip_S(ppk[1] ^ le16_to_cpup(leptr++));
+ ppk[3] += tkip_S(ppk[2] ^ le16_to_cpup(leptr++));
+ ppk[4] += tkip_S(ppk[3] ^ le16_to_cpup(leptr++));
+ ppk[5] += tkip_S(ppk[4] ^ le16_to_cpup(leptr++));
+ ppk[0] += ror16(ppk[5] ^ le16_to_cpup(leptr++), 1);
+ ppk[1] += ror16(ppk[0] ^ le16_to_cpup(leptr++), 1);
ppk[2] += ror16(ppk[1], 1);
ppk[3] += ror16(ppk[2], 1);
ppk[4] += ror16(ppk[3], 1);
ppk[5] += ror16(ppk[4], 1);
+ leptr = (__le16 *)tk;
rc4key[0] = Hi8(tsc_IV16);
rc4key[1] = (Hi8(tsc_IV16) | 0x20) & 0x7f;
rc4key[2] = Lo8(tsc_IV16);
- rc4key[3] = Lo8((ppk[5] ^ Mk16(tk[1], tk[0])) >> 1);
+ rc4key[3] = Lo8((ppk[5] ^ le16_to_cpup(leptr)) >> 1);
for (i = 0; i < 6; i++) {
rc4key[4 + 2 * i] = Lo8(ppk[i]);
--
1.5.4.GIT
next reply other threads:[~2008-03-08 9:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-08 9:23 Harvey Harrison [this message]
2008-03-11 16:14 ` [PATCH 3/5] mac80211: replace Mk16 helper with le16_to_cpup Johannes Berg
2008-03-11 16:21 ` Harvey Harrison
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=1204968187.23455.39.camel@brick \
--to=harvey.harrison@gmail.com \
--cc=jbenc@suse.cz \
--cc=linux-wireless@vger.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).