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/cmdbase.h
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
#ifndef __CMDBASE_INCLUDE__
|
2
|
-
#define __CMDBASE_INCLUDE__
|
3
|
-
#include "stdafx.h"
|
4
|
-
#include "crypto.h"
|
5
|
-
#include "md4.h"
|
6
|
-
#include <stdio.h>
|
7
|
-
#include "string.h"
|
8
|
-
//--------------------
|
9
|
-
|
10
|
-
#ifndef _WIN32
|
11
|
-
#define _NOT_WIN32
|
12
|
-
#endif
|
13
|
-
|
14
|
-
#if defined(__FreeBSD__) && __FreeBSD__ < 5 /* for FreeBSD version <= 4 */
|
15
|
-
#include <inttypes.h>
|
16
|
-
#elif defined(_NOT_WIN32)
|
17
|
-
#include <stdint.h>
|
18
|
-
#endif
|
19
|
-
|
20
|
-
#ifndef _WIN32
|
21
|
-
typedef uint32_t DWORD;
|
22
|
-
typedef bool BOOL;
|
23
|
-
typedef uint8_t BYTE;
|
24
|
-
typedef uint16_t WORD;
|
25
|
-
#endif
|
26
|
-
|
27
|
-
|
28
|
-
//--------------------
|
29
|
-
#define LOWBYTEFIRST
|
30
|
-
#define EBITS (48)
|
31
|
-
#define KEYBITS (528)
|
32
|
-
|
33
|
-
#define MAX_BIT_PRECISION (2048)
|
34
|
-
#define MAX_UNIT_PRECISION (MAX_BIT_PRECISION/(sizeof(unsigned short)*8))
|
35
|
-
|
36
|
-
#define _CMDLOAD_ERR_CMD_CRIPTION_ 1
|
37
|
-
#define _CMDLOAD_ERR_CMD_CRC_ 2
|
38
|
-
#define _CMDLOAD_ERR_BUF_LEN_ 3
|
39
|
-
#define _CMDLOAD_ERR_CMD_DECODE_ 4
|
40
|
-
#define _CMDLOAD_ERR_CMD_CODE_ 5
|
41
|
-
#define _CMDLOAD_ERR_NULL_KEY_ 6
|
42
|
-
|
43
|
-
class szptr
|
44
|
-
{
|
45
|
-
char *sz;
|
46
|
-
|
47
|
-
public:
|
48
|
-
szptr() { sz = NULL; }
|
49
|
-
szptr(const char *csz);
|
50
|
-
szptr(const szptr& cszptr);
|
51
|
-
~szptr();
|
52
|
-
|
53
|
-
char* operator = (char *csz);
|
54
|
-
szptr& operator = (const szptr& cszptr);
|
55
|
-
szptr& operator += (const szptr& cszptr);
|
56
|
-
inline void ReplaceIncluding(char *szp) { if(sz) delete sz; sz = szp; }
|
57
|
-
inline char operator*() { return sz ? *sz : '\0'; }
|
58
|
-
inline char operator[](int i) const { return sz ? *(sz+i) : '\0'; }
|
59
|
-
inline operator char const * const () const { return sz; }
|
60
|
-
int strlen() const {
|
61
|
-
if (sz) return (int)::strlen(sz);
|
62
|
-
else return 0;
|
63
|
-
}
|
64
|
-
inline bool operator==(const szptr& s) const { return (sz && s.sz) ? (strcmp(s.sz,sz)==0) : (sz == s.sz); }
|
65
|
-
inline bool operator!=(const szptr& s) const { return (sz && s.sz) ? (strcmp(s.sz,sz)!=0) : (sz != s.sz); }
|
66
|
-
|
67
|
-
szptr& TrimLeft();
|
68
|
-
szptr& TrimRight();
|
69
|
-
};
|
70
|
-
|
71
|
-
|
72
|
-
WORD SwitchIndian(WORD n1);
|
73
|
-
DWORD SwitchIndian(DWORD n1);
|
74
|
-
|
75
|
-
struct KeyFileFormat
|
76
|
-
{
|
77
|
-
enum {sizeof_header = sizeof(WORD)*2 + sizeof(DWORD)*5, sizeof_crc = (sizeof(DWORD)*4)};
|
78
|
-
WORD wReserved1;
|
79
|
-
WORD wSignFlag;
|
80
|
-
DWORD dwCRC[4];
|
81
|
-
DWORD dwLenBuf;
|
82
|
-
char ptrBuffer[1];
|
83
|
-
};
|
84
|
-
|
85
|
-
struct Keys
|
86
|
-
{
|
87
|
-
DWORD dwReserv;
|
88
|
-
WORD arwEKey[MAX_UNIT_PRECISION];
|
89
|
-
WORD arwNKey[MAX_UNIT_PRECISION];
|
90
|
-
WORD wEKeyBase;
|
91
|
-
WORD wNKeyBase;
|
92
|
-
|
93
|
-
Keys();
|
94
|
-
Keys(const Keys& keysFrom);
|
95
|
-
Keys& operator=(const Keys& KeysFrom);
|
96
|
-
virtual DWORD GetMembersSize();
|
97
|
-
virtual char* LoadMembers(char *BufPtr);
|
98
|
-
virtual int LoadFromBuffer(const char *Buf, DWORD dwBufLen);
|
99
|
-
virtual char* SaveMembers(char *BufPtr);
|
100
|
-
virtual int SaveIntoBuffer(char **ptrAllocBuf, DWORD *dwBufLen);
|
101
|
-
|
102
|
-
static bool CountCrcMD4(DWORD *dwCRC, const char *Buf, DWORD dwBufLenBytes);
|
103
|
-
void RecalcBase();
|
104
|
-
};
|
105
|
-
|
106
|
-
|
107
|
-
bool us2sz(const unsigned short *buf, int len, char *szBuffer);
|
108
|
-
char stohb(char s);
|
109
|
-
bool sz2us(const char *szBuffer, unsigned short *usBuf);
|
110
|
-
#endif
|
111
|
-
//---
|
data/ext/wmsigner/crypto.cpp
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
#include "stdafx.h"
|
2
|
-
#include <stdio.h>
|
3
|
-
#include <stdlib.h>
|
4
|
-
#include "crypto.h"
|
5
|
-
#include "rsalib1.h"
|
6
|
-
#include <memory.h>
|
7
|
-
|
8
|
-
|
9
|
-
unsigned short SwitchIndian(unsigned short n1);
|
10
|
-
|
11
|
-
unsigned int GetCLenB(int len, const unsigned short *n, short KeyBits)
|
12
|
-
{
|
13
|
-
CRSALib rsalib((KeyBits + 15)>> 4);
|
14
|
-
rsalib.set_precision((KeyBits + 15) >> 4);
|
15
|
-
int blocksize = rsalib.significance((unsigned short *)n);
|
16
|
-
int workblocksize = blocksize-1;
|
17
|
-
int len_and_sizeW = (len+sizeof(short)+1) >> 1;
|
18
|
-
int hvost = (len_and_sizeW)%workblocksize;
|
19
|
-
if (hvost) hvost = 1;
|
20
|
-
int newLen = (((len_and_sizeW) / (workblocksize)) + hvost) * blocksize;
|
21
|
-
return (newLen*2);
|
22
|
-
}
|
23
|
-
|
24
|
-
unsigned int CrpB(char* crp, char* p, int len, const unsigned short * e, const unsigned short *n, short KeyBits)
|
25
|
-
{
|
26
|
-
|
27
|
-
CRSALib rsalib((KeyBits + 15)>> 4);
|
28
|
-
rsalib.set_precision((KeyBits + 15) >> 4);
|
29
|
-
int blocksize = rsalib.significance((unsigned short *)n)*2;
|
30
|
-
int workblocksize = blocksize-2;
|
31
|
-
int ostb = 2;
|
32
|
-
int i=0, stP=0, endP=0, stC=0;
|
33
|
-
char pb[CRSALib::MAX_UNIT_PRECISION*2], cb[CRSALib::MAX_UNIT_PRECISION*2];
|
34
|
-
char *buf = (char *)malloc(len+ostb);
|
35
|
-
memcpy(buf+sizeof(short), p, len);
|
36
|
-
*(short*)buf = SwitchIndian((short)len);
|
37
|
-
int iLen = len+sizeof(short);
|
38
|
-
stP = 0;
|
39
|
-
stC = 0;
|
40
|
-
int res = 0, res1 = 0;
|
41
|
-
|
42
|
-
do
|
43
|
-
{
|
44
|
-
memset(cb, 0, CRSALib::MAX_UNIT_PRECISION*2);
|
45
|
-
memset(pb, 0, CRSALib::MAX_UNIT_PRECISION*2);
|
46
|
-
|
47
|
-
endP = ((workblocksize < iLen) ? workblocksize : iLen);
|
48
|
-
memcpy(pb, buf+stP, endP);
|
49
|
-
for(int h=0;h<endP/2;h++)
|
50
|
-
{
|
51
|
-
((unsigned short*)pb)[h] = SwitchIndian(((unsigned short*)pb)[h]);
|
52
|
-
}
|
53
|
-
#ifdef _DEBUG
|
54
|
-
for(int h=0;h<endP/2;h++)
|
55
|
-
{
|
56
|
-
printf("X:%d ", ((unsigned short*)pb)[h]);
|
57
|
-
}
|
58
|
-
#endif
|
59
|
-
|
60
|
-
if ((res = rsalib.mp_modexp((unsigned short*)cb, (unsigned short*)pb, (unsigned short *)e, (unsigned short *)n)) != 0)
|
61
|
-
{
|
62
|
-
res1 = res;
|
63
|
-
}
|
64
|
-
|
65
|
-
memcpy(crp+stC, cb, blocksize);
|
66
|
-
|
67
|
-
stP += endP;
|
68
|
-
stC += blocksize;
|
69
|
-
iLen -= (workblocksize);
|
70
|
-
} while (iLen > 0);
|
71
|
-
|
72
|
-
free(buf);
|
73
|
-
|
74
|
-
return GetCLenB(len, n);
|
75
|
-
}
|
76
|
-
|
77
|
-
unsigned int DCrpB(char* dcrp, int* dlen, char* c, int len, const unsigned short * d, const unsigned short *n, short KeyBits)
|
78
|
-
{
|
79
|
-
CRSALib rsalib((KeyBits + 15)>> 4);
|
80
|
-
rsalib.set_precision((KeyBits + 15) >> 4);
|
81
|
-
int blocksize = rsalib.significance((unsigned short *)n)*2;
|
82
|
-
if (0==blocksize)
|
83
|
-
{
|
84
|
-
*dlen = 0;
|
85
|
-
return 0;
|
86
|
-
}
|
87
|
-
if (len < blocksize)
|
88
|
-
{
|
89
|
-
*dlen = 0;
|
90
|
-
return 0;
|
91
|
-
}
|
92
|
-
int workblocksize = blocksize-2;
|
93
|
-
int rcLen = 0, iLen = len;
|
94
|
-
int stP = 0, stC = 0;
|
95
|
-
|
96
|
-
char *buf = (char *)malloc(len);
|
97
|
-
memset(buf, 0, len);
|
98
|
-
|
99
|
-
char pb[CRSALib::MAX_UNIT_PRECISION*2], cb[CRSALib::MAX_UNIT_PRECISION*2];
|
100
|
-
|
101
|
-
int res = 0, res1 = 0;
|
102
|
-
do
|
103
|
-
{
|
104
|
-
memset(cb, 0, CRSALib::MAX_UNIT_PRECISION*2);
|
105
|
-
memset(pb, 0, CRSALib::MAX_UNIT_PRECISION*2);
|
106
|
-
|
107
|
-
memcpy(cb, c+stC, blocksize);
|
108
|
-
|
109
|
-
if ((res = rsalib.mp_modexp((unsigned short*)pb, (unsigned short*)cb, (unsigned short *)d, (unsigned short *)n))!=0)
|
110
|
-
{
|
111
|
-
res1 = res;
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
|
116
|
-
memcpy(buf+stP, pb, workblocksize);
|
117
|
-
|
118
|
-
stC += blocksize;
|
119
|
-
stP += workblocksize;
|
120
|
-
iLen -= blocksize;
|
121
|
-
} while ((iLen > 0)&&(iLen >= blocksize));
|
122
|
-
|
123
|
-
rcLen = *(unsigned short*)buf;
|
124
|
-
|
125
|
-
if (len >= rcLen)
|
126
|
-
{
|
127
|
-
*dlen = rcLen;
|
128
|
-
memcpy(dcrp, buf+sizeof(short), rcLen);
|
129
|
-
}
|
130
|
-
else
|
131
|
-
{
|
132
|
-
rcLen = 0;
|
133
|
-
}
|
134
|
-
free(buf);
|
135
|
-
return rcLen;
|
136
|
-
}
|
137
|
-
|
138
|
-
unsigned int GetKeyBase(const unsigned short *n)
|
139
|
-
{
|
140
|
-
if(!n) return 0;
|
141
|
-
CRSALib rsalib(CRSALib::MAX_UNIT_PRECISION);
|
142
|
-
rsalib.set_precision(CRSALib::MAX_UNIT_PRECISION);
|
143
|
-
int blocksize = rsalib.significance((unsigned short *)n);
|
144
|
-
return blocksize;
|
145
|
-
}
|
146
|
-
|
147
|
-
unsigned int GetKeyBaseB(const unsigned short *n)
|
148
|
-
{
|
149
|
-
if(!n) return 0;
|
150
|
-
CRSALib rsalib(CRSALib::MAX_UNIT_PRECISION);
|
151
|
-
rsalib.set_precision(CRSALib::MAX_UNIT_PRECISION);
|
152
|
-
int blocksize = rsalib.significance((unsigned short *)n);
|
153
|
-
return blocksize * 2;
|
154
|
-
}
|
155
|
-
//---
|
data/ext/wmsigner/crypto.h
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#ifndef __CRYPTO_H__
|
2
|
-
#define __CRYPTO_H__
|
3
|
-
#include "stdafx.h"
|
4
|
-
|
5
|
-
#ifndef keybits
|
6
|
-
#define ebits 48
|
7
|
-
#define keybits 528
|
8
|
-
#endif
|
9
|
-
|
10
|
-
unsigned int CrpB(char* crp, char* p, int len, const unsigned short * e, const unsigned short *n, short KeyBits=keybits);
|
11
|
-
unsigned int DCrpB(char* dcrp, int* dlen, char* c, int len, const unsigned short * d, const unsigned short *n, short KeyBits=keybits);
|
12
|
-
unsigned int GetCLenB(int len, const unsigned short *n, short KeyBits=keybits);
|
13
|
-
unsigned int GetKeyBaseB(const unsigned short *n);
|
14
|
-
unsigned int GetKeyBase(const unsigned short *n);
|
15
|
-
|
16
|
-
#endif
|
17
|
-
//---
|
data/ext/wmsigner/extconf.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
# Loads mkmf which is used to make makefiles for Ruby extensions
|
3
|
-
require 'mkmf'
|
4
|
-
|
5
|
-
CONFIG["CC"] = "g++ "
|
6
|
-
#CONFIG["CPP"] = "g++ -E "
|
7
|
-
#CONFIG["LDSHARED"].gsub!(/^cc /,"g++ ")
|
8
|
-
|
9
|
-
# Give it a name
|
10
|
-
extension_name = 'wmsigner'
|
11
|
-
|
12
|
-
# The destination
|
13
|
-
dir_config(extension_name)
|
14
|
-
|
15
|
-
# Do the work
|
16
|
-
create_makefile(extension_name)
|
17
|
-
|
data/ext/wmsigner/md4.cpp
DELETED
@@ -1,192 +0,0 @@
|
|
1
|
-
#include "stdafx.h"
|
2
|
-
#include <stdio.h>
|
3
|
-
#include "md4.h"
|
4
|
-
#include "cmdbase.h"
|
5
|
-
|
6
|
-
#define TRUE 1
|
7
|
-
#define FALSE 0
|
8
|
-
|
9
|
-
#define I0 0x67452301L
|
10
|
-
#define I1 0xefcdab89L
|
11
|
-
#define I2 0x98badcfeL
|
12
|
-
#define I3 0x10325476L
|
13
|
-
#define C2 013240474631L
|
14
|
-
#define C3 015666365641L
|
15
|
-
|
16
|
-
#define fs1 3
|
17
|
-
#define fs2 7
|
18
|
-
#define fs3 11
|
19
|
-
#define fs4 19
|
20
|
-
#define gs1 3
|
21
|
-
#define gs2 5
|
22
|
-
#define gs3 9
|
23
|
-
#define gs4 13
|
24
|
-
#define hs1 3
|
25
|
-
#define hs2 9
|
26
|
-
#define hs3 11
|
27
|
-
#define hs4 15
|
28
|
-
|
29
|
-
|
30
|
-
#define f(X,Y,Z) ((X&Y) | ((~X)&Z))
|
31
|
-
#define g(X,Y,Z) ((X&Y) | (X&Z) | (Y&Z))
|
32
|
-
#define h(X,Y,Z) (X^Y^Z)
|
33
|
-
#define rot(X,S) (tmp=X,(tmp<<S) | (tmp>>(32-S)))
|
34
|
-
#define ff(A,B,C,D,i,s) A = rot((A + f(B,C,D) + X[i]),s)
|
35
|
-
#define gg(A,B,C,D,i,s) A = rot((A + g(B,C,D) + X[i] + C2),s)
|
36
|
-
#define hh(A,B,C,D,i,s) A = rot((A + h(B,C,D) + X[i] + C3),s)
|
37
|
-
|
38
|
-
void MDprint(MDptr MDp)
|
39
|
-
{
|
40
|
-
int i,j;
|
41
|
-
for (i=0;i<4;i++)
|
42
|
-
for (j=0;j<32;j=j+8)
|
43
|
-
printf("%02x",(MDp->buffer[i]>>j) & 0xFF);
|
44
|
-
}
|
45
|
-
|
46
|
-
void MDbegin(MDptr MDp)
|
47
|
-
{
|
48
|
-
int i;
|
49
|
-
MDp->buffer[0] = I0;
|
50
|
-
MDp->buffer[1] = I1;
|
51
|
-
MDp->buffer[2] = I2;
|
52
|
-
MDp->buffer[3] = I3;
|
53
|
-
for (i=0;i<8;i++)
|
54
|
-
MDp->count[i] = 0;
|
55
|
-
MDp->done = 0;
|
56
|
-
}
|
57
|
-
|
58
|
-
#define revx { t = (*X << 16) | (*X >> 16); *X++ = ((t & 0xFF00FF00L) >> 8) | ((t & 0x00FF00FFL) << 8); }
|
59
|
-
|
60
|
-
void MDreverse(Word32Type *X)
|
61
|
-
{
|
62
|
-
register Word32Type t;
|
63
|
-
revx; revx; revx; revx; revx; revx; revx; revx;
|
64
|
-
revx; revx; revx; revx; revx; revx; revx; revx;
|
65
|
-
}
|
66
|
-
|
67
|
-
static void MDblock(MDptr MDp, Word32Type *X)
|
68
|
-
{
|
69
|
-
register Word32Type tmp, A, B, C, D;
|
70
|
-
#ifndef LOWBYTEFIRST
|
71
|
-
MDreverse(X);
|
72
|
-
#endif
|
73
|
-
A = MDp->buffer[0];
|
74
|
-
B = MDp->buffer[1];
|
75
|
-
C = MDp->buffer[2];
|
76
|
-
D = MDp->buffer[3];
|
77
|
-
ff(A , B , C , D , 0 , fs1);
|
78
|
-
ff(D , A , B , C , 1 , fs2);
|
79
|
-
ff(C , D , A , B , 2 , fs3);
|
80
|
-
ff(B , C , D , A , 3 , fs4);
|
81
|
-
ff(A , B , C , D , 4 , fs1);
|
82
|
-
ff(D , A , B , C , 5 , fs2);
|
83
|
-
ff(C , D , A , B , 6 , fs3);
|
84
|
-
ff(B , C , D , A , 7 , fs4);
|
85
|
-
ff(A , B , C , D , 8 , fs1);
|
86
|
-
ff(D , A , B , C , 9 , fs2);
|
87
|
-
ff(C , D , A , B , 10 , fs3);
|
88
|
-
ff(B , C , D , A , 11 , fs4);
|
89
|
-
ff(A , B , C , D , 12 , fs1);
|
90
|
-
ff(D , A , B , C , 13 , fs2);
|
91
|
-
ff(C , D , A , B , 14 , fs3);
|
92
|
-
ff(B , C , D , A , 15 , fs4);
|
93
|
-
gg(A , B , C , D , 0 , gs1);
|
94
|
-
gg(D , A , B , C , 4 , gs2);
|
95
|
-
gg(C , D , A , B , 8 , gs3);
|
96
|
-
gg(B , C , D , A , 12 , gs4);
|
97
|
-
gg(A , B , C , D , 1 , gs1);
|
98
|
-
gg(D , A , B , C , 5 , gs2);
|
99
|
-
gg(C , D , A , B , 9 , gs3);
|
100
|
-
gg(B , C , D , A , 13 , gs4);
|
101
|
-
gg(A , B , C , D , 2 , gs1);
|
102
|
-
gg(D , A , B , C , 6 , gs2);
|
103
|
-
gg(C , D , A , B , 10 , gs3);
|
104
|
-
gg(B , C , D , A , 14 , gs4);
|
105
|
-
gg(A , B , C , D , 3 , gs1);
|
106
|
-
gg(D , A , B , C , 7 , gs2);
|
107
|
-
gg(C , D , A , B , 11 , gs3);
|
108
|
-
gg(B , C , D , A , 15 , gs4);
|
109
|
-
hh(A , B , C , D , 0 , hs1);
|
110
|
-
hh(D , A , B , C , 8 , hs2);
|
111
|
-
hh(C , D , A , B , 4 , hs3);
|
112
|
-
hh(B , C , D , A , 12 , hs4);
|
113
|
-
hh(A , B , C , D , 2 , hs1);
|
114
|
-
hh(D , A , B , C , 10 , hs2);
|
115
|
-
hh(C , D , A , B , 6 , hs3);
|
116
|
-
hh(B , C , D , A , 14 , hs4);
|
117
|
-
hh(A , B , C , D , 1 , hs1);
|
118
|
-
hh(D , A , B , C , 9 , hs2);
|
119
|
-
hh(C , D , A , B , 5 , hs3);
|
120
|
-
hh(B , C , D , A , 13 , hs4);
|
121
|
-
hh(A , B , C , D , 3 , hs1);
|
122
|
-
hh(D , A , B , C , 11 , hs2);
|
123
|
-
hh(C , D , A , B , 7 , hs3);
|
124
|
-
hh(B , C , D , A , 15 , hs4);
|
125
|
-
MDp->buffer[0] += A;
|
126
|
-
MDp->buffer[1] += B;
|
127
|
-
MDp->buffer[2] += C;
|
128
|
-
MDp->buffer[3] += D;
|
129
|
-
|
130
|
-
#ifndef LOWBYTEFIRST
|
131
|
-
MDreverse(X);
|
132
|
-
#endif
|
133
|
-
}
|
134
|
-
|
135
|
-
void MDupdate(MDptr MDp, unsigned char *X, Word32Type count)
|
136
|
-
{
|
137
|
-
int i, byte ;
|
138
|
-
Word32Type tmp, bit, mask;
|
139
|
-
unsigned char XX[64];
|
140
|
-
unsigned char *p;
|
141
|
-
if(count == 0 && MDp->done)
|
142
|
-
return;
|
143
|
-
if (MDp->done)
|
144
|
-
{
|
145
|
-
return;
|
146
|
-
}
|
147
|
-
tmp = count;
|
148
|
-
p = MDp->count;
|
149
|
-
while (tmp)
|
150
|
-
{
|
151
|
-
tmp += *p;
|
152
|
-
*p++ = (unsigned char) tmp;
|
153
|
-
tmp = tmp >> 8;
|
154
|
-
}
|
155
|
-
if (count == 512)
|
156
|
-
{
|
157
|
-
MDblock(MDp,(Word32Type *)X);
|
158
|
-
}
|
159
|
-
else
|
160
|
-
if (count > 512)
|
161
|
-
{
|
162
|
-
return;
|
163
|
-
}
|
164
|
-
else
|
165
|
-
{
|
166
|
-
byte = (int) count >> 3;
|
167
|
-
bit = count & 7;
|
168
|
-
for (i=0;i<=byte;i++)
|
169
|
-
XX[i] = X[i];
|
170
|
-
for (i=byte+1;i<64;i++)
|
171
|
-
XX[i] = 0;
|
172
|
-
mask = 1 << (7 - bit);
|
173
|
-
XX[byte] = (unsigned char) (XX[byte] | (unsigned char)mask) & ~((unsigned char)mask - 1);
|
174
|
-
if (byte <= 55)
|
175
|
-
{
|
176
|
-
for (i=0;i<8;i++)
|
177
|
-
XX[56+i] = MDp->count[i];
|
178
|
-
MDblock(MDp,(Word32Type *)XX);
|
179
|
-
}
|
180
|
-
else
|
181
|
-
{
|
182
|
-
MDblock(MDp,(Word32Type *)XX);
|
183
|
-
for (i=0;i<56;i++)
|
184
|
-
XX[i] = 0;
|
185
|
-
for (i=0;i<8;i++)
|
186
|
-
XX[56+i] = MDp->count[i];
|
187
|
-
MDblock(MDp,(Word32Type *)XX);
|
188
|
-
}
|
189
|
-
MDp->done = 1;
|
190
|
-
}
|
191
|
-
}
|
192
|
-
//----
|