Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <linux/types.h>
00010 #include <linux/bitops.h>
00011 #include <linux/ieee80211.h>
00012 #include <asm/unaligned.h>
00013
00014 #include "michael.h"
00015
00016 static void michael_block(struct michael_mic_ctx *mctx, u32 val)
00017 {
00018 mctx->l ^= val;
00019 mctx->r ^= rol32(mctx->l, 17);
00020 mctx->l += mctx->r;
00021 mctx->r ^= ((mctx->l & 0xff00ff00) >> 8) |
00022 ((mctx->l & 0x00ff00ff) << 8);
00023 mctx->l += mctx->r;
00024 mctx->r ^= rol32(mctx->l, 3);
00025 mctx->l += mctx->r;
00026 mctx->r ^= ror32(mctx->l, 2);
00027 mctx->l += mctx->r;
00028 }
00029
00030 static void michael_mic_hdr(struct michael_mic_ctx *mctx, const u8 *key,
00031 struct ieee80211_hdr *hdr)
00032 {
00033 u8 *da, *sa, tid;
00034
00035 da = ieee80211_get_DA(hdr);
00036 sa = ieee80211_get_SA(hdr);
00037 if (ieee80211_is_data_qos(hdr->frame_control))
00038 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
00039 else
00040 tid = 0;
00041
00042 mctx->l = get_unaligned_le32(key);
00043 mctx->r = get_unaligned_le32(key + 4);
00044
00045
00046
00047
00048
00049 michael_block(mctx, get_unaligned_le32(da));
00050 michael_block(mctx, get_unaligned_le16(&da[4]) |
00051 (get_unaligned_le16(sa) << 16));
00052 michael_block(mctx, get_unaligned_le32(&sa[2]));
00053 michael_block(mctx, tid);
00054 }
00055
00056 void michael_mic(const u8 *key, struct ieee80211_hdr *hdr,
00057 const u8 *data, size_t data_len, u8 *mic)
00058 {
00059 u32 val;
00060 size_t block, blocks, left;
00061 struct michael_mic_ctx mctx;
00062
00063 michael_mic_hdr(&mctx, key, hdr);
00064
00065
00066 blocks = data_len / 4;
00067 left = data_len % 4;
00068
00069 for (block = 0; block < blocks; block++)
00070 michael_block(&mctx, get_unaligned_le32(&data[block * 4]));
00071
00072
00073
00074 val = 0x5a;
00075 while (left > 0) {
00076 val <<= 8;
00077 left--;
00078 val |= data[blocks * 4 + left];
00079 }
00080
00081 michael_block(&mctx, val);
00082 michael_block(&mctx, 0);
00083
00084 put_unaligned_le32(mctx.l, mic);
00085 put_unaligned_le32(mctx.r, mic + 4);
00086 }