Core/Crypto: moved away from deprecated SHA1 methods in CalculateSHA1Hash
This commit is contained in:
1 parent
ca37a71c3a
commit
228e3059c9
2 files changed
+18
-12
No files matched your search
@@ -20,8 +20,9 @@
|
||||
#include "Util.h"
|
||||
#include <cstring>
|
||||
#include <stdarg.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
SHA1Hash::SHA1Hash()
|
||||
SHA1Hash::SHA1Hash() noexcept
|
||||
{
|
||||
m_ctx = EVP_MD_CTX_new();
|
||||
EVP_DigestInit_ex(m_ctx, EVP_sha1(), nullptr);
|
||||
@@ -33,7 +34,7 @@ SHA1Hash::SHA1Hash(const SHA1Hash &other) : SHA1Hash() // copy
|
||||
std::memcpy(m_digest, other.m_digest, SHA_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
SHA1Hash::SHA1Hash(SHA1Hash &&other) : SHA1Hash() // move
|
||||
SHA1Hash::SHA1Hash(SHA1Hash &&other) noexcept : SHA1Hash() // move
|
||||
{
|
||||
Swap(other);
|
||||
}
|
||||
@@ -93,8 +94,13 @@ void SHA1Hash::Finalize(void)
|
||||
|
||||
std::string CalculateSHA1Hash(std::string const& content)
|
||||
{
|
||||
unsigned char digest[SHA_DIGEST_LENGTH];
|
||||
SHA1((unsigned char*)content.c_str(), content.length(), (unsigned char*)&digest);
|
||||
EVP_MD_CTX* mdctx = EVP_MD_CTX_new();
|
||||
EVP_DigestInit_ex(mdctx, EVP_sha1(), nullptr);
|
||||
EVP_DigestUpdate(mdctx, content.c_str(), content.size());
|
||||
uint8 digest[SHA_DIGEST_LENGTH];
|
||||
uint32 shaDigestLength = SHA_DIGEST_LENGTH;
|
||||
EVP_DigestFinal_ex(mdctx, digest, &shaDigestLength);
|
||||
EVP_MD_CTX_free(mdctx);
|
||||
|
||||
return ByteArrayToHexStr(digest, SHA_DIGEST_LENGTH);
|
||||
}
|
||||
@@ -28,19 +28,19 @@ class BigNumber;
|
||||
class TC_COMMON_API SHA1Hash
|
||||
{
|
||||
public:
|
||||
SHA1Hash();
|
||||
SHA1Hash(SHA1Hash const &other); // copy
|
||||
SHA1Hash(SHA1Hash &&other); // move
|
||||
SHA1Hash() noexcept;
|
||||
SHA1Hash(SHA1Hash const& other); // copy
|
||||
SHA1Hash(SHA1Hash&& other) noexcept; // move
|
||||
SHA1Hash &operator=(SHA1Hash other); // assign
|
||||
~SHA1Hash();
|
||||
|
||||
void Swap(SHA1Hash &other) throw();
|
||||
friend void Swap(SHA1Hash &left, SHA1Hash &right) { left.Swap(right); }
|
||||
void Swap(SHA1Hash& other) throw();
|
||||
friend void Swap(SHA1Hash& left, SHA1Hash &right) { left.Swap(right); }
|
||||
|
||||
void UpdateBigNumbers(BigNumber* bn0, ...);
|
||||
|
||||
void UpdateData(const uint8 *dta, int len);
|
||||
void UpdateData(const std::string &str);
|
||||
void UpdateData(const uint8* dta, int len);
|
||||
void UpdateData(const std::string& str);
|
||||
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
@@ -49,7 +49,7 @@ class TC_COMMON_API SHA1Hash
|
||||
int GetLength() const { return SHA_DIGEST_LENGTH; }
|
||||
|
||||
private:
|
||||
EVP_MD_CTX *m_ctx;
|
||||
EVP_MD_CTX* m_ctx;
|
||||
uint8 m_digest[SHA_DIGEST_LENGTH];
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user