Core: Reworked hashes
-Removed HashDigest class (replaced by ByteArray) -Removed Hashable/Hash classes (replaced by ComputeHash function and Hashable template struct) -Fixed ByteArray operator<< -Renamed File::GetHash to File::ComputeHash Former-commit-id: cc5eaf2d4c88a556878190b8205e66713512e2d2
This commit is contained in:
@@ -109,7 +109,7 @@ namespace Nz
|
||||
m_state->crc = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
HashDigest HashCRC32::End()
|
||||
ByteArray HashCRC32::End()
|
||||
{
|
||||
m_state->crc ^= 0xFFFFFFFF;
|
||||
|
||||
@@ -117,17 +117,16 @@ namespace Nz
|
||||
SwapBytes(&m_state->crc, sizeof(UInt32));
|
||||
#endif
|
||||
|
||||
return HashDigest(GetHashName(), reinterpret_cast<UInt8*>(&m_state->crc), 4);
|
||||
return ByteArray(reinterpret_cast<UInt8*>(&m_state->crc), 4);
|
||||
}
|
||||
|
||||
unsigned int HashCRC32::GetDigestLength()
|
||||
unsigned int HashCRC32::GetDigestLength() const
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
String HashCRC32::GetHashName()
|
||||
const char* HashCRC32::GetHashName() const
|
||||
{
|
||||
static String hashName = "CRC32";
|
||||
return hashName;
|
||||
return "CRC32";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Nz
|
||||
m_state->sum2 = 0xff;
|
||||
}
|
||||
|
||||
HashDigest HashFletcher16::End()
|
||||
ByteArray HashFletcher16::End()
|
||||
{
|
||||
m_state->sum1 = (m_state->sum1 & 0xff) + (m_state->sum1 >> 8);
|
||||
m_state->sum2 = (m_state->sum2 & 0xff) + (m_state->sum2 >> 8);
|
||||
@@ -59,17 +59,16 @@ namespace Nz
|
||||
SwapBytes(&fletcher, sizeof(UInt32));
|
||||
#endif
|
||||
|
||||
return HashDigest(GetHashName(), reinterpret_cast<UInt8*>(&fletcher), 2);
|
||||
return ByteArray(reinterpret_cast<UInt8*>(&fletcher), 2);
|
||||
}
|
||||
|
||||
unsigned int HashFletcher16::GetDigestLength()
|
||||
unsigned int HashFletcher16::GetDigestLength() const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
String HashFletcher16::GetHashName()
|
||||
const char* HashFletcher16::GetHashName() const
|
||||
{
|
||||
static String hashName = "Fletcher16";
|
||||
return hashName;
|
||||
return "Fletcher16";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ namespace Nz
|
||||
m_state->abcd[3] = 0x10325476;
|
||||
}
|
||||
|
||||
HashDigest HashMD5::End()
|
||||
ByteArray HashMD5::End()
|
||||
{
|
||||
static const unsigned char pad[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@@ -349,17 +349,16 @@ namespace Nz
|
||||
for (i = 0; i < 16; ++i)
|
||||
digest[i] = static_cast<UInt8>(m_state->abcd[i >> 2] >> ((i & 3) << 3));
|
||||
|
||||
return HashDigest(GetHashName(), &digest[0], 16);
|
||||
return ByteArray(&digest[0], 16);
|
||||
}
|
||||
|
||||
unsigned int HashMD5::GetDigestLength()
|
||||
unsigned int HashMD5::GetDigestLength() const
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
String HashMD5::GetHashName()
|
||||
const char* HashMD5::GetHashName() const
|
||||
{
|
||||
static String hashName = "MD5";
|
||||
return hashName;
|
||||
return "MD5";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,23 +28,22 @@ namespace Nz
|
||||
SHA1_Init(m_state);
|
||||
}
|
||||
|
||||
HashDigest HashSHA1::End()
|
||||
ByteArray HashSHA1::End()
|
||||
{
|
||||
UInt8 digest[SHA1_DIGEST_LENGTH];
|
||||
|
||||
SHA1_End(m_state, digest);
|
||||
|
||||
return HashDigest(GetHashName(), digest, SHA1_DIGEST_LENGTH);
|
||||
return ByteArray(digest, SHA1_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
unsigned int HashSHA1::GetDigestLength()
|
||||
unsigned int HashSHA1::GetDigestLength() const
|
||||
{
|
||||
return SHA1_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
String HashSHA1::GetHashName()
|
||||
const char* HashSHA1::GetHashName() const
|
||||
{
|
||||
static String hashName = "SHA1";
|
||||
return hashName;
|
||||
return "SHA1";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,23 +28,22 @@ namespace Nz
|
||||
SHA224_Init(m_state);
|
||||
}
|
||||
|
||||
HashDigest HashSHA224::End()
|
||||
ByteArray HashSHA224::End()
|
||||
{
|
||||
UInt8 digest[SHA224_DIGEST_LENGTH];
|
||||
|
||||
SHA224_End(m_state, digest);
|
||||
|
||||
return HashDigest(GetHashName(), digest, SHA224_DIGEST_LENGTH);
|
||||
return ByteArray(digest, SHA224_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
unsigned int HashSHA224::GetDigestLength()
|
||||
unsigned int HashSHA224::GetDigestLength() const
|
||||
{
|
||||
return SHA224_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
String HashSHA224::GetHashName()
|
||||
const char* HashSHA224::GetHashName() const
|
||||
{
|
||||
static String hashName = "SHA224";
|
||||
return hashName;
|
||||
return "SHA224";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,23 +28,22 @@ namespace Nz
|
||||
SHA256_Init(m_state);
|
||||
}
|
||||
|
||||
HashDigest HashSHA256::End()
|
||||
ByteArray HashSHA256::End()
|
||||
{
|
||||
UInt8 digest[SHA256_DIGEST_LENGTH];
|
||||
|
||||
SHA256_End(m_state, digest);
|
||||
|
||||
return HashDigest(GetHashName(), digest, SHA256_DIGEST_LENGTH);
|
||||
return ByteArray(digest, SHA256_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
unsigned int HashSHA256::GetDigestLength()
|
||||
unsigned int HashSHA256::GetDigestLength() const
|
||||
{
|
||||
return SHA256_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
String HashSHA256::GetHashName()
|
||||
const char* HashSHA256::GetHashName() const
|
||||
{
|
||||
static String hashName = "SHA256";
|
||||
return hashName;
|
||||
return "SHA256";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,23 +28,22 @@ namespace Nz
|
||||
SHA384_Init(m_state);
|
||||
}
|
||||
|
||||
HashDigest HashSHA384::End()
|
||||
ByteArray HashSHA384::End()
|
||||
{
|
||||
UInt8 digest[SHA384_DIGEST_LENGTH];
|
||||
|
||||
SHA384_End(m_state, digest);
|
||||
|
||||
return HashDigest(GetHashName(), digest, SHA384_DIGEST_LENGTH);
|
||||
return ByteArray(digest, SHA384_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
unsigned int HashSHA384::GetDigestLength()
|
||||
unsigned int HashSHA384::GetDigestLength() const
|
||||
{
|
||||
return SHA384_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
String HashSHA384::GetHashName()
|
||||
const char* HashSHA384::GetHashName() const
|
||||
{
|
||||
static String hashName = "SHA384";
|
||||
return hashName;
|
||||
return "SHA384";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,23 +28,22 @@ namespace Nz
|
||||
SHA512_Init(m_state);
|
||||
}
|
||||
|
||||
HashDigest HashSHA512::End()
|
||||
ByteArray HashSHA512::End()
|
||||
{
|
||||
UInt8 digest[SHA512_DIGEST_LENGTH];
|
||||
|
||||
SHA512_End(m_state, digest);
|
||||
|
||||
return HashDigest(GetHashName(), digest, SHA512_DIGEST_LENGTH);
|
||||
return ByteArray(digest, SHA512_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
unsigned int HashSHA512::GetDigestLength()
|
||||
unsigned int HashSHA512::GetDigestLength() const
|
||||
{
|
||||
return SHA512_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
String HashSHA512::GetHashName()
|
||||
const char* HashSHA512::GetHashName() const
|
||||
{
|
||||
static String hashName = "SHA512";
|
||||
return hashName;
|
||||
return "SHA512";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -962,7 +962,7 @@ namespace Nz
|
||||
m_state->hash[i] = 0L; // initial value
|
||||
}
|
||||
|
||||
HashDigest HashWhirlpool::End()
|
||||
ByteArray HashWhirlpool::End()
|
||||
{
|
||||
UInt8 result[64];
|
||||
|
||||
@@ -1012,17 +1012,16 @@ namespace Nz
|
||||
m_state->bufferBits = bufferBits;
|
||||
m_state->bufferPos = bufferPos;
|
||||
|
||||
return HashDigest(GetHashName(), &result[0], 64);
|
||||
return ByteArray(&result[0], 64);
|
||||
}
|
||||
|
||||
unsigned int HashWhirlpool::GetDigestLength()
|
||||
unsigned int HashWhirlpool::GetDigestLength() const
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
String HashWhirlpool::GetHashName()
|
||||
const char* HashWhirlpool::GetHashName() const
|
||||
{
|
||||
static String hashName = "Whirlpool";
|
||||
return hashName;
|
||||
return "Whirlpool";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user