#include "md5.h"
#include <S32FILE.H> // Link against: estor.lib
#include <S32BUF.H>
const TUint8 PADDING[64] = { 0x80 }; /* padding for calculate */
const TUint16 HEX[16]=
{
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
'c', 'd', 'e', 'f'
};
const TInt BUFFER_SIZE = 1024;
/* Constants for MD5Transform routine. */
#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21
/* F, G, H and I are basic MD5 functions.
*/
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits.
*/
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
Rotation is separate from addition to prevent recomputation.
*/
#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + ac; \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + ac; \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + ac; \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + ac; \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
//const TUint8 CMD5::PADDING[64] = { 0x80 };
//const TChar CMD5::HEX[16] = {
// '0', '1', '2', '3',
// '4', '5', '6', '7',
// '8', '9', 'a', 'b',
// 'c', 'd', 'e', 'f'
//};
/* Default construct. */
CMD5::CMD5()
{
Reset();
}
/* Construct a MD5 object with a input buffer. */
CMD5::CMD5(const void* aInput, TUint aLength)
{
Reset();
Update(aInput, aLength);
}
/* Construct a MD5 object with a string. */
CMD5::CMD5(const TDesC& str)
{
Reset();
Update(str);
}
/* Construct a MD5 object with a file. */
CMD5::CMD5(RFileReadStream& in)
{
Reset();
Update(in);
}
/* Return the message-digest */
const TUint8* CMD5::Digest()
{
if (!iFinished)
{
iFinished = true;
Final();
}
return iDigest;
}
/* Reset the calculate state */
void CMD5::Reset()
{
iFinished = EFalse;
/* reset number of bits. */
iCount[0] = iCount[1] = 0;
/* Load magic initialization constants. */
iState[0] = 0x67452301;
iState[1] = 0xefcdab89;
iState[2] = 0x98badcfe;
iState[3] = 0x10325476;
}
/* Updating the context with a input buffer. */
void CMD5::Update(const void* aInput, TUint aLength)
{
Update((const TUint8*) aInput, aLength);
}
/* Updating the context with a string. */
void CMD5::Update(const TDesC& str)
{
Update((const TUint8*) str.Ptr(), str.Length());
}
/* Updating the context with a file. */
void CMD5::Update(RFileReadStream& in)
{
TInt leftSize;
TUint8 buffer[BUFFER_SIZE];
MStreamBuf * srcBuf = in.Source();
leftSize = srcBuf->SizeL();
while (leftSize > 0)
{
TInt readSize = (leftSize > BUFFER_SIZE) ? BUFFER_SIZE : leftSize;
TRAPD(err,in.ReadL(buffer, readSize));
if (err == KErrNone)
{
Update(buffer, readSize);
leftSize -= readSize;
}
else
{
break;
}
}
}
/* MD5 block Update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
void CMD5::Update(const TUint8* aInput, TUint aLength)
{
TUint32 i, index, partLen;
iFinished = EFalse;
/* Compute number of bytes mod 64 */
index = (TUint32) ((iCount[0] >> 3) & 0x3f);
/* Update number of bits */
if ((iCount[0] += ((TUint32) aLength << 3)) < ((TUint32) aLength << 3))
{
++iCount[1];
}
iCount[1] += ((TUint32) aLength >> 29);
partLen = 64 - index;
/* transform as many times as possible. */
if (aLength >= partLen)
{
Mem::Copy(&iBuffer[index], aInput, partLen);
Transform(iBuffer);
for (i = partLen; i + 63 < aLength; i += 64)
{
Transform(&aInput[i]);
}
index = 0;
}
else
{
i = 0;
}
/* Buffer remaining input */
Mem::Copy(&iBuffer[index], &aInput[i], aLength - i);
}
/* MD5 finalization. Ends an MD5 message-_digest operation, writing the
the message iDigest and zeroizing the context.
*/
void CMD5::Final()
{
TUint8 bits[8];
TUint32 oldState[4];
TUint32 oldCount[2];
TUint32 index, padLen;
/* Save current state and count. */
Mem::Copy(oldState, iState, 16);
Mem::Copy(oldCount, iCount, 8);
/* Save number of bits */
Encode(iCount, bits, 8);
/* Pad out to 56 mod 64. */
index = (TUint32) ((iCount[0] >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
Update(PADDING, padLen);
/* Append length (before padding) */
Update(bits, 8);
/* Store state in digest */
Encode(iState, iDigest, 16);
/* Restore current state and count. */
Mem::Copy(iState, oldState, 16);
Mem::Copy(iCount, oldCount, 8);
}
/* MD5 basic transformation. Transforms iState based on block. */
void CMD5::Transform(const TUint8 block[64])
{
TUint32 a = iState[0], b = iState[1], c = iState[2], d = iState[3], x[16];
Decode(block, x, 64);
/* Round 1 */
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
II (d, a, b, c, x[ 7], S
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
移植了一个Md5算法到symbian 移植前的代码参见 http://www.cppblog.com/ant/archive/2007/09/11/31886.html 另外写了一个枚举所有盘符和属性的代码 控制台程序,结果打日志 请在 epocroot\winscw\c\data\logs\下面创建名为“L”的目录,结果将会打印在windcao.log文件里面。 如:2009/05/27 01:16:32 md5_result:len=32,buf=7b94f1c21e6aaf65c50d3ef7e845cba7
资源推荐
资源详情
资源评论
收起资源包目录
TestConsole_DirveInfo_MD5_2009_05_27.rar (25个子文件)
TestConsole
.project 523B
group
ABLD.BAT 314B
run.bat 78B
bld.inf 399B
TestConsole.mmp 769B
sis
TestConsul_EKA2.pkg 705B
TestConsole.sis 2KB
TestConsul_EKA2.sis 7KB
TestConsul_EKA2.sisx 11KB
.cproject 12KB
.settings
carbide_cs_settings.xml 5KB
inc
TestConsole.h 444B
log.h 3KB
md5.h 2KB
TestMd5.h 160B
TestLog.h 502B
TestDirveInfo.h 1017B
litfix.h 1KB
src
TestDirveInfo.cpp 2KB
TestLog.cpp 7KB
log.cpp 5KB
md5.cpp 10KB
TestMd5.cpp 645B
TestConsole.cpp 3KB
data
TestConsole.rss 250B
共 25 条
- 1
资源评论
- NiasSama2013-03-20挺好用的额,谢谢!
- guoli_NIC2012-08-21编译通过,MD5初步检验与理论值一致,很好的一个东西~
曹建峰-17年老猿
- 粉丝: 94
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功