Changeset - r13364:f0288ff44c97
[Not reviewed]
master
0 2 0
smatz - 15 years ago 2009-10-26 23:03:03
smatz@openttd.org
(svn r17883) -Codechange: little cleaning in md5.cpp and md5.h
2 files changed with 5 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/3rdparty/md5/md5.cpp
Show inline comments
 
@@ -166,25 +166,25 @@ Md5::Md5()
 
}
 

	
 
void Md5::Process(const uint8 *data /*[64]*/)
 
{
 
	uint32 a = this->abcd[0];
 
	uint32 b = this->abcd[1];
 
	uint32 c = this->abcd[2];
 
	uint32 d = this->abcd[3];
 

	
 
	uint32 X[16];
 

	
 
	/* Convert the uint8 data to uint32 LE */
 
	uint32 *px = (uint32 *)data;
 
	const uint32 *px = (const uint32 *)data;
 
	for (uint i = 0; i < 16; i++) {
 
		X[i] = TO_LE32(*px);
 
		px++;
 
	}
 

	
 
	/* Round 1. */
 
	Md5Set1(X, &a, &b, &c, &d,  0,  7,  T1);
 
	Md5Set1(X, &d, &a, &b, &c,  1, 12,  T2);
 
	Md5Set1(X, &c, &d, &a, &b,  2, 17,  T3);
 
	Md5Set1(X, &b, &c, &d, &a,  3, 22,  T4);
 
	Md5Set1(X, &a, &b, &c, &d,  4,  7,  T5);
 
	Md5Set1(X, &d, &a, &b, &c,  5, 12,  T6);
 
@@ -297,26 +297,27 @@ void Md5::Append(const void *data, const
 
	if (left) memcpy(this->buf, p, left);
 
}
 

	
 
void Md5::Finish(uint8 digest[16])
 
{
 
	static const uint8 pad[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
 
	};
 
	uint8 data[8];
 
	uint i;
 

	
 
	/* Save the length before padding. */
 
	for (i = 0; i < 8; ++i)
 
	for (uint i = 0; i < 8; ++i) {
 
		data[i] = (uint8)(this->count[i >> 2] >> ((i & 3) << 3));
 
	}
 

	
 
	/* Pad to 56 bytes mod 64. */
 
	this->Append(pad, ((55 - (this->count[0] >> 3)) & 63) + 1);
 
	/* Append the length. */
 
	this->Append(data, 8);
 

	
 
	for (i = 0; i < 16; ++i)
 
	for (uint i = 0; i < 16; ++i) {
 
		digest[i] = (uint8)(this->abcd[i >> 2] >> ((i & 3) << 3));
 
	}
 
}
src/3rdparty/md5/md5.h
Show inline comments
 
@@ -46,34 +46,24 @@
 
             references to Ghostscript; clarified derivation from RFC 1321;
 
             now handles byte order either statically or dynamically.
 
  1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
 
  1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
 
             added conditionalization for C++ compilation from Martin
 
             Purschke <purschke@bnl.gov>.
 
  1999-05-03 lpd Original version.
 
 */
 

	
 
#ifndef MD5_INCLUDED
 
#define MD5_INCLUDED
 

	
 
/*
 
 * This package supports both compile-time and run-time determination of CPU
 
 * byte order.  If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
 
 * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
 
 * defined as non-zero, the code will be compiled to run only on big-endian
 
 * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
 
 * run on either big- or little-endian CPUs, but will run slightly less
 
 * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
 
 */
 

	
 
struct Md5 {
 
private:
 
	uint32 count[2]; ///< message length in bits, lsw first
 
	uint32 abcd[4];  ///< digest buffer
 
	uint8 buf[64];   ///< accumulate block
 

	
 
	void Process(const uint8 *data);
 

	
 
public:
 
	Md5();
 
	void Append(const void *data, const size_t nbytes);
 
	void Finish(uint8 digest[16]);
0 comments (0 inline, 0 general)