Added SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512 support

This commit is contained in:
Lynix
2012-05-10 00:53:36 +02:00
parent d0bc1d908a
commit 68b238fc74
23 changed files with 1621 additions and 15 deletions

View File

@@ -5,6 +5,7 @@
#include <Nazara/Core/Config.hpp>
#if NAZARA_CORE_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#include <Nazara/Core/Error.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)

View File

@@ -11,7 +11,7 @@
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
#define NAZARA_DYNLIB
#define NAZARA_CLASS_DYNLIB
#include <Nazara/Core/ThreadSafety.hpp>
class NzDynLibImpl;
@@ -40,6 +40,6 @@ class NzDynLib : NzNonCopyable
NzDynLibImpl* m_impl;
};
#undef NAZARA_DYNLIB
#undef NAZARA_CLASS_DYNLIB
#endif // NAZARA_DYNLIB_HPP

View File

@@ -2,6 +2,9 @@
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <algorithm>
#include <Nazara/Core/Debug.hpp>
inline void NzByteSwap(void* buffer, unsigned int size)
{
nzUInt8* bytes = reinterpret_cast<nzUInt8*>(buffer);
@@ -36,3 +39,5 @@ inline nzEndianness NzGetPlatformEndianness()
return endianness;
#endif
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HASH_SHA1_HPP
#define NAZARA_HASH_SHA1_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
union SHA_CTX;
class NAZARA_API NzHashSHA1 : public NzHashImpl
{
public:
NzHashSHA1();
virtual ~NzHashSHA1();
void Append(const nzUInt8* data, unsigned int len);
void Begin();
NzHashDigest End();
static unsigned int GetDigestLength();
static NzString GetHashName();
private:
SHA_CTX* m_state;
};
#endif // NAZARA_HASH_SHA1_HPP

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HASH_SHA224_HPP
#define NAZARA_HASH_SHA224_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
union SHA_CTX;
class NAZARA_API NzHashSHA224 : public NzHashImpl
{
public:
NzHashSHA224();
virtual ~NzHashSHA224();
void Append(const nzUInt8* data, unsigned int len);
void Begin();
NzHashDigest End();
static unsigned int GetDigestLength();
static NzString GetHashName();
private:
SHA_CTX* m_state;
};
#endif // NAZARA_HASH_SHA224_HPP

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HASH_SHA256_HPP
#define NAZARA_HASH_SHA256_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
union SHA_CTX;
class NAZARA_API NzHashSHA256 : public NzHashImpl
{
public:
NzHashSHA256();
virtual ~NzHashSHA256();
void Append(const nzUInt8* data, unsigned int len);
void Begin();
NzHashDigest End();
static unsigned int GetDigestLength();
static NzString GetHashName();
private:
SHA_CTX* m_state;
};
#endif // NAZARA_HASH_SHA256_HPP

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HASH_SHA384_HPP
#define NAZARA_HASH_SHA384_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
union SHA_CTX;
class NAZARA_API NzHashSHA384 : public NzHashImpl
{
public:
NzHashSHA384();
virtual ~NzHashSHA384();
void Append(const nzUInt8* data, unsigned int len);
void Begin();
NzHashDigest End();
static unsigned int GetDigestLength();
static NzString GetHashName();
private:
SHA_CTX* m_state;
};
#endif // NAZARA_HASH_SHA384_HPP

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HASH_SHA512_HPP
#define NAZARA_HASH_SHA512_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
union SHA_CTX;
class NAZARA_API NzHashSHA512 : public NzHashImpl
{
public:
NzHashSHA512();
virtual ~NzHashSHA512();
void Append(const nzUInt8* data, unsigned int len);
void Begin();
NzHashDigest End();
static unsigned int GetDigestLength();
static NzString GetHashName();
private:
SHA_CTX* m_state;
};
#endif // NAZARA_HASH_SHA512_HPP

View File

@@ -15,7 +15,7 @@ class NAZARA_API NzHashDigest
{
public:
NzHashDigest();
NzHashDigest(NzString hashName, const nzUInt8* digest, unsigned int length);
NzHashDigest(const NzString& hashName, const nzUInt8* digest, unsigned int length);
NzHashDigest(const NzHashDigest& rhs);
NzHashDigest(NzHashDigest&& rhs);
~NzHashDigest();

View File

@@ -14,6 +14,11 @@ enum nzHash
nzHash_CRC32,
nzHash_Fletcher16,
nzHash_MD5,
nzHash_SHA1,
nzHash_SHA224,
nzHash_SHA256,
nzHash_SHA384,
nzHash_SHA512,
nzHash_Whirlpool
};
@@ -27,7 +32,7 @@ class NAZARA_API NzHashable
public:
NzHashable() = default;
virtual ~NzHashable() {}
virtual ~NzHashable();
NzHashDigest GetHash(nzHash hash) const;
NzHashDigest GetHash(NzHashImpl* impl) const;