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.
@@ -1,81 +0,0 @@
1
- #ifndef __RSALIB1_H_INCLUDE__
2
- #define __RSALIB1_H_INCLUDE__
3
- #include "stdafx.h"
4
-
5
- typedef unsigned char boolean;
6
- typedef unsigned char byte;
7
- typedef unsigned short word16;
8
- typedef word16 unit;
9
- typedef unit *unitptr;
10
- typedef short signedunit;
11
- typedef unsigned long int ulint;
12
-
13
- class CRSALib
14
- {
15
- public:
16
-
17
- enum { MAX_BIT_PRECISION = 2048, MAX_UNIT_PRECISION = MAX_BIT_PRECISION/(sizeof(word16)*8) };
18
- private:
19
- unit moduli_buf[16][(MAX_UNIT_PRECISION)];
20
- unitptr moduli[16+1];
21
-
22
- unit msu_moduli[16+1];
23
- unit nmsu_moduli[16+1];
24
- unit mpdbuf[16-1][(MAX_UNIT_PRECISION)];
25
- unitptr mpd[16];
26
-
27
- public:
28
- short global_precision;
29
- void set_precision(short prec);
30
- CRSALib(short glob_pres=0);
31
-
32
- boolean mp_addc(register unitptr r1,register unitptr r2,register boolean carry);
33
-
34
- boolean mp_subb(register unitptr r1,register unitptr r2,register boolean borrow);
35
- boolean mp_rotate_left(register unitptr r1,register boolean carry);
36
- boolean mp_rotate_right(register unitptr r1,register boolean carry);
37
- short mp_compare(register unitptr r1,register unitptr r2);
38
- boolean mp_inc(register unitptr r);
39
- boolean mp_dec(register unitptr r);
40
- void mp_neg(register unitptr r);
41
- void mp_move(register unitptr dst,register unitptr src);
42
- void mp_init(register unitptr r, word16 value);
43
- short significance(register unitptr r);
44
- void unitfill0(unitptr r,word16 unitcount);
45
- int mp_udiv(register unitptr remainder,register unitptr quotient,
46
- register unitptr dividend,register unitptr divisor);
47
- int mp_div(register unitptr remainder,register unitptr quotient,
48
- register unitptr dividend,register unitptr divisor);
49
- word16 mp_shortdiv(register unitptr quotient,
50
- register unitptr dividend,register word16 divisor);
51
- int mp_mod(register unitptr remainder,
52
- register unitptr dividend,register unitptr divisor);
53
- word16 mp_shortmod(register unitptr dividend,register word16 divisor);
54
- int mp_mult(register unitptr prod,
55
- register unitptr multiplicand,register unitptr multiplier);
56
-
57
- private:
58
- void mp_lshift_unit(register unitptr r1);
59
- void stage_mp_images(unitptr images[16],unitptr r);
60
-
61
- public:
62
- int stage_merritt_modulus(unitptr n);
63
- int merritt_modmult(register unitptr prod,
64
- unitptr multiplicand,register unitptr multiplier);
65
-
66
- private:
67
- void merritt_burn(void);
68
-
69
- public:
70
- int countbits(unitptr r);
71
-
72
- int mp_modexp(register unitptr expout,register unitptr expin,
73
- register unitptr exponent,register unitptr modulus);
74
-
75
- int rsa_decrypt(unitptr M, unitptr C, unitptr d, unitptr p, unitptr q, unitptr u);
76
- int mp_sqrt(unitptr quotient,unitptr dividend);
77
- };
78
-
79
- inline void CRSALib::set_precision(short prec) {global_precision = prec;}
80
- #endif
81
- //---
@@ -1,309 +0,0 @@
1
- #include "stdafx.h"
2
- #include <stdio.h>
3
- #include <fcntl.h>
4
- #include <stdlib.h>
5
- #include <time.h>
6
- #include "signer.h"
7
-
8
- #ifdef _WIN32
9
- #include <io.h>
10
- #include <sys/types.h>
11
- #include <sys/stat.h>
12
- #include <errno.h>
13
- #else
14
- #include <sys/types.h>
15
- #include <sys/stat.h>
16
- #include <sys/uio.h>
17
- #include <unistd.h>
18
- #include <errno.h>
19
- #endif
20
-
21
- #ifndef TRUE
22
- #define TRUE 1
23
- #endif
24
- #ifndef FALSE
25
- #define FALSE 0
26
- #endif
27
-
28
- bool Signer::SecureKeyByIDPW(char *buf, DWORD dwBuf)
29
- {
30
- if(((KeyFileFormat *)buf)->wSignFlag == 0)
31
- {
32
- m_siErrorCode = -2;
33
- return false;
34
- };
35
- DWORD dwCRC[4];
36
- szptr szIDPW = m_szUserName;
37
- szIDPW += m_szPassword;
38
- Keys::CountCrcMD4(dwCRC, szIDPW, szIDPW.strlen());
39
-
40
- dwCRC[0] = SwitchIndian(dwCRC[0]);
41
- dwCRC[1] = SwitchIndian(dwCRC[1]);
42
- dwCRC[2] = SwitchIndian(dwCRC[2]);
43
- dwCRC[3] = SwitchIndian(dwCRC[3]);
44
-
45
- char *ptrKey = ((KeyFileFormat *)buf)->ptrBuffer;
46
- DWORD dwKeyLen = dwBuf-(ptrKey-buf) - 6;
47
- ptrKey += 6;
48
- for(DWORD dwProc=0; dwProc<dwKeyLen; dwProc+=sizeof(dwCRC))
49
- for(int k=0; k<sizeof(dwCRC)&&(dwProc+k)<dwKeyLen; k++)
50
- *(ptrKey+dwProc+k) ^= ((char *)dwCRC)[k];
51
- return true;
52
- }
53
-
54
-
55
- bool Signer::SecureKeyByIDPWHalf(char *buf, DWORD dwBuf)
56
- {
57
- if(((KeyFileFormat *)buf)->wSignFlag == 0)
58
- {
59
- m_siErrorCode = -2;
60
- return false;
61
- };
62
- DWORD dwCRC[4];
63
- szptr szIDPW = m_szUserName;
64
- int len = (int) strlen(m_szPassword)/2 + 1;
65
- if (len > 1)
66
- {
67
- char* pBuf = new char[len];
68
- strncpy(pBuf, m_szPassword, len-1);
69
- pBuf[len-1] = '\0';
70
- szIDPW += pBuf;
71
-
72
- delete [] pBuf;
73
- }
74
- Keys::CountCrcMD4(dwCRC, szIDPW, szIDPW.strlen());
75
-
76
- dwCRC[0] = SwitchIndian(dwCRC[0]);
77
- dwCRC[1] = SwitchIndian(dwCRC[1]);
78
- dwCRC[2] = SwitchIndian(dwCRC[2]);
79
- dwCRC[3] = SwitchIndian(dwCRC[3]);
80
-
81
- char *ptrKey = ((KeyFileFormat *)buf)->ptrBuffer;
82
- DWORD dwKeyLen = dwBuf-(ptrKey-buf) - 6;
83
- ptrKey += 6;
84
- for(DWORD dwProc=0; dwProc<dwKeyLen; dwProc+=sizeof(dwCRC))
85
- for(int k=0; k<sizeof(dwCRC)&&(dwProc+k)<dwKeyLen; k++)
86
- *(ptrKey+dwProc+k) ^= ((char *)dwCRC)[k];
87
- return true;
88
- }
89
- //---------------------------------------------------------
90
- void Signer::SetKeyFromCL( int flag, char *KeyBuf )
91
- {
92
- KeyFromCL = FALSE;
93
- if( flag == TRUE ) KeyFromCL = TRUE;
94
- memcpy( (void *) szKeyData, (const void *)KeyBuf, 164 );
95
- }
96
- //---------------------------------------------------------
97
-
98
- int Signer::LoadKeys()
99
- {
100
- bool bKeysReaded = false, bNotOldFmt = false;
101
- int nReaden;
102
- int errLoadKey;
103
- int fh = -1;
104
- int st_size = 0;
105
- const int nMaxBufLen = sizeof(Keys) + KeyFileFormat::sizeof_header;
106
- char *pBufRead = new char[nMaxBufLen]; // Here Keys must be
107
- m_siErrorCode = 0;
108
- KeyFromCL = FALSE;
109
-
110
- if( (!isIgnoreKeyFile) && (Key64Flag == FALSE) ) {
111
- #ifdef O_BINARY
112
- fh = open( m_szKeyFileName, O_RDONLY | O_BINARY);
113
- #else
114
- fh = open( m_szKeyFileName, O_RDONLY);
115
- #endif
116
-
117
- if( fh == -1 )
118
- {
119
- m_siErrorCode = errno;
120
- return false;
121
- }
122
-
123
- st_size = lseek(fh, 0, SEEK_END);
124
- lseek(fh, 0, SEEK_SET);
125
- if (st_size == lMinKeyFileSize)
126
- {
127
- // load 164 bytes from "small" keys file
128
- nReaden = read( fh, pBufRead, nMaxBufLen );
129
- bKeysReaded = (nReaden == lMinKeyFileSize);
130
- }
131
- close( fh );
132
- }
133
- else {
134
- bKeysReaded = true;
135
- nReaden = lMinKeyFileSize;
136
- memcpy( pBufRead, szKeyData, lMinKeyFileSize);
137
- }
138
-
139
- //*************************************************************************
140
-
141
- if(bKeysReaded)
142
- {
143
- SecureKeyByIDPWHalf(pBufRead, lMinKeyFileSize);
144
- WORD old_SignFlag;
145
- old_SignFlag = ((KeyFileFormat *)pBufRead)->wSignFlag;
146
- ((KeyFileFormat *)pBufRead)->wSignFlag = 0;
147
- errLoadKey = keys.LoadFromBuffer( pBufRead, lMinKeyFileSize );
148
- if(errLoadKey)
149
- {
150
- // Restore for correct Loading (CRC) !
151
- ((KeyFileFormat *)pBufRead)->wSignFlag = old_SignFlag;
152
- SecureKeyByIDPWHalf(pBufRead, lMinKeyFileSize); // restore buffer
153
-
154
- SecureKeyByIDPW(pBufRead, lMinKeyFileSize);
155
-
156
- ((KeyFileFormat *)pBufRead)->wSignFlag = 0;
157
- errLoadKey = keys.LoadFromBuffer( pBufRead, lMinKeyFileSize );
158
- }
159
-
160
- delete[] pBufRead;
161
- if( !errLoadKey )
162
- bKeysReaded = true;
163
- else
164
- {
165
- Keys flushKey;
166
- keys = flushKey;
167
- m_siErrorCode = -3;
168
- }
169
- }
170
-
171
- return bKeysReaded;
172
- }
173
-
174
- Signer::Signer(const char * szLogin, const char *szPassword, const char *szKeyFileName)
175
- : m_szUserName(szLogin), m_szPassword(szPassword), m_szKeyFileName(szKeyFileName)
176
- {
177
- m_siErrorCode = 0;
178
- isIgnoreKeyFile = false;
179
- isIgnoreIniFile = false;
180
- isKWMFileFromCL = false;
181
- memset(szKeyData, 0, MAXBUF+1);
182
- Key64Flag = FALSE;
183
- }
184
-
185
- short Signer::ErrorCode()
186
- {
187
- return m_siErrorCode;
188
- }
189
-
190
- bool Signer::Sign(const char *szIn, szptr& szSign)
191
- {
192
- DWORD dwCRC[14];
193
- #ifdef _DEBUG
194
- printf("\n\rSign - Start !");
195
- #endif
196
-
197
- if (!LoadKeys())
198
- {
199
- puts("!LoadKeys");
200
- return false;
201
- }
202
- #ifdef _DEBUG
203
- printf("\n\rSign - Load Keys");
204
- #endif
205
-
206
- if(!keys.wEKeyBase || !keys.wNKeyBase)
207
- return false;
208
-
209
- #ifdef _DEBUG
210
- char *szInHex = new char [(strlen(szIn)+1)*2+1];
211
- us2sz((const unsigned short *)szIn, (int)(strlen(szIn)+1)/2, szInHex);
212
- puts("\n\rInput:\n");
213
- puts(szIn);
214
- puts("\nin hex:\n");
215
- puts(szInHex);
216
- puts("\n");
217
- delete [] szInHex;
218
- #endif
219
-
220
- if(Keys::CountCrcMD4(dwCRC, szIn, (DWORD)strlen(szIn)))
221
- {
222
- DWORD dwCrpSize = GetCLenB(sizeof(dwCRC), keys.arwNKey);
223
- char *ptrCrpBlock = new char[dwCrpSize];
224
- #ifdef _DEBUG
225
- for(int i=4; i<14; i++) dwCRC[i] = 0;
226
- #else
227
- srand((unsigned)time(NULL));
228
- for(int i=4; i<14; i++) dwCRC[i] = rand();
229
- #endif
230
- dwCRC[0] = SwitchIndian(dwCRC[0]);
231
- dwCRC[1] = SwitchIndian(dwCRC[1]);
232
- dwCRC[2] = SwitchIndian(dwCRC[2]);
233
- dwCRC[3] = SwitchIndian(dwCRC[3]);
234
- #ifdef _DEBUG
235
- for(int h=0;h<sizeof(dwCRC);h++)
236
- { printf("packing%d: %x\n", h, ((char*)dwCRC)[h]); }
237
- #endif
238
- #ifdef _DEBUG
239
- printf("\n\rCalling CrpB() - start");
240
- #endif
241
- CrpB(ptrCrpBlock, (char *)dwCRC, sizeof(dwCRC), keys.arwEKey, keys.arwNKey);
242
- #ifdef _DEBUG
243
- printf("\n\rCalling CrpB() - end");
244
- #endif
245
- char *charCrpBlock = new char[dwCrpSize*2+1];
246
- us2sz((const unsigned short *)ptrCrpBlock, dwCrpSize/2, charCrpBlock);
247
- szSign = charCrpBlock;
248
- #ifdef _DEBUG
249
- printf("\n\rSign - prepare end");
250
- #endif
251
-
252
- delete [] charCrpBlock;
253
- delete [] ptrCrpBlock;
254
-
255
- #ifdef _DEBUG
256
- printf("\n\rSign - end return true");
257
- #endif
258
-
259
- return true;
260
- }
261
-
262
- #ifdef _DEBUG
263
- printf("\n\rSign - end return false");
264
- #endif
265
- return false;
266
- }
267
-
268
- Signer2::Signer2(const char *szLogin, const char *szPassword, const char *szKeyData)
269
- :Signer(szLogin, szPassword, ""), m_strKeyData(szKeyData)
270
- {
271
- m_siErrorCode = 0;
272
- }
273
-
274
- int Signer2::LoadKeys()
275
- {
276
- bool bKeysReaded = false, bNotOldFmt = false;
277
- int errLoadKey;
278
-
279
- int nStrKeyDataLen = m_strKeyData.strlen();
280
- const int nMaxBufLen = sizeof(Keys) + KeyFileFormat::sizeof_header;
281
- if ((nStrKeyDataLen>0) && (nStrKeyDataLen < nMaxBufLen*2))
282
- {
283
- BYTE *bKeyData = new BYTE[nMaxBufLen];
284
- sz2us(m_strKeyData, (unsigned short*)bKeyData);
285
- SecureKeyByIDPW((char*)bKeyData, nStrKeyDataLen / 2);
286
- ((KeyFileFormat *)bKeyData)->wSignFlag = 0;
287
- errLoadKey = keys.LoadFromBuffer((char*)bKeyData, nStrKeyDataLen / 2);
288
- delete bKeyData;
289
- if( !errLoadKey )
290
- bKeysReaded = true;
291
- else {
292
- Keys flushKey;
293
- keys = flushKey;
294
- m_siErrorCode = -2;
295
- }
296
- }
297
- else
298
- {
299
- errLoadKey = -1;
300
- m_siErrorCode = -1;
301
- }
302
- return (bKeysReaded);
303
- }
304
-
305
- short Signer2::ErrorCode()
306
- {
307
- return m_siErrorCode;
308
- }
309
- //----
@@ -1,63 +0,0 @@
1
- #ifndef __SIGNER_H_INCLUDE__
2
- #define __SIGNER_H_INCLUDE__
3
- #include "stdafx.h"
4
- #include "cmdbase.h"
5
-
6
- #define MAXBUF 4096
7
-
8
- const long lMinKeyFileSize = 164;//smallest size of the keysfaile
9
- const long lKiloByte = 1024;//1 kilobyte in bytes
10
- const long lMegaByte = lKiloByte*lKiloByte;//1 megabyte in bytes
11
- const long lScrollZoom = 100;
12
- const long lMaxKeyFileSize = 10*lMegaByte;//10 Mb in this version
13
- const szptr szOptionKeyFileSize = "KeyFileSize";
14
- const unsigned int uiKWNHeaderOffset = 2;
15
- const unsigned int uiKWNHeaderSize = uiKWNHeaderOffset + lMinKeyFileSize;
16
- const unsigned int uiBlockSizeOffset = 1;
17
-
18
- class Signer
19
- {
20
-
21
- public:
22
- bool isIgnoreKeyFile;
23
- bool isIgnoreIniFile;
24
- bool isKWMFileFromCL;
25
- char szKeyData[MAXBUF+1]; /* Buffer for Signre-s key */
26
- int Key64Flag;
27
-
28
- protected:
29
- szptr m_szUserName;
30
- szptr m_szPassword;
31
- szptr m_szKeyFileName;
32
- short m_siErrorCode;
33
- Keys keys;
34
- bool SecureKeyByIDPW(char *buf, DWORD dwBuf);
35
- bool SecureKeyByIDPWHalf(char *buf, DWORD dwBuf);
36
- int virtual LoadKeys();
37
-
38
- public:
39
- Signer(const char *szLogin, const char *szPassword, const char *szKeyFileName);
40
- bool Sign(const char *szIn, szptr& szSign);
41
- short ErrorCode();
42
- //-------------------------------------------------
43
- public:
44
- int KeyFromCL;
45
- char KeyBuffer[164];
46
- void SetKeyFromCL( int flag, char *KeyBuf );
47
- //-------------------------------------------------
48
- };
49
-
50
- class Signer2: public Signer
51
- {
52
- protected:
53
- szptr m_strKeyData;
54
- short m_siErrorCode;
55
- int virtual LoadKeys();
56
-
57
- public:
58
- Signer2(const char *szLogin, const char *szPassword, const char *szKeyData);
59
- short ErrorCode();
60
- };
61
-
62
- #endif
63
- //-----