diff options
author | Harvey Harrison <harvey.harrison@gmail.com> | 2008-05-14 19:26:16 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-05-21 21:47:47 -0400 |
commit | 1bd3dff549537d3d9b92d0b284f4cc2be264a56d (patch) | |
tree | f91ae27448a00734ab035919c4e9f15b056909f7 | |
parent | 57962f0b9d76487a660619f97c0aa811924274a0 (diff) |
mac80211: michael.c use kernel-provided infrastructure
Replace private implementation of bit rotation and unaligned access helpers
with kernel-provided implementation.
Fold xswap helper in its one usage in the michael_block macro.
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Cc: "John W. Linville" <linville@tuxdriver.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | net/mac80211/michael.c | 60 |
1 files changed, 14 insertions, 46 deletions
diff --git a/net/mac80211/michael.c b/net/mac80211/michael.c index 0f844f7895f1..c1e5897fcf7c 100644 --- a/net/mac80211/michael.c +++ b/net/mac80211/michael.c | |||
@@ -8,71 +8,39 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/types.h> | 10 | #include <linux/types.h> |
11 | #include <linux/bitops.h> | ||
12 | #include <asm/unaligned.h> | ||
11 | 13 | ||
12 | #include "michael.h" | 14 | #include "michael.h" |
13 | 15 | ||
14 | static inline u32 rotr(u32 val, int bits) | ||
15 | { | ||
16 | return (val >> bits) | (val << (32 - bits)); | ||
17 | } | ||
18 | |||
19 | |||
20 | static inline u32 rotl(u32 val, int bits) | ||
21 | { | ||
22 | return (val << bits) | (val >> (32 - bits)); | ||
23 | } | ||
24 | |||
25 | |||
26 | static inline u32 xswap(u32 val) | ||
27 | { | ||
28 | return ((val & 0xff00ff00) >> 8) | ((val & 0x00ff00ff) << 8); | ||
29 | } | ||
30 | |||
31 | |||
32 | #define michael_block(l, r) \ | 16 | #define michael_block(l, r) \ |
33 | do { \ | 17 | do { \ |
34 | r ^= rotl(l, 17); \ | 18 | r ^= rol32(l, 17); \ |
35 | l += r; \ | 19 | l += r; \ |
36 | r ^= xswap(l); \ | 20 | r ^= ((l & 0xff00ff00) >> 8) | ((l & 0x00ff00ff) << 8); \ |
37 | l += r; \ | 21 | l += r; \ |
38 | r ^= rotl(l, 3); \ | 22 | r ^= rol32(l, 3); \ |
39 | l += r; \ | 23 | l += r; \ |
40 | r ^= rotr(l, 2); \ | 24 | r ^= ror32(l, 2); \ |
41 | l += r; \ | 25 | l += r; \ |
42 | } while (0) | 26 | } while (0) |
43 | 27 | ||
44 | |||
45 | static inline u32 michael_get32(u8 *data) | ||
46 | { | ||
47 | return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); | ||
48 | } | ||
49 | |||
50 | |||
51 | static inline void michael_put32(u32 val, u8 *data) | ||
52 | { | ||
53 | data[0] = val & 0xff; | ||
54 | data[1] = (val >> 8) & 0xff; | ||
55 | data[2] = (val >> 16) & 0xff; | ||
56 | data[3] = (val >> 24) & 0xff; | ||
57 | } | ||
58 | |||
59 | |||
60 | void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority, | 28 | void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority, |
61 | u8 *data, size_t data_len, u8 *mic) | 29 | u8 *data, size_t data_len, u8 *mic) |
62 | { | 30 | { |
63 | u32 l, r, val; | 31 | u32 l, r, val; |
64 | size_t block, blocks, left; | 32 | size_t block, blocks, left; |
65 | 33 | ||
66 | l = michael_get32(key); | 34 | l = get_unaligned_le32(key); |
67 | r = michael_get32(key + 4); | 35 | r = get_unaligned_le32(key + 4); |
68 | 36 | ||
69 | /* A pseudo header (DA, SA, Priority, 0, 0, 0) is used in Michael MIC | 37 | /* A pseudo header (DA, SA, Priority, 0, 0, 0) is used in Michael MIC |
70 | * calculation, but it is _not_ transmitted */ | 38 | * calculation, but it is _not_ transmitted */ |
71 | l ^= michael_get32(da); | 39 | l ^= get_unaligned_le32(da); |
72 | michael_block(l, r); | 40 | michael_block(l, r); |
73 | l ^= da[4] | (da[5] << 8) | (sa[0] << 16) | (sa[1] << 24); | 41 | l ^= get_unaligned_le16(&da[4]) | (get_unaligned_le16(sa) << 16); |
74 | michael_block(l, r); | 42 | michael_block(l, r); |
75 | l ^= michael_get32(&sa[2]); | 43 | l ^= get_unaligned_le32(&sa[2]); |
76 | michael_block(l, r); | 44 | michael_block(l, r); |
77 | l ^= priority; | 45 | l ^= priority; |
78 | michael_block(l, r); | 46 | michael_block(l, r); |
@@ -82,7 +50,7 @@ void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority, | |||
82 | left = data_len % 4; | 50 | left = data_len % 4; |
83 | 51 | ||
84 | for (block = 0; block < blocks; block++) { | 52 | for (block = 0; block < blocks; block++) { |
85 | l ^= michael_get32(&data[block * 4]); | 53 | l ^= get_unaligned_le32(&data[block * 4]); |
86 | michael_block(l, r); | 54 | michael_block(l, r); |
87 | } | 55 | } |
88 | 56 | ||
@@ -99,6 +67,6 @@ void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority, | |||
99 | /* last block is zero, so l ^ 0 = l */ | 67 | /* last block is zero, so l ^ 0 = l */ |
100 | michael_block(l, r); | 68 | michael_block(l, r); |
101 | 69 | ||
102 | michael_put32(l, mic); | 70 | put_unaligned_le32(l, mic); |
103 | michael_put32(r, mic + 4); | 71 | put_unaligned_le32(r, mic + 4); |
104 | } | 72 | } |