MD5校验值program(2) (2008-06-09 09:20:11)

hegangben
2025-07-14 / 0 评论 / 0 阅读 / 正在检测是否收录...

/ 这是已导出类的构造函数。

// 有关类定义的信息,请参阅 Security.h

CSecurity::CSecurity()

{

return;

}

void CSecurity::MD5Init( MD5_CTX *context )

{

context->count[0] = context->count[1] = 0;

context->state[0] = 0x67452301;

context->state[1] = 0xefcdab89;

context->state[2] = 0x98badcfe;

context->state[3] = 0x10325476;

}

void CSecurity::MD5Update(

MD5_CTX *context,  

unsigned char *input,  

size_t inputLen  

) 

{

size_t i, index, partLen;

index = (size_t)((context->count[0] >> 3) & 0x3F);

if ((context->count[0] += ((UINT4)inputLen << 3))

< ((UINT4)inputLen << 3))

context->count[1]++;

context->count[1] += ((UINT4)inputLen >> 29);

partLen = 64 - index;

if (inputLen >= partLen) {

MD5_memcpy

((POINTER)&context->buffer[index], (POINTER)input, partLen);

MD5Transform (context->state, context->buffer);

for (i = partLen; i + 63 < inputLen; i += 64)

MD5Transform (context->state, &input);

index = 0;

}

else

i = 0;

MD5_memcpy

((POINTER)&context->buffer[index], (POINTER)&input,

inputLen-i);

}

void CSecurity::MD5Final(

unsigned char digest[16],  

MD5_CTX *context  

) 

{

unsigned char bits[8];

size_t index, padLen;

Encode (bits, context->count, 8);

index = (size_t)((context->count[0] >> 3) & 0x3f);

padLen = (index < 56) ? (56 - index) : (120 - index);

MD5Update (context, PADDING, padLen);

MD5Update (context, bits, 8);

Encode (digest, context->state, 16);

MD5_memset ((POINTER)context, 0, sizeof (*context));

}

void CSecurity::MD5Transform(

UINT4 state[4], 

unsigned char block[64] 

) 

{

UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];

Decode (x, block, 64);

FF (a, b, c, d, x[ 0], S11, 0xd76aa478);

FF (d, a, b, c, x[ 1], S12, 0xe8c7b756);

FF (c, d, a, b, x[ 2], S13, 0x242070db);

FF (b, c, d, a, x[ 3], S14, 0xc1bdceee);

FF (a, b, c, d, x[ 4], S11, 0xf57c0faf);

FF (d, a, b, c, x[ 5], S12, 0x4787c62a);

FF (c, d, a, b, x[ 6], S13, 0xa8304613);

FF (b, c, d, a, x[ 7], S14, 0xfd469501);

FF (a, b, c, d, x[ 8], S11, 0x698098d8);

FF (d, a, b, c, x[ 9], S12, 0x8b44f7af);

FF (c, d, a, b, x[10], S13, 0xffff5bb1);

FF (b, c, d, a, x[11], S14, 0x895cd7be);

FF (a, b, c, d, x[12], S11, 0x6b901122);

FF (d, a, b, c, x[13], S12, 0xfd987193);

FF (c, d, a, b, x[14], S13, 0xa679438e);

FF (b, c, d, a, x[15], S14, 0x49b40821);

分享:

0

评论 (0)

取消