diff options
author | Brad King <brad.king@kitware.com> | 2016-11-03 17:21:41 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-11-10 13:29:38 (GMT) |
commit | 5420278dc884c0382f271872b67c33978f3fe6b8 (patch) | |
tree | bbc69e42b2785521157da63324473b0f0d36fb64 /Source/cmUuid.cxx | |
parent | 9a596b33bbfdb274ccf7f678c78cb8826c7c363b (diff) | |
download | CMake-5420278dc884c0382f271872b67c33978f3fe6b8.zip CMake-5420278dc884c0382f271872b67c33978f3fe6b8.tar.gz CMake-5420278dc884c0382f271872b67c33978f3fe6b8.tar.bz2 |
Port hash computation to cmCryptoHash
Avoid using KWSys MD5 or `cm_sha2` and use the `cmCryptoHash`
abstraction instead.
Diffstat (limited to 'Source/cmUuid.cxx')
-rw-r--r-- | Source/cmUuid.cxx | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/Source/cmUuid.cxx b/Source/cmUuid.cxx index 904bcbb..201e1cc 100644 --- a/Source/cmUuid.cxx +++ b/Source/cmUuid.cxx @@ -2,9 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmUuid.h" -#include "cm_sha2.h" +#include "cmCryptoHash.h" -#include <cmsys/MD5.h> #include <string.h> cmUuid::cmUuid() @@ -22,16 +21,12 @@ std::string cmUuid::FromMd5(std::vector<unsigned char> const& uuidNamespace, std::vector<unsigned char> hashInput; this->CreateHashInput(uuidNamespace, name, hashInput); - cmsysMD5_s* md5 = cmsysMD5_New(); - cmsysMD5_Initialize(md5); - cmsysMD5_Append(md5, &hashInput[0], int(hashInput.size())); + cmCryptoHash md5(cmCryptoHash::AlgoMD5); + md5.Initialize(); + md5.Append(&hashInput[0], hashInput.size()); + std::vector<unsigned char> digest = md5.Finalize(); - unsigned char digest[16] = { 0 }; - cmsysMD5_Finalize(md5, digest); - - cmsysMD5_Delete(md5); - - return this->FromDigest(digest, 3); + return this->FromDigest(&digest[0], 3); } std::string cmUuid::FromSha1(std::vector<unsigned char> const& uuidNamespace, @@ -40,16 +35,12 @@ std::string cmUuid::FromSha1(std::vector<unsigned char> const& uuidNamespace, std::vector<unsigned char> hashInput; this->CreateHashInput(uuidNamespace, name, hashInput); - SHA_CTX* sha = new SHA_CTX; - SHA1_Init(sha); - SHA1_Update(sha, &hashInput[0], hashInput.size()); - - unsigned char digest[SHA1_DIGEST_LENGTH] = { 0 }; - SHA1_Final(digest, sha); - - delete sha; + cmCryptoHash sha1(cmCryptoHash::AlgoSHA1); + sha1.Initialize(); + sha1.Append(&hashInput[0], hashInput.size()); + std::vector<unsigned char> digest = sha1.Finalize(); - return this->FromDigest(digest, 5); + return this->FromDigest(&digest[0], 5); } void cmUuid::CreateHashInput(std::vector<unsigned char> const& uuidNamespace, |