2 * Copyright (c) 1996, 2003 VIA Networking Technologies, 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 as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 VOID
rc4_init(PRC4Ext pRC4
, PBYTE pbyKey
, UINT cbKey_len
)
43 pbyst
= pRC4
->abystate
;
46 for (idx
= 0; idx
< 256; idx
++)
47 pbyst
[idx
] = (BYTE
)idx
;
50 for (idx
= 0; idx
< 256; idx
++) {
52 stateindex
= (stateindex
+ pbyKey
[keyindex
] + ust1
) & 0xff;
53 ust2
= pbyst
[stateindex
];
54 pbyst
[stateindex
] = (BYTE
)ust1
;
55 pbyst
[idx
] = (BYTE
)ust2
;
56 if (++keyindex
>= cbKey_len
)
61 UINT
rc4_byte(PRC4Ext pRC4
)
68 pbyst
= pRC4
->abystate
;
69 ux
= (pRC4
->ux
+ 1) & 0xff;
71 uy
= (ustx
+ pRC4
->uy
) & 0xff;
75 pbyst
[uy
] = (BYTE
)ustx
;
76 pbyst
[ux
] = (BYTE
)usty
;
78 return pbyst
[(ustx
+ usty
) & 0xff];
81 VOID
rc4_encrypt(PRC4Ext pRC4
, PBYTE pbyDest
,
82 PBYTE pbySrc
, UINT cbData_len
)
85 for (ii
= 0; ii
< cbData_len
; ii
++)
86 pbyDest
[ii
] = (BYTE
)(pbySrc
[ii
] ^ rc4_byte(pRC4
));