~ubuntu-branches/ubuntu/vivid/bcmwl/vivid

« back to all changes in this revision

Viewing changes to src/src/bcmcrypto/rc4.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
 * rc4.c
 
3
 * RC4 stream cipher
 
4
 *
 
5
 * Copyright (C) 2011, Broadcom Corporation. All Rights Reserved.
 
6
 * 
 
7
 * Permission to use, copy, modify, and/or distribute this software for any
 
8
 * purpose with or without fee is hereby granted, provided that the above
 
9
 * copyright notice and this permission notice appear in all copies.
 
10
 * 
 
11
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 
12
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 
13
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 
14
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
15
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 
16
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 
17
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
18
 *
 
19
 * $Id: rc4.c 326246 2012-04-06 19:08:11Z $
 
20
 */
 
21
 
 
22
#include <typedefs.h>
 
23
#include <bcmcrypto/rc4.h>
 
24
 
 
25
void
 
26
BCMROMFN(prepare_key)(uint8 *key_data, int key_data_len, rc4_ks_t *ks)
 
27
{
 
28
        unsigned int counter, index1 = 0, index2 = 0;
 
29
        uint8 key_byte, temp;
 
30
        uint8 *key_state = ks->state;
 
31
 
 
32
        for (counter = 0; counter < RC4_STATE_NBYTES; counter++) {
 
33
                key_state[counter] = (uint8) counter;
 
34
        }
 
35
 
 
36
        for (counter = 0; counter < RC4_STATE_NBYTES; counter++) {
 
37
                key_byte = key_data[index1];
 
38
                index2 = (key_byte + key_state[counter] + index2) % RC4_STATE_NBYTES;
 
39
                temp = key_state[counter];
 
40
                key_state[counter] = key_state[index2];
 
41
                key_state[index2] = temp;
 
42
                index1 = (index1 + 1) % key_data_len;
 
43
        }
 
44
 
 
45
        ks->x = 0;
 
46
        ks->y = 0;
 
47
}
 
48
 
 
49
void
 
50
BCMROMFN(rc4)(uint8 *buf, int data_len, rc4_ks_t *ks)
 
51
{
 
52
        uint8 tmp;
 
53
        uint8 xor_ind, x = ks->x, y = ks->y, *key_state = ks->state;
 
54
        int i;
 
55
 
 
56
        for (i = 0; i < data_len; i++) {
 
57
                y += key_state[++x]; 
 
58
                tmp = key_state[x];
 
59
                key_state[x] = key_state[y];
 
60
                key_state[y] = tmp;
 
61
                xor_ind = key_state[x] + key_state[y];
 
62
                buf[i] ^= key_state[xor_ind];
 
63
        }
 
64
 
 
65
        ks->x = x;
 
66
        ks->y = y;
 
67
}