diff options
author | Shauren <shauren.trinity@gmail.com> | 2014-06-03 18:15:35 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2014-06-03 18:15:35 +0200 |
commit | 7a27492071d79b036343b90ecdf1678548f3c550 (patch) | |
tree | d1f31324cb1de14cbfff11ce8780c41c57622f08 /src/server/shared/Cryptography/HmacHash.h | |
parent | c98853ca1c0f325296f509fe187b5505e32d607f (diff) |
Core/Crypto: Refactored HmacHash to make it easier to use with different hash algorithms
Diffstat (limited to 'src/server/shared/Cryptography/HmacHash.h')
-rw-r--r-- | src/server/shared/Cryptography/HmacHash.h | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/server/shared/Cryptography/HmacHash.h b/src/server/shared/Cryptography/HmacHash.h index bf82e39a526..56ee55edda2 100644 --- a/src/server/shared/Cryptography/HmacHash.h +++ b/src/server/shared/Cryptography/HmacHash.h @@ -28,21 +28,26 @@ class BigNumber; #define SEED_KEY_SIZE 16 +typedef EVP_MD const* (*HashCreateFn)(); + +template<HashCreateFn HashCreator, uint32 DigestLength> class HmacHash { public: - HmacHash(uint32 len, uint8 *seed, EVP_MD const* hasher, uint32 digestLength); + HmacHash(uint32 len, uint8 *seed); ~HmacHash(); - void UpdateData(const std::string &str); - void UpdateData(const uint8* data, size_t len); + void UpdateData(std::string const& str); + void UpdateData(uint8 const* data, size_t len); void Finalize(); uint8* ComputeHash(BigNumber* bn); uint8* GetDigest() { return _digest; } - uint32 GetLength() const { return _digestLength; } + uint32 GetLength() const { return DigestLength; } private: HMAC_CTX _ctx; - uint8* _digest; - uint32 _digestLength; + uint8 _digest[DigestLength]; }; +typedef HmacHash<EVP_sha1, SHA_DIGEST_LENGTH> HmacSha1; +typedef HmacHash<EVP_sha256, SHA256_DIGEST_LENGTH> HmacSha256; + #endif |