Resync with broadcom drivers 5.100.138.20 and utilities.
[tomato.git] / release / src-rt / bcmcrypto / tkmic.c
blobf9f94075dd01d967225ef7cffa10b0577b5c50fe
1 /*
2 * tkmic.c - TKIP Message Integrity Check (MIC) functions
4 * Copyright (C) 2010, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8 * the contents of this file may not be disclosed to third parties, copied
9 * or duplicated in any form, in whole or in part, without the prior
10 * written permission of Broadcom Corporation.
12 * $Id: tkmic.c,v 1.2.540.1 2010-04-22 22:27:54 Exp $
15 #include <typedefs.h>
16 #include <bcmendian.h>
17 #include <bcmcrypto/tkmic.h>
20 * "Michael" Messge Integrity Check (MIC) algorithm
22 static INLINE void
23 tkip_micblock(uint32 *left, uint32 *right)
25 uint32 l = *left;
26 uint32 r = *right;
28 r ^= ROTR32(l, 15);
29 l += r; /* mod 2^32 */
30 r ^= XSWAP32(l);
31 l += r; /* mod 2^32 */
32 r ^= ROTR32(l, 29);
33 l += r; /* mod 2^32 */
34 r ^= ROTR32(l, 2);
35 l += r; /* mod 2^32 */
37 *left = l;
38 *right = r;
42 /* compute mic across message */
43 /* buffer must already have terminator and padding appended */
44 /* buffer length (n) specified in bytes */
45 void
46 BCMROMFN(tkip_mic)(uint32 k0, uint32 k1, int n, uint8 *m, uint32 *left, uint32 *right)
48 uint32 l = k0;
49 uint32 r = k1;
51 if (((uintptr)m & 3) == 0) {
52 for (; n > 0; n -= 4) {
53 l ^= ltoh32(*(uint *)m);
54 m += 4;
55 tkip_micblock(&l, &r);
57 } else {
58 for (; n > 0; n -= 4) {
59 l ^= ltoh32_ua(m);
60 m += 4;
61 tkip_micblock(&l, &r);
64 *left = l;
65 *right = r;
68 /* append the MIC terminator to the data buffer */
69 /* terminator is 0x5a followed by 4-7 bytes of 0 */
70 /* param 'o' is the current frag's offset in the frame */
71 /* returns length of message plus terminator in bytes */
72 int
73 BCMROMFN(tkip_mic_eom)(uint8 *m, uint n, uint o)
75 uint8 *mend = m + n;
76 uint t = n + o;
77 mend[0] = 0x5a;
78 mend[1] = 0;
79 mend[2] = 0;
80 mend[3] = 0;
81 mend[4] = 0;
82 mend += 5;
83 o += n + 5;
84 while (o++%4) {
85 *mend++ = 0;
87 return (n+o-1-t);