webmoney 0.0.14 → 0.0.15.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +15 -0
- data/README.md +13 -1
- data/VERSION +1 -1
- data/lib/signer.rb +128 -0
- data/lib/webmoney.rb +22 -10
- data/rakefile +2 -11
- data/spec/benchmark.rb +12 -0
- data/spec/spec_helper.rb +6 -27
- data/spec/unit/interfaces_spec.rb +2 -2
- data/webmoney.gemspec +6 -21
- metadata +10 -24
- data/ext/wmsigner/base64.cpp +0 -144
- data/ext/wmsigner/base64.h +0 -48
- data/ext/wmsigner/cmdbase.cpp +0 -417
- data/ext/wmsigner/cmdbase.h +0 -111
- data/ext/wmsigner/crypto.cpp +0 -155
- data/ext/wmsigner/crypto.h +0 -17
- data/ext/wmsigner/extconf.rb +0 -17
- data/ext/wmsigner/md4.cpp +0 -192
- data/ext/wmsigner/md4.h +0 -41
- data/ext/wmsigner/rsalib1.cpp +0 -838
- data/ext/wmsigner/rsalib1.h +0 -81
- data/ext/wmsigner/signer.cpp +0 -309
- data/ext/wmsigner/signer.h +0 -63
- data/ext/wmsigner/stdafx.cpp +0 -8
- data/ext/wmsigner/stdafx.h +0 -33
- data/ext/wmsigner/wmsigner.cpp +0 -117
data/ext/wmsigner/base64.cpp
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
/****************************************************************************************************************************
|
2
|
-
* Usage this module :
|
3
|
-
* size_t result = code64( JOB [ENCODE or DECODE], char *ASCII_Buffer, size_t ASCII_BUFFER_SIZE,
|
4
|
-
* char *BASE64_Buffer, size_t BASE64_BUFFER_SIZE );
|
5
|
-
* Sample for decode from ascii to base64 :
|
6
|
-
* result = code64( DECODE, char *ASCII_Buffer, size_t ASCII_BUFFER_SIZE, char *BASE64_Buffer, size_t BASE64_BUFFER_SIZE );
|
7
|
-
* Parameter ASCII_BUFFER_SIZE - definition size input to decode sequence !
|
8
|
-
* function strlen() - may be used ONLY for text buffers, otherwize - BINARY DATA, use really size !
|
9
|
-
* Sample for encode from base64 to ascii :
|
10
|
-
* result = code64( ENCODE, char *ASCII_Buffer, size_t ASCII_BUFFER_SIZE, char *BASE64_Buffer, size_t BASE64_BUFFER_SIZE );
|
11
|
-
* Parameter BASE64_BUFFER_SIZE - definition size input to encode sequence !
|
12
|
-
* function strlen() may be used for counting size for BASE64 array, if last symbol == '\0', otherwise use really size !
|
13
|
-
* .........................................................................................................................
|
14
|
-
* Return value:
|
15
|
-
* size_t result - counter, number of bytes in OUTPUT array, whose successfully encoded/decoded.
|
16
|
-
* if result == 0 - error found, abnormal terminating, nothing to encoding or decoding.
|
17
|
-
* .........................................................................................................................
|
18
|
-
* Internal function: idx64( char Ch ); Binary search index in Base64 array, for Ch character in parameter
|
19
|
-
* .........................................................................................................................
|
20
|
-
* This module present "AS IS", absolutely no warranty, if anybody modyfied this source.
|
21
|
-
****************************************************************************************************************************/
|
22
|
-
#include "base64.h"
|
23
|
-
|
24
|
-
/* Base_64 characters */
|
25
|
-
const char Ch64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
26
|
-
|
27
|
-
/* Presort array for indexes */
|
28
|
-
const INDEX64 Id64[64] = {
|
29
|
-
{'+',62},{'/',63},{'0',52},{'1',53},{'2',54},{'3',55},{'4',56},{'5',57},{'6',58},{'7',59},{'8',60},{'9',61},
|
30
|
-
{'A',0},{'B',1},{'C',2},{'D',3},{'E',4},{'F',5},{'G',6},{'H',7},{'I',8},{'J',9},{'K',10},{'L',11},{'M',12},
|
31
|
-
{'N',13},{'O',14},{'P',15},{'Q',16},{'R',17},{'S',18},{'T',19},{'U',20},{'V',21},{'W',22},{'X',23},{'Y',24},{'Z',25},
|
32
|
-
{'a',26},{'b',27},{'c',28},{'d',29},{'e',30},{'f',31},{'g',32},{'h',33},{'i',34},{'j',35},{'k',36},{'l',37},{'m',38},
|
33
|
-
{'n',39},{'o',40},{'p',41},{'q',42},{'r',43},{'s',44},{'t',45},{'u',46},{'v',47},{'w',48},{'x',49},{'y',50},{'z',51}
|
34
|
-
};
|
35
|
-
|
36
|
-
/* Base64 ENCODE / DECODE function */
|
37
|
-
size_t code64( int job, char *buf_ascii, size_t ascii_size, char *buf_64, size_t buf_64_size )
|
38
|
-
{
|
39
|
-
BASE64 b64;
|
40
|
-
size_t i = 0, j = 0, k = 0, i3 = 0; /* job indexes */
|
41
|
-
size_t ask_len = 0; /* Internal variable for size ascii buffer */
|
42
|
-
size_t buf64_len = 0; /* Internal variable for size base64 buffer */
|
43
|
-
|
44
|
-
b64.a[0] = 0; b64.a[1] = 0; b64.a[2] = 0;
|
45
|
-
|
46
|
-
/* Decoding to Base64 code */
|
47
|
-
if( job == DECODE ) {
|
48
|
-
ask_len = ascii_size;
|
49
|
-
if( (ascii_size * 4 / 3) > buf_64_size ) return( CODE_ERR ); /* No enough space to decoding */
|
50
|
-
if( ask_len == 0 ) return( CODE_ERR );
|
51
|
-
i3 = (int) 3 * (ask_len / 3); /* Dividing by 3 */
|
52
|
-
if( i3 > 0 ) k = 3 - ask_len + i3; /* End of seq (1 or 2) */
|
53
|
-
if( ask_len < 3 ) k = 3 - ask_len;
|
54
|
-
|
55
|
-
while( i < i3 ) {
|
56
|
-
b64.a[2] = buf_ascii[i];
|
57
|
-
b64.a[1] = buf_ascii[i+1];
|
58
|
-
b64.a[0] = buf_ascii[i+2];
|
59
|
-
buf_64[j++] = Ch64[b64.b.b0];
|
60
|
-
buf_64[j++] = Ch64[b64.b.b1];
|
61
|
-
buf_64[j++] = Ch64[b64.b.b2];
|
62
|
-
buf_64[j++] = Ch64[b64.b.b3];
|
63
|
-
i+=3;
|
64
|
-
}
|
65
|
-
|
66
|
-
if( k == 2 ) {
|
67
|
-
b64.a[2] = buf_ascii[i];
|
68
|
-
b64.a[1] = 0;
|
69
|
-
b64.a[0] = 0;
|
70
|
-
buf_64[j++] = Ch64[b64.b.b0];
|
71
|
-
buf_64[j++] = Ch64[b64.b.b1];
|
72
|
-
buf_64[j++] = '=';
|
73
|
-
buf_64[j++] = '=';
|
74
|
-
}
|
75
|
-
|
76
|
-
if( k == 1 ) {
|
77
|
-
b64.a[2] = buf_ascii[i];
|
78
|
-
b64.a[1] = buf_ascii[i+1];
|
79
|
-
b64.a[0] = 0;
|
80
|
-
buf_64[j++] = Ch64[b64.b.b0];
|
81
|
-
buf_64[j++] = Ch64[b64.b.b1];
|
82
|
-
buf_64[j++] = Ch64[b64.b.b2];
|
83
|
-
buf_64[j++] = '=';
|
84
|
-
}
|
85
|
-
|
86
|
-
return( j );
|
87
|
-
}
|
88
|
-
|
89
|
-
/* Restoring original characters */
|
90
|
-
if( job == ENCODE ) {
|
91
|
-
buf64_len = buf_64_size;
|
92
|
-
if( buf64_len < 4 ) return( CODE_ERR ); /* Too small input buffer */
|
93
|
-
if( (buf_64_size * 3 / 4) > ascii_size ) return( CODE_ERR ); /* No enough space to encoding */
|
94
|
-
i3 = buf64_len / 4;
|
95
|
-
k = buf64_len - i3 * 4;
|
96
|
-
if( k ) return( CODE_ERR ); /* Illegal size for input sequence !! */
|
97
|
-
k = 0; /* Counter original bytes for output */
|
98
|
-
|
99
|
-
for( i = 0; i < buf64_len; i+=4 ) {
|
100
|
-
b64.b.b0 = idx64( buf_64[i] );
|
101
|
-
b64.b.b1 = idx64( buf_64[i+1] );
|
102
|
-
b64.b.b2 = 0; b64.b.b3 = 0;
|
103
|
-
if( buf_64[i+2] != '=' ) b64.b.b2 = idx64( buf_64[i+2] );
|
104
|
-
else k--;
|
105
|
-
if( buf_64[i+3] != '=' ) b64.b.b3 = idx64( buf_64[i+3] );
|
106
|
-
else k--;
|
107
|
-
buf_ascii[j++] = b64.a[2]; k++;
|
108
|
-
buf_ascii[j++] = b64.a[1]; k++;
|
109
|
-
buf_ascii[j++] = b64.a[0]; k++;
|
110
|
-
}
|
111
|
-
|
112
|
-
return( k );
|
113
|
-
}
|
114
|
-
|
115
|
-
return( CODE_ERR ); /* Unknown command ! */
|
116
|
-
}
|
117
|
-
|
118
|
-
/* Binary search character's index in array */
|
119
|
-
int idx64( char ch )
|
120
|
-
{
|
121
|
-
int start = 0;
|
122
|
-
int pos = 32;
|
123
|
-
int end = 63;
|
124
|
-
|
125
|
-
while( (pos >= start) || (pos <= end) ) {
|
126
|
-
if( ch == Id64[start].Ch ) return( Id64[start].Id );
|
127
|
-
if( ch == Id64[pos].Ch ) return( Id64[pos].Id );
|
128
|
-
if( ch == Id64[end].Ch ) return( Id64[end].Id );
|
129
|
-
|
130
|
-
if( ch > Id64[pos].Ch ) {
|
131
|
-
start = pos;
|
132
|
-
}
|
133
|
-
|
134
|
-
if( ch < Id64[pos].Ch ) {
|
135
|
-
end = pos;
|
136
|
-
}
|
137
|
-
|
138
|
-
pos = (int) (start+end) / 2;
|
139
|
-
}
|
140
|
-
|
141
|
-
/* Illegal character found, task aborted ! */
|
142
|
-
fprintf( stderr, "\n\rBase64 Fatal Error: Illegal character found : '%c' [%d] - No Base64 legal character!!\n\r", ch, ch );
|
143
|
-
exit(1);
|
144
|
-
}
|
data/ext/wmsigner/base64.h
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
#include <stdio.h>
|
2
|
-
#include <stdlib.h>
|
3
|
-
#include <string.h>
|
4
|
-
|
5
|
-
#ifndef __BASE64_DEFINED___
|
6
|
-
#define __BASE64_DEFINED___
|
7
|
-
#endif /* __BASE64_DEFINED___ */
|
8
|
-
|
9
|
-
#define ENCODE 0
|
10
|
-
#define DECODE 1
|
11
|
-
|
12
|
-
#define CODE_ERR 0
|
13
|
-
|
14
|
-
#ifndef TRUE
|
15
|
-
#define TRUE 1
|
16
|
-
#endif
|
17
|
-
#ifndef FALSE
|
18
|
-
#define FALSE 0
|
19
|
-
#endif
|
20
|
-
|
21
|
-
#define MAXBUFFER 4096 // Don`t change this parameter !!!
|
22
|
-
#define READBYTES 3072 // Don`t change this parameter !!!
|
23
|
-
|
24
|
-
/* Bits BASE64 structure */
|
25
|
-
typedef struct __Bits64__ {
|
26
|
-
unsigned b3 : 6; /* 1 Base 64 character */
|
27
|
-
unsigned b2 : 6; /* 2 Base 64 character */
|
28
|
-
unsigned b1 : 6; /* 3 Base 64 character */
|
29
|
-
unsigned b0 : 6; /* 4 Base 64 character */
|
30
|
-
} BITS, *BITSPTR;
|
31
|
-
|
32
|
-
/* Union of Bits & Bytes */
|
33
|
-
typedef union __Base64__ {
|
34
|
-
char a[3]; /* Byte array in the case */
|
35
|
-
BITS b; /* Bits fields in the case */
|
36
|
-
} BASE64;
|
37
|
-
|
38
|
-
/* Base_64 index structure */
|
39
|
-
|
40
|
-
typedef struct __index64__ {
|
41
|
-
char Ch;
|
42
|
-
int Id;
|
43
|
-
} INDEX64, *INDEX64PTR;
|
44
|
-
|
45
|
-
/* Prototypes */
|
46
|
-
size_t code64( int job, char *buf_ascii, size_t ascii_size, char *buf_64, size_t buf_64_size );
|
47
|
-
int idx64( char ch );
|
48
|
-
|
data/ext/wmsigner/cmdbase.cpp
DELETED
@@ -1,417 +0,0 @@
|
|
1
|
-
#include "stdafx.h"
|
2
|
-
#include <stdio.h>
|
3
|
-
#include <stdlib.h>
|
4
|
-
//#include <io.h>
|
5
|
-
#include <string.h>
|
6
|
-
#include "ctype.h"
|
7
|
-
#include "cmdbase.h"
|
8
|
-
|
9
|
-
WORD SwitchIndian(WORD n1)
|
10
|
-
{
|
11
|
-
#ifndef LOWBYTEFIRST
|
12
|
-
WORD n2;
|
13
|
-
|
14
|
-
char* ps=(char*)&n1;
|
15
|
-
char* pd=(char*)&n2;
|
16
|
-
pd[1] = ps[0];
|
17
|
-
pd[0] = ps[1];
|
18
|
-
|
19
|
-
return n2;
|
20
|
-
#else
|
21
|
-
return n1;
|
22
|
-
#endif
|
23
|
-
}
|
24
|
-
|
25
|
-
DWORD SwitchIndian(DWORD n1)
|
26
|
-
{
|
27
|
-
#ifndef LOWBYTEFIRST
|
28
|
-
DWORD n2;
|
29
|
-
|
30
|
-
char* ps=(char*)&n1;
|
31
|
-
char* pd=(char*)&n2;
|
32
|
-
pd[3] = ps[0];
|
33
|
-
pd[2] = ps[1];
|
34
|
-
pd[1] = ps[2];
|
35
|
-
pd[0] = ps[3];
|
36
|
-
|
37
|
-
return n2;
|
38
|
-
#else
|
39
|
-
return n1;
|
40
|
-
#endif
|
41
|
-
}
|
42
|
-
|
43
|
-
szptr::szptr(const char *csz)
|
44
|
-
{
|
45
|
-
if (csz)
|
46
|
-
{
|
47
|
-
sz = new char[::strlen(csz)+4];
|
48
|
-
strcpy(sz, csz);
|
49
|
-
}
|
50
|
-
else
|
51
|
-
sz = NULL;
|
52
|
-
}
|
53
|
-
|
54
|
-
szptr::szptr(const szptr& cszptr)
|
55
|
-
{
|
56
|
-
if ((const char *)cszptr)
|
57
|
-
{
|
58
|
-
sz = new char[cszptr.strlen()+4];
|
59
|
-
sz = strcpy(sz, cszptr);
|
60
|
-
}
|
61
|
-
else
|
62
|
-
sz = (const char *)cszptr ? strcpy(new char[cszptr.strlen()+4], cszptr) : NULL;
|
63
|
-
}
|
64
|
-
|
65
|
-
szptr::~szptr()
|
66
|
-
{
|
67
|
-
if(sz) delete[] sz;
|
68
|
-
}
|
69
|
-
|
70
|
-
char* szptr::operator = (char *csz)
|
71
|
-
{
|
72
|
-
if(sz && csz)
|
73
|
-
{
|
74
|
-
if(!strcmp(csz,sz))
|
75
|
-
return sz;
|
76
|
-
}
|
77
|
-
|
78
|
-
char *szprev = sz;
|
79
|
-
if(csz)
|
80
|
-
{
|
81
|
-
sz = new char[::strlen(csz)+4];
|
82
|
-
sz = strcpy(sz, csz);
|
83
|
-
}
|
84
|
-
else
|
85
|
-
sz = NULL;
|
86
|
-
|
87
|
-
if(szprev)
|
88
|
-
delete[] szprev;
|
89
|
-
|
90
|
-
return sz;
|
91
|
-
}
|
92
|
-
|
93
|
-
szptr& szptr::operator = (const szptr& cszptr)
|
94
|
-
{
|
95
|
-
if(sz && cszptr.sz)
|
96
|
-
if(!strcmp(cszptr,sz))
|
97
|
-
return *this;
|
98
|
-
|
99
|
-
char *szprev = sz;
|
100
|
-
if(cszptr)
|
101
|
-
{
|
102
|
-
sz = new char[::strlen(cszptr)+4];
|
103
|
-
sz = strcpy(sz, cszptr);
|
104
|
-
}
|
105
|
-
else
|
106
|
-
sz = NULL;
|
107
|
-
if(szprev)
|
108
|
-
delete[] szprev;
|
109
|
-
return *this;
|
110
|
-
}
|
111
|
-
|
112
|
-
szptr& szptr::operator += (const szptr& cszptr)
|
113
|
-
{
|
114
|
-
if(!&cszptr) return *this;
|
115
|
-
if(!cszptr.strlen()) return *this;
|
116
|
-
|
117
|
-
char *szprev = sz;
|
118
|
-
sz = new char[strlen()+cszptr.strlen()+4];
|
119
|
-
if(szprev)
|
120
|
-
{
|
121
|
-
strcpy(sz, szprev);
|
122
|
-
delete[] szprev;
|
123
|
-
}
|
124
|
-
else
|
125
|
-
sz[0] = '\0';
|
126
|
-
|
127
|
-
strcat(sz, cszptr);
|
128
|
-
return *this;
|
129
|
-
}
|
130
|
-
|
131
|
-
szptr& szptr::TrimRight()
|
132
|
-
{
|
133
|
-
if (NULL== this->sz)
|
134
|
-
return *this;
|
135
|
-
char* lpsz = this->sz;
|
136
|
-
char* lpszLast = NULL;
|
137
|
-
|
138
|
-
while (*lpsz != '\0')
|
139
|
-
{
|
140
|
-
if (*lpsz == ' ')
|
141
|
-
{
|
142
|
-
if (lpszLast == NULL)
|
143
|
-
lpszLast = lpsz;
|
144
|
-
}
|
145
|
-
else
|
146
|
-
lpszLast = NULL;
|
147
|
-
lpsz = ((char*)lpsz)+1;
|
148
|
-
}
|
149
|
-
|
150
|
-
if (lpszLast != NULL)
|
151
|
-
{
|
152
|
-
*lpszLast = '\0';
|
153
|
-
}
|
154
|
-
return *this;
|
155
|
-
}
|
156
|
-
|
157
|
-
szptr& szptr::TrimLeft()
|
158
|
-
{
|
159
|
-
if (NULL== this->sz)
|
160
|
-
return *this;
|
161
|
-
char* lpsz = this->sz;
|
162
|
-
int nLen = (int)::strlen(sz);
|
163
|
-
while ((*lpsz==' '))
|
164
|
-
lpsz = ((char*)lpsz)+1;
|
165
|
-
|
166
|
-
if (lpsz != sz)
|
167
|
-
{
|
168
|
-
int nDataLength = (int)nLen - (int)(lpsz - sz);
|
169
|
-
memmove(sz, lpsz, (nDataLength+1)*sizeof(char));
|
170
|
-
}
|
171
|
-
return *this;
|
172
|
-
}
|
173
|
-
|
174
|
-
static char *dwordFromBuf(DWORD *wMember, char *szNextElemBufPtr)
|
175
|
-
{
|
176
|
-
*wMember = SwitchIndian(*((DWORD*)szNextElemBufPtr));
|
177
|
-
return (szNextElemBufPtr+sizeof(DWORD));
|
178
|
-
}
|
179
|
-
|
180
|
-
static char *wordFromBuf(WORD *wMember, char *szNextElemBufPtr)
|
181
|
-
{
|
182
|
-
*wMember = SwitchIndian(*((WORD*)szNextElemBufPtr));
|
183
|
-
return (szNextElemBufPtr+sizeof(WORD));
|
184
|
-
}
|
185
|
-
|
186
|
-
static char *dwordToBuf(char *szNextElemBufPtr, DWORD wMember)
|
187
|
-
{
|
188
|
-
*((DWORD*)szNextElemBufPtr) = wMember;
|
189
|
-
return (szNextElemBufPtr+sizeof(DWORD));
|
190
|
-
}
|
191
|
-
|
192
|
-
static char *wordToBuf(char *szNextElemBufPtr, WORD wMember)
|
193
|
-
{
|
194
|
-
*((WORD*)szNextElemBufPtr) = wMember;
|
195
|
-
return (szNextElemBufPtr+sizeof(WORD));
|
196
|
-
}
|
197
|
-
|
198
|
-
|
199
|
-
/**/
|
200
|
-
Keys::Keys()
|
201
|
-
:dwReserv(0)
|
202
|
-
{
|
203
|
-
memset(arwEKey, 0, (MAX_UNIT_PRECISION) * 2);
|
204
|
-
memset(arwNKey, 0, (MAX_UNIT_PRECISION) * 2);
|
205
|
-
wEKeyBase= wNKeyBase = 0;
|
206
|
-
}
|
207
|
-
|
208
|
-
Keys::Keys(const Keys& keysFrom)
|
209
|
-
{
|
210
|
-
dwReserv = keysFrom.dwReserv;
|
211
|
-
wEKeyBase= wNKeyBase = 0;
|
212
|
-
memcpy(arwEKey, keysFrom.arwEKey, (MAX_UNIT_PRECISION) * 2);
|
213
|
-
memcpy(arwNKey, keysFrom.arwEKey, (MAX_UNIT_PRECISION) * 2);
|
214
|
-
wEKeyBase = keysFrom.wEKeyBase;
|
215
|
-
wNKeyBase = keysFrom.wNKeyBase;
|
216
|
-
}
|
217
|
-
|
218
|
-
Keys& Keys::operator=(const Keys& keysFrom)
|
219
|
-
{
|
220
|
-
dwReserv = keysFrom.dwReserv;
|
221
|
-
memcpy(arwEKey, keysFrom.arwEKey, (MAX_UNIT_PRECISION) * 2);
|
222
|
-
memcpy(arwNKey, keysFrom.arwNKey, (MAX_UNIT_PRECISION) * 2);
|
223
|
-
wEKeyBase = keysFrom.wEKeyBase;
|
224
|
-
wNKeyBase = keysFrom.wNKeyBase;
|
225
|
-
return *this;
|
226
|
-
}
|
227
|
-
|
228
|
-
DWORD Keys::GetMembersSize()
|
229
|
-
{
|
230
|
-
return (
|
231
|
-
sizeof(dwReserv)
|
232
|
-
+ GetKeyBaseB(arwEKey)
|
233
|
-
+ GetKeyBaseB(arwNKey)
|
234
|
-
+ sizeof(wEKeyBase)
|
235
|
-
+ sizeof(wNKeyBase));
|
236
|
-
}
|
237
|
-
|
238
|
-
char *Keys::LoadMembers(char *BufPtr)
|
239
|
-
{
|
240
|
-
char *ptrNextMemb = dwordFromBuf(&dwReserv, BufPtr);
|
241
|
-
|
242
|
-
ptrNextMemb = wordFromBuf(&wEKeyBase, ptrNextMemb);
|
243
|
-
memcpy(arwEKey, ptrNextMemb, wEKeyBase);
|
244
|
-
for(WORD i=0;i<wEKeyBase/sizeof(arwEKey[0]);i++)
|
245
|
-
{ arwEKey[i] = SwitchIndian(arwEKey[i]); }
|
246
|
-
|
247
|
-
ptrNextMemb += wEKeyBase;
|
248
|
-
|
249
|
-
ptrNextMemb = wordFromBuf(&wNKeyBase, ptrNextMemb);
|
250
|
-
memcpy(arwNKey, ptrNextMemb, wNKeyBase);
|
251
|
-
for(unsigned int i=0;i<wNKeyBase/sizeof(arwNKey[0]);i++)
|
252
|
-
{ arwNKey[i] = SwitchIndian(arwNKey[i]); }
|
253
|
-
|
254
|
-
ptrNextMemb += wNKeyBase;
|
255
|
-
|
256
|
-
return ptrNextMemb;
|
257
|
-
}
|
258
|
-
|
259
|
-
char *Keys::SaveMembers(char *BufPtr)
|
260
|
-
{
|
261
|
-
char *ptrNextMemb = dwordToBuf(BufPtr, dwReserv);
|
262
|
-
|
263
|
-
wEKeyBase = GetKeyBaseB(arwEKey);
|
264
|
-
ptrNextMemb = wordToBuf(ptrNextMemb, wEKeyBase);
|
265
|
-
memcpy(ptrNextMemb, arwEKey, wEKeyBase);
|
266
|
-
ptrNextMemb += wEKeyBase;
|
267
|
-
|
268
|
-
wNKeyBase = GetKeyBaseB(arwNKey);
|
269
|
-
ptrNextMemb = wordToBuf(ptrNextMemb, wNKeyBase);
|
270
|
-
memcpy(ptrNextMemb, arwNKey, wNKeyBase);
|
271
|
-
ptrNextMemb += wNKeyBase;
|
272
|
-
|
273
|
-
return ptrNextMemb;
|
274
|
-
}
|
275
|
-
|
276
|
-
|
277
|
-
void Keys::RecalcBase()
|
278
|
-
{
|
279
|
-
wEKeyBase = GetKeyBaseB(arwEKey);
|
280
|
-
wNKeyBase = GetKeyBaseB(arwNKey);
|
281
|
-
}
|
282
|
-
|
283
|
-
int Keys::LoadFromBuffer(const char *Buf, DWORD dwBufLen)
|
284
|
-
{
|
285
|
-
if(dwBufLen < KeyFileFormat::sizeof_header)
|
286
|
-
return _CMDLOAD_ERR_BUF_LEN_;
|
287
|
-
|
288
|
-
KeyFileFormat *keyFmt = (KeyFileFormat *)Buf;
|
289
|
-
DWORD ardwRecievedCRC[4], ardwCheckedCRC[4], i;
|
290
|
-
|
291
|
-
if(dwBufLen-2*sizeof(DWORD) >= SwitchIndian(keyFmt->dwLenBuf))
|
292
|
-
{
|
293
|
-
for(i=0; i<4; i++)
|
294
|
-
ardwRecievedCRC[i] = SwitchIndian(keyFmt->dwCRC[i]);
|
295
|
-
for(i=0; i<4; i++) keyFmt->dwCRC[i] = 0;
|
296
|
-
CountCrcMD4(ardwCheckedCRC, Buf, SwitchIndian(keyFmt->dwLenBuf)+KeyFileFormat::sizeof_header);
|
297
|
-
|
298
|
-
for(i=0; i<4; i++) keyFmt->dwCRC[i] = SwitchIndian(ardwRecievedCRC[i]);
|
299
|
-
|
300
|
-
bool bCrcGood = true;
|
301
|
-
for(i=0; i<4; i++)
|
302
|
-
if(ardwCheckedCRC[i]!=ardwRecievedCRC[i])
|
303
|
-
{
|
304
|
-
bCrcGood = false;
|
305
|
-
break;
|
306
|
-
}
|
307
|
-
|
308
|
-
if(bCrcGood)
|
309
|
-
{
|
310
|
-
LoadMembers(keyFmt->ptrBuffer);
|
311
|
-
return 0;
|
312
|
-
}
|
313
|
-
else
|
314
|
-
return _CMDLOAD_ERR_CMD_CRC_;
|
315
|
-
}
|
316
|
-
else
|
317
|
-
return _CMDLOAD_ERR_BUF_LEN_;
|
318
|
-
}
|
319
|
-
|
320
|
-
int Keys::SaveIntoBuffer(char **ptrAllocBuf, DWORD *dwBufLen)
|
321
|
-
{
|
322
|
-
char *Buf;
|
323
|
-
KeyFileFormat *cmdFmt;
|
324
|
-
DWORD dwMembersSize;
|
325
|
-
DWORD dwBufSize, i;
|
326
|
-
BOOL bRC = false;
|
327
|
-
|
328
|
-
dwMembersSize = GetMembersSize();
|
329
|
-
|
330
|
-
dwBufSize = dwMembersSize+KeyFileFormat::sizeof_header;
|
331
|
-
Buf = new char[dwBufSize];
|
332
|
-
memset(Buf, 0, dwBufSize); // Clear for Trail...
|
333
|
-
cmdFmt = (KeyFileFormat *)Buf;
|
334
|
-
if(Buf)
|
335
|
-
{
|
336
|
-
char *BufMemb;
|
337
|
-
BufMemb = cmdFmt->ptrBuffer;
|
338
|
-
|
339
|
-
if(SaveMembers(BufMemb))
|
340
|
-
{
|
341
|
-
cmdFmt->wReserved1 = 0x81;
|
342
|
-
cmdFmt->wSignFlag = 0;
|
343
|
-
cmdFmt->dwLenBuf = dwMembersSize;
|
344
|
-
|
345
|
-
for(i=0; i<4; i++) cmdFmt->dwCRC[i] = 0;
|
346
|
-
CountCrcMD4(cmdFmt->dwCRC, Buf, dwBufSize); //*((WORD *)(Buf+sizeof(WORD)))=
|
347
|
-
*dwBufLen = dwBufSize;
|
348
|
-
*ptrAllocBuf = Buf;
|
349
|
-
bRC = true;
|
350
|
-
}
|
351
|
-
}
|
352
|
-
else
|
353
|
-
bRC = false; // NOT_ENOUGH_MEMORY
|
354
|
-
|
355
|
-
return bRC;
|
356
|
-
}
|
357
|
-
|
358
|
-
bool Keys::CountCrcMD4(DWORD *dwCRC, const char *Buf, DWORD dwBufLenBytes)
|
359
|
-
{
|
360
|
-
int b,bitcount;
|
361
|
-
MDstruct MD;
|
362
|
-
|
363
|
-
MDbegin(&MD);
|
364
|
-
for(b=0,bitcount=512; (unsigned int)b<dwBufLenBytes/64+1; b++)
|
365
|
-
{
|
366
|
-
if((unsigned int)b==dwBufLenBytes/64) bitcount = (dwBufLenBytes%64)<<3;
|
367
|
-
MDupdate(&MD, (unsigned char *)(Buf+b*64), bitcount);
|
368
|
-
}
|
369
|
-
MDupdate(&MD, (unsigned char *)Buf, 0);
|
370
|
-
|
371
|
-
for(b=0; b<4; b++) dwCRC[b] = MD.buffer[b];
|
372
|
-
|
373
|
-
return true;
|
374
|
-
}
|
375
|
-
|
376
|
-
bool us2sz(const unsigned short *buf, int len, char *szBuffer)
|
377
|
-
{
|
378
|
-
char tmp[5];
|
379
|
-
szBuffer[0] = '\0';
|
380
|
-
|
381
|
-
for(int i=0;i<len;i++)
|
382
|
-
{
|
383
|
-
sprintf(tmp, "%04x", buf[i]);
|
384
|
-
strcat(szBuffer, tmp);
|
385
|
-
}
|
386
|
-
return true;
|
387
|
-
}
|
388
|
-
|
389
|
-
char stohb(char s)
|
390
|
-
{
|
391
|
-
if ( s>='0' && s<='9') return (s-'0');
|
392
|
-
else
|
393
|
-
if ( s>='A' && s<='F') return (s-'A'+0xA);
|
394
|
-
else
|
395
|
-
if ( s>='a' && s<='f') return (s-'a'+0xA);
|
396
|
-
return 0;
|
397
|
-
}
|
398
|
-
|
399
|
-
bool sz2us(const char *szBuffer, unsigned short *usBuf)
|
400
|
-
{
|
401
|
-
const char* p = szBuffer;
|
402
|
-
int l = (int)strlen(szBuffer);
|
403
|
-
unsigned short cell = 0;
|
404
|
-
for(int i=0,k=0; i<l; i+=4) {
|
405
|
-
cell = 0;
|
406
|
-
cell = stohb(*p++);
|
407
|
-
cell <<= 4;
|
408
|
-
cell |= stohb(*p++);
|
409
|
-
cell <<= 4;
|
410
|
-
cell |= stohb(*p++);
|
411
|
-
cell <<= 4;
|
412
|
-
cell |= stohb(*p++);
|
413
|
-
usBuf[k++] = cell;
|
414
|
-
}
|
415
|
-
return true;
|
416
|
-
}
|
417
|
-
//----
|