-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathXKRC4.cpp
130 lines (113 loc) · 4 KB
/
XKRC4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
**********************************
**********************************
** BROUGHT TO YOU BY: **
**********************************
**********************************
** **
** [TEAM ASSEMBLY] **
** **
** www.team-assembly.com **
** **
******************************************************************************************************
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
******************************************************************************************************
********************************************************************************************************
** XKRC4.CPP - General RC4 Encryption Class' Implementation
********************************************************************************************************
**
** This is the Class Contains basic RC4 encryption functionality...
**
********************************************************************************************************
********************************************************************************************************
** CREDITS:
********************************************************************************************************
** SPEEDBUMP:
** ---------
** My utmost greatfullness and admiration goes towards SpeedBump for all his hard work..
** I used most of his code and converted to C++ objects etc..
**
** XBOX-LINUX TEAM:
** ---------------
** Wow, you guys are awsome !! I bow down to your greatness !!
** REFERENCE URL: http://xbox-linux.sourceforge.net
**
********************************************************************************************************
UPDATE LOG:
--------------------------------------------------------------------------------------------------------
Date: 02/18/2003
By: UNDEAD [team-assembly]
Reason: Prepared 0.2 for Public Release
--------------------------------------------------------------------------------------------------------
Date: 01/06/2003
By: UNDEAD [team-assembly]
Reason: Prepared for Public Release
--------------------------------------------------------------------------------------------------------
*/
#include "XKRC4.h"
XKRC4::XKRC4(void)
{
}
XKRC4::~XKRC4(void)
{
}
void XKRC4::InitRC4Key(UCHAR* pRC4KeyData, int KeyLen, RC4KEY *pRC4Key)
{
UCHAR index1;
UCHAR index2;
UCHAR* state;
short counter;
state = &pRC4Key->state[0];
for(counter = 0; counter < 256; counter++)
state[counter] = (UCHAR)counter;
pRC4Key->x = 0;
pRC4Key->y = 0;
index1 = 0;
index2 = 0;
for(counter = 0; counter < 256; counter++)
{
index2 = (pRC4KeyData[index1] + state[counter] + index2) % 256;
swap_byte(&state[counter], &state[index2]);
index1 = (index1 + 1) % KeyLen;
}
}
void XKRC4::RC4EnDecrypt(UCHAR* pData, int DataLen, RC4KEY *pRC4key)
{
unsigned char x;
unsigned char y;
unsigned char* state;
unsigned char xorIndex;
long counter;
x = pRC4key->x;
y = pRC4key->y;
state = &pRC4key->state[0];
for(counter = 0; counter < DataLen; counter ++)
{
x = (x + 1) % 256;
y = (state[x] + y) % 256;
swap_byte(&state[x], &state[y]);
xorIndex = (state[x] + state[y]) % 256;
pData[counter] ^= state[xorIndex];
}
pRC4key->x = x;
pRC4key->y = y;
}
void XKRC4::swap_byte(unsigned char *a, unsigned char *b)
{
unsigned char swapByte;
swapByte = *a;
*a = *b;
*b = swapByte;
}