2 * Michael MIC implementation - optimized for TKIP MIC operations
3 * Copyright 2002-2003, Instant802 Networks, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/types.h>
11 #include <linux/bitops.h>
12 #include <asm/unaligned.h>
16 #define michael_block(l, r) \
20 r ^= ((l & 0xff00ff00) >> 8) | ((l & 0x00ff00ff) << 8); \
28 void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority,
29 u8 *data, size_t data_len, u8 *mic)
32 size_t block, blocks, left;
34 l = get_unaligned_le32(key);
35 r = get_unaligned_le32(key + 4);
37 /* A pseudo header (DA, SA, Priority, 0, 0, 0) is used in Michael MIC
38 * calculation, but it is _not_ transmitted */
39 l ^= get_unaligned_le32(da);
41 l ^= get_unaligned_le16(&da[4]) | (get_unaligned_le16(sa) << 16);
43 l ^= get_unaligned_le32(&sa[2]);
49 blocks = data_len / 4;
52 for (block = 0; block < blocks; block++) {
53 l ^= get_unaligned_le32(&data[block * 4]);
57 /* Partial block of 0..3 bytes and padding: 0x5a + 4..7 zeros to make
58 * total length a multiple of 4. */
63 val |= data[blocks * 4 + left];
67 /* last block is zero, so l ^ 0 = l */
70 put_unaligned_le32(l, mic);
71 put_unaligned_le32(r, mic + 4);