linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] mac80211: use kernel-provided bit rotation/byteordering
@ 2008-03-08  9:22 Harvey Harrison
  2008-03-11 16:11 ` Johannes Berg
  0 siblings, 1 reply; 3+ messages in thread
From: Harvey Harrison @ 2008-03-08  9:22 UTC (permalink / raw)
  To: Jiri Benc; +Cc: linux-wireless

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
Perhaps a bit too fine-grained of a patch series, but each one should
be pretty easily reviewable.

 include/linux/bitops.h |   40 ++++++++++++++++++++++++++++++++++++++++
 net/mac80211/michael.c |   28 ++++++----------------------
 net/mac80211/tkip.c    |   20 ++++++--------------
 3 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 69c1edb..40d5473 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -65,6 +65,46 @@ static inline __u32 ror32(__u32 word, unsigned int shift)
 	return (word >> shift) | (word << (32 - shift));
 }
 
+/**
+ * rol16 - rotate a 16-bit value left
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u16 rol16(__u16 word, unsigned int shift)
+{
+	return (word << shift) | (word >> (16 - shift));
+}
+
+/**
+ * ror16 - rotate a 16-bit value right
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u16 ror16(__u16 word, unsigned int shift)
+{
+	return (word >> shift) | (word << (16 - shift));
+}
+
+/**
+ * rol8 - rotate an 8-bit value left
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u8 rol8(__u8 word, unsigned int shift)
+{
+	return (word << shift) | (word >> (8 - shift));
+}
+
+/**
+ * ror8 - rotate an 8-bit value right
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u8 ror8(__u8 word, unsigned int shift)
+{
+	return (word >> shift) | (word << (8 - shift));
+}
+
 static inline unsigned fls_long(unsigned long l)
 {
 	if (sizeof(l) == 4)
diff --git a/net/mac80211/michael.c b/net/mac80211/michael.c
index 0f844f7..1a1871f 100644
--- a/net/mac80211/michael.c
+++ b/net/mac80211/michael.c
@@ -7,53 +7,37 @@
  * published by the Free Software Foundation.
  */
 
-#include <linux/types.h>
+#include <linux/kernel.h>
 
 #include "michael.h"
 
-static inline u32 rotr(u32 val, int bits)
-{
-	return (val >> bits) | (val << (32 - bits));
-}
-
-
-static inline u32 rotl(u32 val, int bits)
-{
-	return (val << bits) | (val >> (32 - bits));
-}
-
-
 static inline u32 xswap(u32 val)
 {
 	return ((val & 0xff00ff00) >> 8) | ((val & 0x00ff00ff) << 8);
 }
 
-
 #define michael_block(l, r) \
 do { \
-	r ^= rotl(l, 17); \
+	r ^= rol32(l, 17); \
 	l += r; \
 	r ^= xswap(l); \
 	l += r; \
-	r ^= rotl(l, 3); \
+	r ^= rol32(l, 3); \
 	l += r; \
-	r ^= rotr(l, 2); \
+	r ^= ror32(l, 2); \
 	l += r; \
 } while (0)
 

 static inline u32 michael_get32(u8 *data)
 {
-	return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
+	return le32_to_cpup((__le32 *)data);
 }
 

 static inline void michael_put32(u32 val, u8 *data)
 {
-	data[0] = val & 0xff;
-	data[1] = (val >> 8) & 0xff;
-	data[2] = (val >> 16) & 0xff;
-	data[3] = (val >> 24) & 0xff;
+	*((u32 *)data) = cpu_to_le32(val);
 }
 

diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c
index 3abe194..229b4b4 100644
--- a/net/mac80211/tkip.c
+++ b/net/mac80211/tkip.c
@@ -8,7 +8,6 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/types.h>
 #include <linux/netdevice.h>
 
 #include <net/mac80211.h>
@@ -91,13 +90,6 @@ static inline u16 Lo16(u32 v)
 	return v & 0xffff;
 }
 
-
-static inline u16 RotR1(u16 v)
-{
-	return (v >> 1) | ((v & 0x0001) << 15);
-}
-
-
 static inline u16 tkip_S(u16 val)
 {
 	u16 a = tkip_sbox[Hi8(val)];
@@ -154,12 +146,12 @@ static void tkip_mixing_phase2(const u16 *p1k, const u8 *tk, u16 tsc_IV16,
 	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] +=  RotR1(ppk[5] ^ Mk16(tk[13], tk[12]));
-	ppk[1] +=  RotR1(ppk[0] ^ Mk16(tk[15], tk[14]));
-	ppk[2] +=  RotR1(ppk[1]);
-	ppk[3] +=  RotR1(ppk[2]);
-	ppk[4] +=  RotR1(ppk[3]);
-	ppk[5] +=  RotR1(ppk[4]);
+	ppk[0] += ror16(ppk[5] ^ Mk16(tk[13], tk[12]), 1);
+	ppk[1] += ror16(ppk[0] ^ Mk16(tk[15], tk[14]), 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);
 
 	rc4key[0] = Hi8(tsc_IV16);
 	rc4key[1] = (Hi8(tsc_IV16) | 0x20) & 0x7f;
-- 
1.5.4.GIT



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/5] mac80211: use kernel-provided bit rotation/byteordering
  2008-03-08  9:22 [PATCH 1/5] mac80211: use kernel-provided bit rotation/byteordering Harvey Harrison
@ 2008-03-11 16:11 ` Johannes Berg
  2008-03-11 16:17   ` Harvey Harrison
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Berg @ 2008-03-11 16:11 UTC (permalink / raw)
  To: Harvey Harrison; +Cc: Jiri Benc, linux-wireless

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


>  include/linux/bitops.h |   40 ++++++++++++++++++++++++++++++++++++++++

> +++ b/include/linux/bitops.h
> @@ -65,6 +65,46 @@ static inline __u32 ror32(__u32 word, unsigned int shift)
>  	return (word >> shift) | (word << (32 - shift));
>  }
>  
> +/**
> + * rol16 - rotate a 16-bit value left
> + * @word: value to rotate
> + * @shift: bits to roll
> + */
> +static inline __u16 rol16(__u16 word, unsigned int shift)

I don't think we can take that via wireless, and I think architectures
should be able to override this if they can optimise it (though the
compiler might be good enough...)

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 1/5] mac80211: use kernel-provided bit rotation/byteordering
  2008-03-11 16:11 ` Johannes Berg
@ 2008-03-11 16:17   ` Harvey Harrison
  0 siblings, 0 replies; 3+ messages in thread
From: Harvey Harrison @ 2008-03-11 16:17 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Jiri Benc, linux-wireless

On Tue, 2008-03-11 at 17:11 +0100, Johannes Berg wrote:
> >  include/linux/bitops.h |   40 ++++++++++++++++++++++++++++++++++++++++
> 
> > +++ b/include/linux/bitops.h
> > @@ -65,6 +65,46 @@ static inline __u32 ror32(__u32 word, unsigned int shift)
> >  	return (word >> shift) | (word << (32 - shift));
> >  }
> >  
> > +/**
> > + * rol16 - rotate a 16-bit value left
> > + * @word: value to rotate
> > + * @shift: bits to roll
> > + */
> > +static inline __u16 rol16(__u16 word, unsigned int shift)
> 
> I don't think we can take that via wireless, and I think architectures
> should be able to override this if they can optimise it (though the
> compiler might be good enough...)

OK, I'll get the common parts through Andrew and once that's in I'll
resubmit the wireless parts.

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:22 [PATCH 1/5] mac80211: use kernel-provided bit rotation/byteordering Harvey Harrison
2008-03-11 16:11 ` Johannes Berg
2008-03-11 16:17   ` 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).