* [PATCH 3/5] mac80211: replace Mk16 helper with le16_to_cpup
@ 2008-03-08 9:23 Harvey Harrison
2008-03-11 16:14 ` Johannes Berg
0 siblings, 1 reply; 3+ messages in thread
From: Harvey Harrison @ 2008-03-08 9:23 UTC (permalink / raw)
To: Jiri Benc; +Cc: linux-wireless
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 3/5] mac80211: replace Mk16 helper with le16_to_cpup
2008-03-08 9:23 [PATCH 3/5] mac80211: replace Mk16 helper with le16_to_cpup Harvey Harrison
@ 2008-03-11 16:14 ` Johannes Berg
2008-03-11 16:21 ` Harvey Harrison
0 siblings, 1 reply; 3+ messages in thread
From: Johannes Berg @ 2008-03-11 16:14 UTC (permalink / raw)
To: Harvey Harrison; +Cc: Jiri Benc, linux-wireless
[-- Attachment #1: Type: text/plain, Size: 305 bytes --]
On Sat, 2008-03-08 at 01:23 -0800, Harvey Harrison wrote:
> Opencoded byte-swapping could just use the kernel helper.
> + p1k[2] = le16_to_cpup(leptr++);
I'm ok with this if architectures guarantee that these operations work
on unaligned values, but I don't think that is the case.
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 3/5] mac80211: replace Mk16 helper with le16_to_cpup
2008-03-11 16:14 ` Johannes Berg
@ 2008-03-11 16:21 ` Harvey Harrison
0 siblings, 0 replies; 3+ messages in thread
From: Harvey Harrison @ 2008-03-11 16:21 UTC (permalink / raw)
To: Johannes Berg; +Cc: Jiri Benc, linux-wireless
On Tue, 2008-03-11 at 17:14 +0100, Johannes Berg wrote:
> On Sat, 2008-03-08 at 01:23 -0800, Harvey Harrison wrote:
> > Opencoded byte-swapping could just use the kernel helper.
>
> > + p1k[2] = le16_to_cpup(leptr++);
>
> I'm ok with this if architectures guarantee that these operations work
> on unaligned values, but I don't think that is the case.
>
I'm looking into this, but I'm pretty sure this isn't right as-is.
I wasn't thinking about alignment at the time, just ignore this.
Harvey
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-03-11 16:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-08 9:23 [PATCH 3/5] mac80211: replace Mk16 helper with le16_to_cpup Harvey Harrison
2008-03-11 16:14 ` Johannes Berg
2008-03-11 16:21 ` Harvey Harrison
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).