mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 07:11:52 +08:00
Port hash computation to cmCryptoHash
Avoid using KWSys MD5 or `cm_sha2` and use the `cmCryptoHash` abstraction instead.
This commit is contained in:
@@ -1060,8 +1060,8 @@ std::string cmCPackWIXGenerator::CreateNewIdForPath(std::string const& path)
|
|||||||
std::string cmCPackWIXGenerator::CreateHashedId(
|
std::string cmCPackWIXGenerator::CreateHashedId(
|
||||||
std::string const& path, std::string const& normalizedFilename)
|
std::string const& path, std::string const& normalizedFilename)
|
||||||
{
|
{
|
||||||
CM_AUTO_PTR<cmCryptoHash> sha1 = cmCryptoHash::New("SHA1");
|
cmCryptoHash sha1(cmCryptoHash::AlgoSHA1);
|
||||||
std::string hash = sha1->HashString(path.c_str());
|
std::string const hash = sha1.HashString(path);
|
||||||
|
|
||||||
std::string identifier;
|
std::string identifier;
|
||||||
identifier += hash.substr(0, 7) + "_";
|
identifier += hash.substr(0, 7) + "_";
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <cmConfigure.h>
|
#include <cmConfigure.h>
|
||||||
|
|
||||||
|
#include "cmCryptoHash.h"
|
||||||
#include "cmGeneratedFileStream.h"
|
#include "cmGeneratedFileStream.h"
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
@@ -14,7 +15,6 @@
|
|||||||
|
|
||||||
#include <cm_auto_ptr.hxx>
|
#include <cm_auto_ptr.hxx>
|
||||||
#include <cmsys/FStream.hxx>
|
#include <cmsys/FStream.hxx>
|
||||||
#include <cmsys/MD5.h>
|
|
||||||
#include <cmsys/Process.h>
|
#include <cmsys/Process.h>
|
||||||
#include <cmsys/RegularExpression.hxx>
|
#include <cmsys/RegularExpression.hxx>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -167,17 +167,14 @@ void cmCTestLaunch::ComputeFileNames()
|
|||||||
|
|
||||||
// We hash the input command working dir and command line to obtain
|
// We hash the input command working dir and command line to obtain
|
||||||
// a repeatable and (probably) unique name for log files.
|
// a repeatable and (probably) unique name for log files.
|
||||||
char hash[32];
|
cmCryptoHash md5(cmCryptoHash::AlgoMD5);
|
||||||
cmsysMD5* md5 = cmsysMD5_New();
|
md5.Initialize();
|
||||||
cmsysMD5_Initialize(md5);
|
md5.Append(this->CWD);
|
||||||
cmsysMD5_Append(md5, (unsigned char const*)(this->CWD.c_str()), -1);
|
|
||||||
for (std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
|
for (std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
|
||||||
ai != this->RealArgs.end(); ++ai) {
|
ai != this->RealArgs.end(); ++ai) {
|
||||||
cmsysMD5_Append(md5, (unsigned char const*)ai->c_str(), -1);
|
md5.Append(*ai);
|
||||||
}
|
}
|
||||||
cmsysMD5_FinalizeHex(md5, hash);
|
this->LogHash = md5.FinalizeHex();
|
||||||
cmsysMD5_Delete(md5);
|
|
||||||
this->LogHash.assign(hash, 32);
|
|
||||||
|
|
||||||
// We store stdout and stderr in temporary log files.
|
// We store stdout and stderr in temporary log files.
|
||||||
this->LogOut = this->LogDir;
|
this->LogOut = this->LogDir;
|
||||||
|
@@ -2553,7 +2553,8 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
|
|||||||
this->SetError("DOWNLOAD missing sum value for EXPECTED_MD5.");
|
this->SetError("DOWNLOAD missing sum value for EXPECTED_MD5.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
hash = CM_AUTO_PTR<cmCryptoHash>(cmCryptoHash::New("MD5"));
|
hash =
|
||||||
|
CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(cmCryptoHash::AlgoMD5));
|
||||||
hashMatchMSG = "MD5 sum";
|
hashMatchMSG = "MD5 sum";
|
||||||
expectedHash = cmSystemTools::LowerCase(*i);
|
expectedHash = cmSystemTools::LowerCase(*i);
|
||||||
} else if (*i == "SHOW_PROGRESS") {
|
} else if (*i == "SHOW_PROGRESS") {
|
||||||
|
@@ -107,8 +107,8 @@ std::string cmFilePathUuid::GetChecksumString(
|
|||||||
{
|
{
|
||||||
// Calculate the file ( seed + relative path + name ) checksum
|
// Calculate the file ( seed + relative path + name ) checksum
|
||||||
std::vector<unsigned char> hashBytes =
|
std::vector<unsigned char> hashBytes =
|
||||||
cmCryptoHash::New("SHA256")->ByteHashString(
|
cmCryptoHash(cmCryptoHash::AlgoSHA256)
|
||||||
sourceRelSeed + sourceRelPath + sourceFilename);
|
.ByteHashString(sourceRelSeed + sourceRelPath + sourceFilename);
|
||||||
|
|
||||||
checksumBase32 =
|
checksumBase32 =
|
||||||
cmBase32Encoder().encodeString(&hashBytes[0], hashBytes.size(), false);
|
cmBase32Encoder().encodeString(&hashBytes[0], hashBytes.size(), false);
|
||||||
|
@@ -44,9 +44,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
|
#include "cmCryptoHash.h"
|
||||||
#include <cm_jsoncpp_value.h>
|
#include <cm_jsoncpp_value.h>
|
||||||
#include <cm_jsoncpp_writer.h>
|
#include <cm_jsoncpp_writer.h>
|
||||||
#include <cmsys/MD5.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class cmInstalledFile;
|
class cmInstalledFile;
|
||||||
@@ -2616,14 +2616,9 @@ void cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
|
|||||||
// Compute a hash of the rule.
|
// Compute a hash of the rule.
|
||||||
RuleHash hash;
|
RuleHash hash;
|
||||||
{
|
{
|
||||||
unsigned char const* data =
|
cmCryptoHash md5(cmCryptoHash::AlgoMD5);
|
||||||
reinterpret_cast<unsigned char const*>(content.c_str());
|
std::string const md5_hex = md5.HashString(content);
|
||||||
int length = static_cast<int>(content.length());
|
memcpy(hash.Data, md5_hex.c_str(), 32);
|
||||||
cmsysMD5* sum = cmsysMD5_New();
|
|
||||||
cmsysMD5_Initialize(sum);
|
|
||||||
cmsysMD5_Append(sum, data, length);
|
|
||||||
cmsysMD5_FinalizeHex(sum, hash.Data);
|
|
||||||
cmsysMD5_Delete(sum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shorten the output name (in expected use case).
|
// Shorten the output name (in expected use case).
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
#define CM_LG_ENCODE_OBJECT_NAMES
|
#define CM_LG_ENCODE_OBJECT_NAMES
|
||||||
#include <cmsys/MD5.h>
|
#include "cmCryptoHash.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -2001,17 +2001,6 @@ void cmLocalGenerator::GenerateTargetInstallRules(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CM_LG_ENCODE_OBJECT_NAMES)
|
#if defined(CM_LG_ENCODE_OBJECT_NAMES)
|
||||||
static std::string cmLocalGeneratorMD5(const char* input)
|
|
||||||
{
|
|
||||||
char md5out[32];
|
|
||||||
cmsysMD5* md5 = cmsysMD5_New();
|
|
||||||
cmsysMD5_Initialize(md5);
|
|
||||||
cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
|
|
||||||
cmsysMD5_FinalizeHex(md5, md5out);
|
|
||||||
cmsysMD5_Delete(md5);
|
|
||||||
return std::string(md5out, 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool cmLocalGeneratorShortenObjectName(std::string& objName,
|
static bool cmLocalGeneratorShortenObjectName(std::string& objName,
|
||||||
std::string::size_type max_len)
|
std::string::size_type max_len)
|
||||||
{
|
{
|
||||||
@@ -2020,7 +2009,8 @@ static bool cmLocalGeneratorShortenObjectName(std::string& objName,
|
|||||||
std::string::size_type pos =
|
std::string::size_type pos =
|
||||||
objName.find('/', objName.size() - max_len + 32);
|
objName.find('/', objName.size() - max_len + 32);
|
||||||
if (pos != objName.npos) {
|
if (pos != objName.npos) {
|
||||||
std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
|
cmCryptoHash md5(cmCryptoHash::AlgoMD5);
|
||||||
|
std::string md5name = md5.HashString(objName.substr(0, pos));
|
||||||
md5name += objName.substr(pos);
|
md5name += objName.substr(pos);
|
||||||
objName = md5name;
|
objName = md5name;
|
||||||
|
|
||||||
|
@@ -847,8 +847,8 @@ bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
|
|||||||
bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
|
bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
|
||||||
{
|
{
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
CM_AUTO_PTR<cmCryptoHash> md5 = cmCryptoHash::New("MD5");
|
cmCryptoHash md5(cmCryptoHash::AlgoMD5);
|
||||||
std::string str = md5->HashFile(source);
|
std::string const str = md5.HashFile(source);
|
||||||
strncpy(md5out, str.c_str(), 32);
|
strncpy(md5out, str.c_str(), 32);
|
||||||
return !str.empty();
|
return !str.empty();
|
||||||
#else
|
#else
|
||||||
@@ -863,8 +863,8 @@ bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
|
|||||||
std::string cmSystemTools::ComputeStringMD5(const std::string& input)
|
std::string cmSystemTools::ComputeStringMD5(const std::string& input)
|
||||||
{
|
{
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
CM_AUTO_PTR<cmCryptoHash> md5 = cmCryptoHash::New("MD5");
|
cmCryptoHash md5(cmCryptoHash::AlgoMD5);
|
||||||
return md5->HashString(input);
|
return md5.HashString(input);
|
||||||
#else
|
#else
|
||||||
(void)input;
|
(void)input;
|
||||||
cmSystemTools::Message("md5sum not supported in bootstrapping mode",
|
cmSystemTools::Message("md5sum not supported in bootstrapping mode",
|
||||||
|
@@ -2,9 +2,8 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
#include "cmUuid.h"
|
#include "cmUuid.h"
|
||||||
|
|
||||||
#include "cm_sha2.h"
|
#include "cmCryptoHash.h"
|
||||||
|
|
||||||
#include <cmsys/MD5.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
cmUuid::cmUuid()
|
cmUuid::cmUuid()
|
||||||
@@ -22,16 +21,12 @@ std::string cmUuid::FromMd5(std::vector<unsigned char> const& uuidNamespace,
|
|||||||
std::vector<unsigned char> hashInput;
|
std::vector<unsigned char> hashInput;
|
||||||
this->CreateHashInput(uuidNamespace, name, hashInput);
|
this->CreateHashInput(uuidNamespace, name, hashInput);
|
||||||
|
|
||||||
cmsysMD5_s* md5 = cmsysMD5_New();
|
cmCryptoHash md5(cmCryptoHash::AlgoMD5);
|
||||||
cmsysMD5_Initialize(md5);
|
md5.Initialize();
|
||||||
cmsysMD5_Append(md5, &hashInput[0], int(hashInput.size()));
|
md5.Append(&hashInput[0], hashInput.size());
|
||||||
|
std::vector<unsigned char> digest = md5.Finalize();
|
||||||
|
|
||||||
unsigned char digest[16] = { 0 };
|
return this->FromDigest(&digest[0], 3);
|
||||||
cmsysMD5_Finalize(md5, digest);
|
|
||||||
|
|
||||||
cmsysMD5_Delete(md5);
|
|
||||||
|
|
||||||
return this->FromDigest(digest, 3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cmUuid::FromSha1(std::vector<unsigned char> const& uuidNamespace,
|
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;
|
std::vector<unsigned char> hashInput;
|
||||||
this->CreateHashInput(uuidNamespace, name, hashInput);
|
this->CreateHashInput(uuidNamespace, name, hashInput);
|
||||||
|
|
||||||
SHA_CTX* sha = new SHA_CTX;
|
cmCryptoHash sha1(cmCryptoHash::AlgoSHA1);
|
||||||
SHA1_Init(sha);
|
sha1.Initialize();
|
||||||
SHA1_Update(sha, &hashInput[0], hashInput.size());
|
sha1.Append(&hashInput[0], hashInput.size());
|
||||||
|
std::vector<unsigned char> digest = sha1.Finalize();
|
||||||
|
|
||||||
unsigned char digest[SHA1_DIGEST_LENGTH] = { 0 };
|
return this->FromDigest(&digest[0], 5);
|
||||||
SHA1_Final(digest, sha);
|
|
||||||
|
|
||||||
delete sha;
|
|
||||||
|
|
||||||
return this->FromDigest(digest, 5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmUuid::CreateHashInput(std::vector<unsigned char> const& uuidNamespace,
|
void cmUuid::CreateHashInput(std::vector<unsigned char> const& uuidNamespace,
|
||||||
|
Reference in New Issue
Block a user