-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathISCrypt.c
71 lines (60 loc) · 1.34 KB
/
ISCrypt.c
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
#include <windows.h>
typedef unsigned char byte;
struct ArcFourContext {
byte state[256];
byte x, y;
};
int __stdcall ISCryptGetVersion()
{
return 1;
}
void __stdcall ArcFourInit(struct ArcFourContext *context, const byte *key, unsigned int key_length)
{
unsigned int i, j = 0, k = 0;
for (i = 0; i < 256; i++) {
context->state[i] = i;
}
for (i = 0; i < 256; i++)
{
byte a = context->state[i];
j = (j + key[k] + a) & 0xff;
context->state[i] = context->state[j];
context->state[j] = a;
if(++k >= key_length) {
k = 0;
}
}
context->x = 0;
context->y = 0;
}
void __stdcall ArcFourCrypt(struct ArcFourContext *context, const byte *in_buffer, byte *out_buffer,
unsigned int length)
{
byte x = context->x;
byte y = context->y;
byte *state = context->state;
unsigned int i;
byte a, b;
for (i = 0; i < length; i++)
{
x = (x + 1) & 0xff;
a = state[x];
y = (y + a) & 0xff;
b = state[y];
state[x] = b;
state[y] = a;
if (out_buffer != NULL) {
out_buffer[i] = in_buffer[i] ^ state[(a + b) & 0xff];
}
}
context->x = x;
context->y = y;
}
BOOL WINAPI _DllMainCRTStartup(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hInstance);
}
return TRUE;
}