Форум: "Сети";
Текущий архив: 2004.07.11;
Скачать: [xml.tar.bz2];
ВнизeDonkey eMule hash алгоритм Найти похожие ветки
← →
Eugene13 © (2004-05-05 02:56) [0]Кто знает какой алгоритм используют программы P2P (eMule, eDonkey) для хеширривания файлов. Может есть у кого информация и исходники. Спасибо.
← →
Girder (2004-05-05 03:44) [1]//The md4 RFC, if you want to know how MD4 works
//http://community.roxen.com/developers/idocs/rfc/rfc1320.html
//It uses MD4 hashing.....
//Each Part (9mb or so) is hashed using md4 to produce the part
//hash, then all the part hashes are hashed together to produce
//the overall filehash. The filehash is contained in the e2k
//link, all the hashes of the parts (known as a hashset) is
//transfered p2p between two clients, when you find a source
//for this file
//In this way we can validate each part as correct, as all
//clients have a hashset. When we download a complete part it
//is hashed, if it matches the part hash in the hashset it is
//correct and will be uploaded to other clients. If it is
//invalid, the part is dropped or a fix is attempted
// CreateHashFromInput() generates a hash from the
//next "Length" bytes of one of "file", "file2", or "in_string"
// (the other two must be NULL (UGLY UGLY UGLY)). The hash is
//returned in "*Output".
void CKnownFile::CreateHashFromInput(FILE* file,CFile* file2, int Length, uchar* Output, uchar* in_string)
{
EMULE_TRY
// time critial
uint32 Hash[4];
Hash[0] = 0x67452301;
Hash[1] = 0xEFCDAB89;
Hash[2] = 0x98BADCFE;
Hash[3] = 0x10325476;
CFile* data = 0;
if (in_string)
data = new CMemFile(in_string,Length);
uint32 Required = Length;
uchar X[64*128];
while (Required >= 64)
{
uint32 len = Required & ~63;
if (len > sizeof(X))
len = sizeof(X);
if (in_string)
data->Read(&X,len);
else if (file)
fread(&X,len,1,file);
else if (file2)
file2->Read(&X,len);
uint32 i = 0;
do
{
MD4Transform(Hash, (uint32*)(X + i));
i += 64;
} while(i < len);
Required -= len;
}
// bytes to read
if (Required != 0)
{
if (in_string)
data->Read(&X,Required);
else if (file)
fread(&X,Required,1,file);
else if (file2)
file2->Read(&X,Required);
}
// in byte scale 512 = 64, 448 = 56
X[Required++] = 0x80;
if (Required > 56)
{
memset2(&X[Required], 0, 64 - Required);
MD4Transform(Hash, (uint32*)X);
Required = 0;
}
memset2(&X[Required], 0, 56 - Required);
// add size (convert to bits)
uint32 Length2[2] = { Length << 3, (uint32)Length >> 29 };
memcpy2(&X[56], Length2, 8);
MD4Transform(Hash, (uint32*)X);
md4cpy(Output, Hash);
safe_delete(data);
EMULE_CATCH
}
/////////////////////////////////////////////////////////////////////////////////////////////
// partial transformations
#define MD4_FF(a, b, c, d, x, s) \
{ \
(a) += MD4_F((b), (c), (d)) + (x); \
(a) = MD4_ROTATE_LEFT((a), (s)); \
}
#define MD4_GG(a, b, c, d, x, s) \
{ \
(a) += MD4_G((b), (c), (d)) + (x) + (uint32)0x5A827999; \
(a) = MD4_ROTATE_LEFT((a), (s)); \
}
#define MD4_HH(a, b, c, d, x, s) \
{ \
(a) += MD4_H((b), (c), (d)) + (x) + (uint32)0x6ED9EBA1; \
(a) = MD4_ROTATE_LEFT((a), (s)); \
}
/////////////////////////////////////////////////////////////////////////////////////////////
static void MD4Transform(uint32 Hash[4], uint32 x[16])
{
EMULE_TRY
uint32 a = Hash[0];
uint32 b = Hash[1];
uint32 c = Hash[2];
uint32 d = Hash[3];
/* Round 1 */
MD4_FF(a, b, c, d, x[ 0], S11); // 01
MD4_FF(d, a, b, c, x[ 1], S12); // 02
MD4_FF(c, d, a, b, x[ 2], S13); // 03
MD4_FF(b, c, d, a, x[ 3], S14); // 04
MD4_FF(a, b, c, d, x[ 4], S11); // 05
MD4_FF(d, a, b, c, x[ 5], S12); // 06
MD4_FF(c, d, a, b, x[ 6], S13); // 07
MD4_FF(b, c, d, a, x[ 7], S14); // 08
MD4_FF(a, b, c, d, x[ 8], S11); // 09
MD4_FF(d, a, b, c, x[ 9], S12); // 10
MD4_FF(c, d, a, b, x[10], S13); // 11
MD4_FF(b, c, d, a, x[11], S14); // 12
MD4_FF(a, b, c, d, x[12], S11); // 13
MD4_FF(d, a, b, c, x[13], S12); // 14
MD4_FF(c, d, a, b, x[14], S13); // 15
MD4_FF(b, c, d, a, x[15], S14); // 16
/* Round 2 */
MD4_GG(a, b, c, d, x[ 0], S21); // 17
MD4_GG(d, a, b, c, x[ 4], S22); // 18
MD4_GG(c, d, a, b, x[ 8], S23); // 19
MD4_GG(b, c, d, a, x[12], S24); // 20
MD4_GG(a, b, c, d, x[ 1], S21); // 21
MD4_GG(d, a, b, c, x[ 5], S22); // 22
MD4_GG(c, d, a, b, x[ 9], S23); // 23
MD4_GG(b, c, d, a, x[13], S24); // 24
MD4_GG(a, b, c, d, x[ 2], S21); // 25
MD4_GG(d, a, b, c, x[ 6], S22); // 26
MD4_GG(c, d, a, b, x[10], S23); // 27
MD4_GG(b, c, d, a, x[14], S24); // 28
MD4_GG(a, b, c, d, x[ 3], S21); // 29
MD4_GG(d, a, b, c, x[ 7], S22); // 30
MD4_GG(c, d, a, b, x[11], S23); // 31
MD4_GG(b, c, d, a, x[15], S24); // 32
/* Round 3 */
MD4_HH(a, b, c, d, x[ 0], S31); // 33
MD4_HH(d, a, b, c, x[ 8], S32); // 34
MD4_HH(c, d, a, b, x[ 4], S33); // 35
MD4_HH(b, c, d, a, x[12], S34); // 36
MD4_HH(a, b, c, d, x[ 2], S31); // 37
MD4_HH(d, a, b, c, x[10], S32); // 38
MD4_HH(c, d, a, b, x[ 6], S33); // 39
MD4_HH(b, c, d, a, x[14], S34); // 40
MD4_HH(a, b, c, d, x[ 1], S31); // 41
MD4_HH(d, a, b, c, x[ 9], S32); // 42
MD4_HH(c, d, a, b, x[ 5], S33); // 43
MD4_HH(b, c, d, a, x[13], S34); // 44
MD4_HH(a, b, c, d, x[ 3], S31); // 45
MD4_HH(d, a, b, c, x[11], S32); // 46
MD4_HH(c, d, a, b, x[ 7], S33); // 47
MD4_HH(b, c, d, a, x[15], S34); // 48
Hash[0] += a;
Hash[1] += b;
Hash[2] += c;
Hash[3] += d;
EMULE_CATCH
}
← →
ЖукЖук (2004-05-12 19:21) [2]А здесь MD5:
http://forum.vingrad.ru/index.php?s=d00e52df0b015e3648c3ff2d7e5a9781&showtopic=13554
← →
BillyJeans © (2004-05-13 15:17) [3]Удалено модератором
Примечание: А если внимательней вопрос почитать? Подразумевалось "КАКОЙ НИБУДЬ алгоритм"...
Страницы: 1 вся ветка
Форум: "Сети";
Текущий архив: 2004.07.11;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.034 c