~computersforpeace/ubuntu/utopic/bcmwl/fix-for-1358966

« back to all changes in this revision

Viewing changes to src/src/bcmcrypto/tkmic.c

  • Committer: Package Import Robot
  • Author(s): Alberto Milone
  • Date: 2012-12-11 17:06:22 UTC
  • mfrom: (2.1.6)
  • Revision ID: package-import@ubuntu.com-20121211170622-7bd9yp2wm1plhhu1
Tags: 6.20.155.1+bdcom-0ubuntu1
* New upstream release (LP: #923809):
  - Added 43142 support.
  - Added 4331 support.
* debian/control:
  - depend on the different flavours of the linux-headers.
* Refresh 0002-Makefile.patch and 0001-MODULE_LICENSE.patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   tkmic.c - TKIP Message Integrity Check (MIC) functions
 
3
 *
 
4
 * Copyright (C) 2011, Broadcom Corporation. All Rights Reserved.
 
5
 * 
 
6
 * Permission to use, copy, modify, and/or distribute this software for any
 
7
 * purpose with or without fee is hereby granted, provided that the above
 
8
 * copyright notice and this permission notice appear in all copies.
 
9
 * 
 
10
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 
11
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 
12
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 
13
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
14
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 
15
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 
16
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
17
 *
 
18
 * $Id: tkmic.c 326246 2012-04-06 19:08:11Z $
 
19
 */
 
20
 
 
21
#include <typedefs.h>
 
22
#include <bcmendian.h>
 
23
#include <bcmcrypto/tkmic.h>
 
24
 
 
25
static INLINE void
 
26
tkip_micblock(uint32 *left, uint32 *right)
 
27
{
 
28
        uint32 l = *left;
 
29
        uint32 r = *right;
 
30
 
 
31
        r ^= ROTR32(l, 15);
 
32
        l += r; 
 
33
        r ^= XSWAP32(l);
 
34
        l += r; 
 
35
        r ^= ROTR32(l, 29);
 
36
        l += r; 
 
37
        r ^= ROTR32(l, 2);
 
38
        l += r; 
 
39
 
 
40
        *left = l;
 
41
        *right = r;
 
42
}
 
43
 
 
44
void
 
45
BCMROMFN(tkip_mic)(uint32 k0, uint32 k1, int n, uint8 *m, uint32 *left, uint32 *right)
 
46
{
 
47
        uint32 l = k0;
 
48
        uint32 r = k1;
 
49
 
 
50
        if (((uintptr)m & 3) == 0) {
 
51
                for (; n > 0; n -= 4) {
 
52
                        l ^= ltoh32(*(uint *)m);
 
53
                        m += 4;
 
54
                        tkip_micblock(&l, &r);
 
55
                }
 
56
        } else {
 
57
                for (; n > 0; n -= 4) {
 
58
                        l ^= ltoh32_ua(m);
 
59
                        m += 4;
 
60
                        tkip_micblock(&l, &r);
 
61
                }
 
62
        }
 
63
        *left = l;
 
64
        *right = r;
 
65
}
 
66
 
 
67
int
 
68
BCMROMFN(tkip_mic_eom)(uint8 *m, uint n, uint o)
 
69
{
 
70
        uint8 *mend = m + n;
 
71
        uint t = n + o;
 
72
        mend[0] = 0x5a;
 
73
        mend[1] = 0;
 
74
        mend[2] = 0;
 
75
        mend[3] = 0;
 
76
        mend[4] = 0;
 
77
        mend += 5;
 
78
        o += n + 5;
 
79
        while (o++%4) {
 
80
                *mend++ = 0;
 
81
        }
 
82
        return (n+o-1-t);
 
83
}