#include <memory.h>
#include "MD4.h"
// Constants for MD4_Transform routine.
#define MD4_S11 3
#define MD4_S12 7
#define MD4_S13 11
#define MD4_S14 19
#define MD4_S21 3
#define MD4_S22 5
#define MD4_S23 9
#define MD4_S24 13
#define MD4_S31 3
#define MD4_S32 9
#define MD4_S33 11
#define MD4_S34 15
static void MD4_Transform(UINT4 *state, unsigned char *block);
static void MD4_Encode(unsigned char *output, UINT4 *input, unsigned int len);
static void MD4_Decode(UINT4 *output, unsigned char *input, unsigned int len);
static unsigned char MD4_PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
// MD4F, MD4G and MD4H are basic MD4 functions.
#define MD4F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define MD4G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
#define MD4H(x, y, z) ((x) ^ (y) ^ (z))
// MD4_ROTL rotates x left n bits.
#define MD4_ROTL(x, n) (((x) << (n)) | ((x) >> (32-(n))))
// MD4FF, MD4GG and MD4HH are transformations for rounds 1, 2 and 3
// Rotation is separate from addition to prevent recomputation
#define MD4FF(a, b, c, d, x, s) { \
(a) += MD4F ((b), (c), (d)) + (x); \
(a) = MD4_ROTL ((a), (s)); \
}
#define MD4GG(a, b, c, d, x, s) { \
(a) += MD4G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; \
(a) = MD4_ROTL ((a), (s)); \
}
#define MD4HH(a, b, c, d, x, s) { \
(a) += MD4H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; \
(a) = MD4_ROTL ((a), (s)); \
}
// MD4 initialization. Begins an MD4 operation, writing a new context
void MD4Init(MD4_CTX *context)
{
context->count[0] = context->count[1] = 0;
// Load magic initialization constants
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
}
// MD4 block update operation. Continues an MD4 message-digest
// operation, processing another message block, and updating the
// context
void MD4Update(MD4_CTX *context, unsigned char *input, unsigned int inputLen)
{
unsigned int i = 0, index = 0, partLen = 0;
// Compute number of bytes mod 64
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
// Update number of bits
if ((context->count[0] += ((UINT4)inputLen << 3))
< ((UINT4)inputLen << 3))
context->count[1]++;
context->count[1] += ((UINT4)inputLen >> 29);
partLen = 64 - index;
// Transform as many times as possible
if (inputLen >= partLen)
{
memcpy((MD4_POINTER)&context->buffer[index], (MD4_POINTER)input, partLen);
MD4_Transform(context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
MD4_Transform (context->state, &input[i]);
index = 0;
}
else i = 0;
// Buffer remaining input
memcpy((MD4_POINTER)&context->buffer[index], (MD4_POINTER)&input[i], inputLen - i);
}
// MD4 finalization. Ends an MD4 message-digest operation, writing the
// the message digest and zeroizing the context.
void MD4Final(unsigned char *digest, MD4_CTX *context)
{
unsigned char bits[8] = {0, 0, 0, 0, 0, 0, 0, 0};
unsigned int index = 0, padLen = 0;
// Save number of bits
MD4_Encode (bits, context->count, 8);
// Pad out to 56 mod 64.
index = (unsigned int)((context->count[0] >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
MD4Update(context, MD4_PADDING, padLen);
// Append length (before padding)
MD4Update(context, bits, 8);
// Store state in digest
MD4_Encode(digest, context->state, 16);
// Zeroize sensitive information
memset((MD4_POINTER)context, 0, sizeof(MD4_CTX));
}
// MD4 basic transformation. Transforms state based on block.
static void MD4_Transform(UINT4 *state, unsigned char *block)
{
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
MD4_Decode(x, block, 64);
// Round 1
MD4FF (a, b, c, d, x[ 0], MD4_S11); /* 1 */
MD4FF (d, a, b, c, x[ 1], MD4_S12); /* 2 */
MD4FF (c, d, a, b, x[ 2], MD4_S13); /* 3 */
MD4FF (b, c, d, a, x[ 3], MD4_S14); /* 4 */
MD4FF (a, b, c, d, x[ 4], MD4_S11); /* 5 */
MD4FF (d, a, b, c, x[ 5], MD4_S12); /* 6 */
MD4FF (c, d, a, b, x[ 6], MD4_S13); /* 7 */
MD4FF (b, c, d, a, x[ 7], MD4_S14); /* 8 */
MD4FF (a, b, c, d, x[ 8], MD4_S11); /* 9 */
MD4FF (d, a, b, c, x[ 9], MD4_S12); /* 10 */
MD4FF (c, d, a, b, x[10], MD4_S13); /* 11 */
MD4FF (b, c, d, a, x[11], MD4_S14); /* 12 */
MD4FF (a, b, c, d, x[12], MD4_S11); /* 13 */
MD4FF (d, a, b, c, x[13], MD4_S12); /* 14 */
MD4FF (c, d, a, b, x[14], MD4_S13); /* 15 */
MD4FF (b, c, d, a, x[15], MD4_S14); /* 16 */
// Round 2
MD4GG (a, b, c, d, x[ 0], MD4_S21); /* 17 */
MD4GG (d, a, b, c, x[ 4], MD4_S22); /* 18 */
MD4GG (c, d, a, b, x[ 8], MD4_S23); /* 19 */
MD4GG (b, c, d, a, x[12], MD4_S24); /* 20 */
MD4GG (a, b, c, d, x[ 1], MD4_S21); /* 21 */
MD4GG (d, a, b, c, x[ 5], MD4_S22); /* 22 */
MD4GG (c, d, a, b, x[ 9], MD4_S23); /* 23 */
MD4GG (b, c, d, a, x[13], MD4_S24); /* 24 */
MD4GG (a, b, c, d, x[ 2], MD4_S21); /* 25 */
MD4GG (d, a, b, c, x[ 6], MD4_S22); /* 26 */
MD4GG (c, d, a, b, x[10], MD4_S23); /* 27 */
MD4GG (b, c, d, a, x[14], MD4_S24); /* 28 */
MD4GG (a, b, c, d, x[ 3], MD4_S21); /* 29 */
MD4GG (d, a, b, c, x[ 7], MD4_S22); /* 30 */
MD4GG (c, d, a, b, x[11], MD4_S23); /* 31 */
MD4GG (b, c, d, a, x[15], MD4_S24); /* 32 */
// Round 3
MD4HH (a, b, c, d, x[ 0], MD4_S31); /* 33 */
MD4HH (d, a, b, c, x[ 8], MD4_S32); /* 34 */
MD4HH (c, d, a, b, x[ 4], MD4_S33); /* 35 */
MD4HH (b, c, d, a, x[12], MD4_S34); /* 36 */
MD4HH (a, b, c, d, x[ 2], MD4_S31); /* 37 */
MD4HH (d, a, b, c, x[10], MD4_S32); /* 38 */
MD4HH (c, d, a, b, x[ 6], MD4_S33); /* 39 */
MD4HH (b, c, d, a, x[14], MD4_S34); /* 40 */
MD4HH (a, b, c, d, x[ 1], MD4_S31); /* 41 */
MD4HH (d, a, b, c, x[ 9], MD4_S32); /* 42 */
MD4HH (c, d, a, b, x[ 5], MD4_S33); /* 43 */
MD4HH (b, c, d, a, x[13], MD4_S34); /* 44 */
MD4HH (a, b, c, d, x[ 3], MD4_S31); /* 45 */
MD4HH (d, a, b, c, x[11], MD4_S32); /* 46 */
MD4HH (c, d, a, b, x[ 7], MD4_S33); /* 47 */
MD4HH (b, c, d, a, x[15], MD4_S34); /* 48 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
// Zeroize sensitive information.
memset ((MD4_POINTER)x, 0, sizeof(x));
}
// MD4_Encodes input (UINT4) into output (unsigned char). Assumes len is
// a multiple of 4.
static void MD4_Encode(unsigned char *output, UINT4 *input, unsigned int len)
{
unsigned int i = 0, j = 0;
for (i = 0, j = 0; j < len; i++, j += 4)
{
output[j] = (unsigned char)(input[i] & 0xff);
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
}
}
// MD4_Decodes input (unsigned char) into output (UINT4). Assumes len is
// a multiple of 4.
static void MD4_Decode(UINT4 *output, unsigned char *input, unsigned int len)
{
unsigned int i = 0, j = 0;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
}
没有合适的资源?快使用搜索试试~ 我知道了~
c++实现LM和NTLM哈希
共16个文件
h:2个
cpp:2个
obj:2个
5星 · 超过95%的资源 需积分: 10 147 下载量 171 浏览量
2010-10-31
19:27:52
上传
评论 3
收藏 367KB RAR 举报
温馨提示
在vs2008下实现NTLM和LM哈希加密,包含MD4加密和DES加密函数
资源推荐
资源详情
资源评论
收起资源包目录
HashWorks.rar (16个子文件)
HashWorks
HashWorks.ncb 1.54MB
HashWorks.sln 893B
HashWorks.suo 14KB
HashWorks
LMHash.h 10KB
HashWorks.vcproj 4KB
HashWorks.cpp 747B
MD4.cpp 7KB
Debug
HashWorks.exe.intermediate.manifest 621B
vc90.idb 179KB
BuildLog.htm 7KB
mt.dep 63B
HashWorks.obj 63KB
vc90.pdb 212KB
MD4.obj 3KB
MD4.h 636B
HashWorks.vcproj.achilles-PC.achilles.user 1KB
共 16 条
- 1
skybest1
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页