From 814ffcfaf34ad1d35e397eeaaafefbf03faed9cf Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 7 Jan 2020 19:21:40 +0100 Subject: hashes: Use Libgcrypt for hashing purposes Switch the code of the Hashes class to use libgcrypt, which allows us to use hardware-accelerated implementations of SHA1 and friends. --- apt-pkg/contrib/hashes.cc | 106 ++++++++++++++++++++++++++++++---------------- apt-pkg/contrib/hashes.h | 8 ++-- 2 files changed, 74 insertions(+), 40 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index 366133b02..d68919778 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -15,18 +15,30 @@ #include #include #include -#include -#include -#include #include #include #include +#include #include #include #include + +#include /*}}}*/ +static const constexpr struct HashAlgo +{ + const char *name; + int gcryAlgo; + Hashes::SupportedHashes ourAlgo; +} Algorithms[] = { + {"MD5Sum", GCRY_MD_MD5, Hashes::MD5SUM}, + {"SHA1", GCRY_MD_SHA1, Hashes::SHA1SUM}, + {"SHA256", GCRY_MD_SHA256, Hashes::SHA256SUM}, + {"SHA512", GCRY_MD_SHA512, Hashes::SHA512SUM}, +}; + const char * HashString::_SupportedHashes[] = { "SHA512", "SHA256", "SHA1", "MD5Sum", "Checksum-FileSize", NULL @@ -286,39 +298,41 @@ bool HashStringList::operator!=(HashStringList const &other) const class PrivateHashes { public: unsigned long long FileSize; - unsigned int CalcHashes; + gcry_md_hd_t hd; + + explicit PrivateHashes(unsigned int const CalcHashes) : FileSize(0) + { + gcry_md_open(&hd, 0, 0); + for (auto & Algo : Algorithms) + { + if ((CalcHashes & Algo.ourAlgo) == Algo.ourAlgo) + gcry_md_enable(hd, Algo.gcryAlgo); + } + } - explicit PrivateHashes(unsigned int const CalcHashes) : FileSize(0), CalcHashes(CalcHashes) {} explicit PrivateHashes(HashStringList const &Hashes) : FileSize(0) { - unsigned int calcHashes = Hashes.usable() ? 0 : ~0; - if (Hashes.find("MD5Sum") != NULL) - calcHashes |= Hashes::MD5SUM; - if (Hashes.find("SHA1") != NULL) - calcHashes |= Hashes::SHA1SUM; - if (Hashes.find("SHA256") != NULL) - calcHashes |= Hashes::SHA256SUM; - if (Hashes.find("SHA512") != NULL) - calcHashes |= Hashes::SHA512SUM; - CalcHashes = calcHashes; + gcry_md_open(&hd, 0, 0); + for (auto & Algo : Algorithms) + { + if (not Hashes.usable() || Hashes.find(Algo.name) != NULL) + gcry_md_enable(hd, Algo.gcryAlgo); + } + } + ~PrivateHashes() + { + gcry_md_close(hd); } }; /*}}}*/ // Hashes::Add* - Add the contents of data or FD /*{{{*/ bool Hashes::Add(const unsigned char * const Data, unsigned long long const Size) { - if (Size == 0) - return true; - bool Res = true; - if ((d->CalcHashes & MD5SUM) == MD5SUM) - Res &= MD5.Add(Data, Size); - if ((d->CalcHashes & SHA1SUM) == SHA1SUM) - Res &= SHA1.Add(Data, Size); - if ((d->CalcHashes & SHA256SUM) == SHA256SUM) - Res &= SHA256.Add(Data, Size); - if ((d->CalcHashes & SHA512SUM) == SHA512SUM) - Res &= SHA512.Add(Data, Size); - d->FileSize += Size; - return Res; + if (Size != 0) + { + gcry_md_write(d->hd, Data, Size); + d->FileSize += Size; + } + return true; } bool Hashes::AddFD(int const Fd,unsigned long long Size) { @@ -364,18 +378,38 @@ bool Hashes::AddFD(FileFd &Fd,unsigned long long Size) return true; } /*}}}*/ + +static APT_PURE std::string HexDigest(gcry_md_hd_t hd, int algo) +{ + char Conv[16] = + {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', + 'c', 'd', 'e', 'f'}; + + auto Size = gcry_md_get_algo_dlen(algo); + char Result[((Size)*2) + 1]; + Result[(Size)*2] = 0; + + auto Sum = gcry_md_read(hd, algo); + + // Convert each char into two letters + size_t J = 0; + size_t I = 0; + for (; I != (Size)*2; J++, I += 2) + { + Result[I] = Conv[Sum[J] >> 4]; + Result[I + 1] = Conv[Sum[J] & 0xF]; + } + return std::string(Result); +}; + HashStringList Hashes::GetHashStringList() { HashStringList hashes; - if ((d->CalcHashes & MD5SUM) == MD5SUM) - hashes.push_back(HashString("MD5Sum", MD5.Result().Value())); - if ((d->CalcHashes & SHA1SUM) == SHA1SUM) - hashes.push_back(HashString("SHA1", SHA1.Result().Value())); - if ((d->CalcHashes & SHA256SUM) == SHA256SUM) - hashes.push_back(HashString("SHA256", SHA256.Result().Value())); - if ((d->CalcHashes & SHA512SUM) == SHA512SUM) - hashes.push_back(HashString("SHA512", SHA512.Result().Value())); + for (auto & Algo : Algorithms) + if (gcry_md_is_enabled(d->hd, Algo.gcryAlgo)) + hashes.push_back(HashString(Algo.name, HexDigest(d->hd, Algo.gcryAlgo))); hashes.FileSize(d->FileSize); + return hashes; } Hashes::Hashes() : d(new PrivateHashes(~0)) { } diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h index e9b8a0519..14100e13b 100644 --- a/apt-pkg/contrib/hashes.h +++ b/apt-pkg/contrib/hashes.h @@ -173,10 +173,10 @@ class Hashes PrivateHashes * const d; /* TODO: those will disappear in the future as it is hard to add new ones this way. * Use Add* to build the results and get them via GetHashStringList() instead */ - MD5Summation MD5; - SHA1Summation SHA1; - SHA256Summation SHA256; - SHA512Summation SHA512; + MD5Summation MD5 APT_PKG_590("Remove"); + SHA1Summation SHA1 APT_PKG_590("Remove"); + SHA256Summation SHA256 APT_PKG_590("Remove"); + SHA512Summation SHA512 APT_PKG_590("Remove"); public: static const int UntilEOF = 0; -- cgit v1.2.3-70-g09d2 From b350560e34a369ef7610f9fceeffb00660209390 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 7 Jan 2020 19:55:48 +0100 Subject: Raise buffer size for Hashes::AddFD() from 4 KiB to 64 KiB Move APT_BUFFER_SIZE to macros.h and re-use it in hashes, this also might speed up stuff, the motivation for using 64 KiB buffers in fileutl.cc was precisely that after all. --- apt-pkg/contrib/fileutl.cc | 3 --- apt-pkg/contrib/hashes.cc | 5 +++-- apt-pkg/contrib/macros.h | 3 +++ 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index b83a4bad7..db5463be2 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -85,9 +85,6 @@ using namespace std; -/* Should be a multiple of the common page size (4096) */ -static constexpr unsigned long long APT_BUFFER_SIZE = 64 * 1024; - // RunScripts - Run a set of scripts from a configuration subtree /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index d68919778..8ddaaf549 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -336,7 +337,7 @@ bool Hashes::Add(const unsigned char * const Data, unsigned long long const Size } bool Hashes::AddFD(int const Fd,unsigned long long Size) { - unsigned char Buf[64*64]; + unsigned char Buf[APT_BUFFER_SIZE]; bool const ToEOF = (Size == UntilEOF); while (Size != 0 || ToEOF) { @@ -355,7 +356,7 @@ bool Hashes::AddFD(int const Fd,unsigned long long Size) } bool Hashes::AddFD(FileFd &Fd,unsigned long long Size) { - unsigned char Buf[64*64]; + unsigned char Buf[APT_BUFFER_SIZE]; bool const ToEOF = (Size == 0); while (Size != 0 || ToEOF) { diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index 340549fbd..7e42092f6 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -128,4 +128,7 @@ #define APT_PKG_590(msg) #endif +/* Should be a multiple of the common page size (4096) */ +static constexpr unsigned long long APT_BUFFER_SIZE = 64 * 1024; + #endif -- cgit v1.2.3-70-g09d2 From 79de3008ebfc6b4a5dd32e9de1d19788da0b885d Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 7 Jan 2020 20:36:53 +0100 Subject: Convert users of {MD5,SHA1,SHA256,SHA512}Summation to use Hashes This makes use of the a function GetHashString() that returns the specific hash string. We also need to implement another overload of Add() for signed chars with sizes, so the existing users do not require reinterpret_cast everywhere. --- apt-pkg/contrib/cdromutl.cc | 6 +++--- apt-pkg/contrib/hashes.cc | 25 +++++++++++++++++-------- apt-pkg/contrib/hashes.h | 7 +++++++ apt-pkg/deb/deblistparser.cc | 6 +++--- apt-private/private-show.cc | 5 +++-- ftparchive/multicompress.cc | 9 ++++----- ftparchive/writer.cc | 4 ++-- 7 files changed, 39 insertions(+), 23 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index 9db3980da..c0fe869d2 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include @@ -181,7 +181,7 @@ bool MountCdrom(string Path, string DeviceName) from effecting the outcome. */ bool IdentCdrom(string CD,string &Res,unsigned int Version) { - MD5Summation Hash; + Hashes Hash(Hashes::MD5SUM); bool writable_media = false; int dirfd = open(CD.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC); @@ -254,7 +254,7 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version) strprintf(S, "-%u.debug", Version); closedir(D); - Res = Hash.Result().Value().append(std::move(S)); + Res = Hash.GetHashString(Hashes::MD5SUM).HashValue().append(std::move(S)); return true; } /*}}}*/ diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index 8ddaaf549..d506a1361 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -102,27 +102,27 @@ std::string HashString::GetHashForFile(std::string filename) const /*{{{*/ FileFd Fd(filename, FileFd::ReadOnly); if(strcasecmp(Type.c_str(), "MD5Sum") == 0) { - MD5Summation MD5; + Hashes MD5(Hashes::MD5SUM); MD5.AddFD(Fd); - fileHash = (std::string)MD5.Result(); + fileHash = MD5.GetHashString(Hashes::MD5SUM).Hash; } else if (strcasecmp(Type.c_str(), "SHA1") == 0) { - SHA1Summation SHA1; + Hashes SHA1(Hashes::SHA1SUM); SHA1.AddFD(Fd); - fileHash = (std::string)SHA1.Result(); + fileHash = SHA1.GetHashString(Hashes::SHA1SUM).Hash; } else if (strcasecmp(Type.c_str(), "SHA256") == 0) { - SHA256Summation SHA256; + Hashes SHA256(Hashes::SHA256SUM); SHA256.AddFD(Fd); - fileHash = (std::string)SHA256.Result(); + fileHash = SHA256.GetHashString(Hashes::SHA256SUM).Hash; } else if (strcasecmp(Type.c_str(), "SHA512") == 0) { - SHA512Summation SHA512; + Hashes SHA512(Hashes::SHA512SUM); SHA512.AddFD(Fd); - fileHash = (std::string)SHA512.Result(); + fileHash = SHA512.GetHashString(Hashes::SHA512SUM).Hash; } else if (strcasecmp(Type.c_str(), "Checksum-FileSize") == 0) strprintf(fileHash, "%llu", Fd.FileSize()); @@ -413,6 +413,15 @@ HashStringList Hashes::GetHashStringList() return hashes; } + +HashString Hashes::GetHashString(SupportedHashes hash) +{ + for (auto & Algo : Algorithms) + if (hash == Algo.ourAlgo) + return HashString(Algo.name, HexDigest(d->hd, Algo.gcryAlgo)); + + abort(); +} Hashes::Hashes() : d(new PrivateHashes(~0)) { } Hashes::Hashes(unsigned int const Hashes) : d(new PrivateHashes(Hashes)) {} Hashes::Hashes(HashStringList const &Hashes) : d(new PrivateHashes(Hashes)) {} diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h index 14100e13b..07ccc6900 100644 --- a/apt-pkg/contrib/hashes.h +++ b/apt-pkg/contrib/hashes.h @@ -184,6 +184,10 @@ class Hashes bool Add(const unsigned char * const Data, unsigned long long const Size) APT_NONNULL(2); inline bool Add(const char * const Data) APT_NONNULL(2) {return Add(reinterpret_cast(Data),strlen(Data));}; + inline bool Add(const char *const Data, unsigned long long const Size) APT_NONNULL(2) + { + return Add(reinterpret_cast(Data), Size); + }; inline bool Add(const unsigned char * const Beg,const unsigned char * const End) APT_NONNULL(2,3) {return Add(Beg,End-Beg);}; @@ -194,6 +198,9 @@ class Hashes HashStringList GetHashStringList(); + /** Get a specific hash. It is an error to use a hash that was not hashes */ + HashString GetHashString(SupportedHashes hash); + /** create a Hashes object to calculate all supported hashes * * If ALL is too much, you can limit which Hashes are calculated diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 88b41ad30..21d1736e4 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -17,8 +17,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -298,10 +298,10 @@ APT::StringView debListParser::Description_md5() if (desc == "\n") return StringView(); - MD5Summation md5; + Hashes md5(Hashes::MD5SUM); md5.Add(desc.data(), desc.size()); md5.Add("\n"); - MD5Buffer = md5.Result(); + MD5Buffer = md5.GetHashString(Hashes::MD5SUM).HashValue(); return StringView(MD5Buffer); } else if (likely(value.size() == 32)) diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index 9ebbe6ac0..103fa57e4 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -415,9 +416,9 @@ bool ShowPackage(CommandLine &CmdL) /*{{{*/ static std::string Sha1FromString(std::string const &input) /*{{{*/ { // XXX: move to hashes.h: HashString::FromString() ? - SHA1Summation sha1; + Hashes sha1(Hashes::SHA1SUM); sha1.Add(input.c_str(), input.length()); - return sha1.Result().Value(); + return sha1.GetHashString(Hashes::SHA1SUM).HashValue(); } /*}}}*/ bool ShowSrcPackage(CommandLine &CmdL) /*{{{*/ diff --git a/ftparchive/multicompress.cc b/ftparchive/multicompress.cc index f5fe14164..cdaa7a60a 100644 --- a/ftparchive/multicompress.cc +++ b/ftparchive/multicompress.cc @@ -18,8 +18,7 @@ #include #include #include -#include -#include +#include #include #include @@ -267,7 +266,7 @@ bool MultiCompress::Child(int const &FD) SetNonBlock(FD,false); unsigned char Buffer[32*1024]; unsigned long long FileSize = 0; - MD5Summation MD5; + Hashes MD5(Hashes::MD5SUM); while (1) { WaitFd(FD,false); @@ -315,7 +314,7 @@ bool MultiCompress::Child(int const &FD) } // Compute the hash - MD5Summation OldMD5; + Hashes OldMD5(Hashes::MD5SUM); unsigned long long NewFileSize = 0; while (1) { @@ -330,7 +329,7 @@ bool MultiCompress::Child(int const &FD) CompFd.Close(); // Check the hash - if (OldMD5.Result() == MD5.Result() && + if (OldMD5.GetHashString(Hashes::MD5SUM) == MD5.GetHashString(Hashes::MD5SUM) && FileSize == NewFileSize) { for (Files *I = Outputs; I != 0; I = I->Next) diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 078638c41..edf548f3a 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -493,9 +493,9 @@ bool PackagesWriter::DoPackage(string FileName) string DescriptionMd5; if (LongDescription == false) { - MD5Summation descmd5; + Hashes descmd5(Hashes::MD5SUM); descmd5.Add(desc.c_str()); - DescriptionMd5 = descmd5.Result().Value(); + DescriptionMd5 = descmd5.GetHashString(Hashes::MD5SUM).HashValue(); Changes.push_back(pkgTagSection::Tag::Rewrite("Description-md5", DescriptionMd5)); if (TransWriter != NULL) TransWriter->DoPackage(Package, desc, DescriptionMd5); -- cgit v1.2.3-70-g09d2 From 5872a2e7dd308e49a063a20da1beb40a32d1e9b2 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 7 Jan 2020 21:05:27 +0100 Subject: Deprecate the Summation classes and mark them for removal --- apt-pkg/contrib/hashes.h | 2 ++ apt-pkg/contrib/md5.h | 2 +- apt-pkg/contrib/sha1.h | 2 +- apt-pkg/contrib/sha2.h | 4 +-- test/libapt/hashsums_test.cc | 66 +++++++++++++++++++++++--------------------- 5 files changed, 41 insertions(+), 35 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h index 07ccc6900..dad50c564 100644 --- a/apt-pkg/contrib/hashes.h +++ b/apt-pkg/contrib/hashes.h @@ -171,12 +171,14 @@ class PrivateHashes; class Hashes { PrivateHashes * const d; +APT_IGNORE_DEPRECATED_PUSH /* TODO: those will disappear in the future as it is hard to add new ones this way. * Use Add* to build the results and get them via GetHashStringList() instead */ MD5Summation MD5 APT_PKG_590("Remove"); SHA1Summation SHA1 APT_PKG_590("Remove"); SHA256Summation SHA256 APT_PKG_590("Remove"); SHA512Summation SHA512 APT_PKG_590("Remove"); +APT_IGNORE_DEPRECATED_POP public: static const int UntilEOF = 0; diff --git a/apt-pkg/contrib/md5.h b/apt-pkg/contrib/md5.h index d1287c573..de0699f6a 100644 --- a/apt-pkg/contrib/md5.h +++ b/apt-pkg/contrib/md5.h @@ -29,7 +29,7 @@ typedef HashSumValue<128> MD5SumValue; -class MD5Summation : public SummationImplementation +class APT_DEPRECATED_MSG("Use Hashes instead") APT_PKG_590("Remove") MD5Summation : public SummationImplementation { uint32_t Buf[4]; unsigned char Bytes[2*4]; diff --git a/apt-pkg/contrib/sha1.h b/apt-pkg/contrib/sha1.h index 7149da97f..5d16cbd16 100644 --- a/apt-pkg/contrib/sha1.h +++ b/apt-pkg/contrib/sha1.h @@ -18,7 +18,7 @@ typedef HashSumValue<160> SHA1SumValue; -class SHA1Summation : public SummationImplementation +class APT_DEPRECATED_MSG("Use Hashes instead") APT_PKG_590("Remove") SHA1Summation : public SummationImplementation { /* assumes 64-bit alignment just in case */ unsigned char Buffer[64] __attribute__((aligned(8))); diff --git a/apt-pkg/contrib/sha2.h b/apt-pkg/contrib/sha2.h index 5489007a2..9e179b43c 100644 --- a/apt-pkg/contrib/sha2.h +++ b/apt-pkg/contrib/sha2.h @@ -33,7 +33,7 @@ class SHA2SummationBase : public SummationImplementation void Result(); }; -class SHA256Summation : public SHA2SummationBase +class APT_DEPRECATED_MSG("Use Hashes instead") APT_PKG_590("Remove") SHA256Summation : public SHA2SummationBase { SHA256_CTX ctx; unsigned char Sum[32]; @@ -66,7 +66,7 @@ class SHA256Summation : public SHA2SummationBase }; }; -class SHA512Summation : public SHA2SummationBase +class APT_DEPRECATED_MSG("Use Hashes instead") APT_PKG_590("Remove") SHA512Summation : public SHA2SummationBase { SHA512_CTX ctx; unsigned char Sum[64]; diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index eede213cd..c50c84b90 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -29,9 +29,11 @@ TEST(HashSumsTest,SummationStrings) { #define EXPECT_SUM(Summation, In, Out) \ { \ + APT_IGNORE_DEPRECATED_PUSH \ Summation Sum; \ Sum.Add(In); \ EXPECT_EQ(Sum.Result().Value(), Out) << #Summation << " for '" << In << "'"; \ + APT_IGNORE_DEPRECATED_POP \ } // From FIPS PUB 180-1 @@ -80,6 +82,7 @@ TEST(HashSumsTest,SummationStrings) } TEST(HashSumsTest, Mill) { +APT_IGNORE_DEPRECATED_PUSH SHA1Summation Sum1; const unsigned char As[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; @@ -100,6 +103,7 @@ TEST(HashSumsTest, Mill) } EXPECT_EQ("34aa973cd4c4daa4f61eeb2bdbad27316534016f", Sum1.Result().Value()); +APT_IGNORE_DEPRECATED_POP } static void getSummationString(char const * const type, std::string &sum) @@ -146,20 +150,20 @@ TEST(HashSumsTest, FileBased) std::string summation; getSummationString("md5sum", summation); - MD5SumValue md5(summation); - EXPECT_EQ(md5.Value(), summation); + HashString md5("MD5Sum", summation); + EXPECT_EQ(md5.HashValue(), summation); getSummationString("sha1sum", summation); - SHA1SumValue sha1(summation); - EXPECT_EQ(sha1.Value(), summation); + HashString sha1("SHA1", summation); + EXPECT_EQ(sha1.HashValue(), summation); getSummationString("sha256sum", summation); - SHA256SumValue sha256(summation); - EXPECT_EQ(sha256.Value(), summation); + HashString sha256("SHA256", summation); + EXPECT_EQ(sha256.HashValue(), summation); getSummationString("sha512sum", summation); - SHA512SumValue sha512(summation); - EXPECT_EQ(sha512.Value(), summation); + HashString sha512("SHA512", summation); + EXPECT_EQ(sha512.HashValue(), summation); FileFd fd("/etc/os-release", FileFd::ReadOnly); EXPECT_TRUE(fd.IsOpen()); @@ -172,10 +176,10 @@ TEST(HashSumsTest, FileBased) HashStringList list = hashes.GetHashStringList(); EXPECT_FALSE(list.empty()); EXPECT_EQ(5u, list.size()); - EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); - EXPECT_EQ(sha1.Value(), list.find("SHA1")->HashValue()); - EXPECT_EQ(sha256.Value(), list.find("SHA256")->HashValue()); - EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(md5.HashValue(), list.find("MD5Sum")->HashValue()); + EXPECT_EQ(sha1.HashValue(), list.find("SHA1")->HashValue()); + EXPECT_EQ(sha256.HashValue(), list.find("SHA256")->HashValue()); + EXPECT_EQ(sha512.HashValue(), list.find("SHA512")->HashValue()); EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); } unsigned long long sz = fd.FileSize(); @@ -186,10 +190,10 @@ TEST(HashSumsTest, FileBased) HashStringList list = hashes.GetHashStringList(); EXPECT_FALSE(list.empty()); EXPECT_EQ(5u, list.size()); - EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); - EXPECT_EQ(sha1.Value(), list.find("SHA1")->HashValue()); - EXPECT_EQ(sha256.Value(), list.find("SHA256")->HashValue()); - EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(md5.HashValue(), list.find("MD5Sum")->HashValue()); + EXPECT_EQ(sha1.HashValue(), list.find("SHA1")->HashValue()); + EXPECT_EQ(sha256.HashValue(), list.find("SHA256")->HashValue()); + EXPECT_EQ(sha512.HashValue(), list.find("SHA512")->HashValue()); EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); } fd.Seek(0); @@ -199,10 +203,10 @@ TEST(HashSumsTest, FileBased) HashStringList list = hashes.GetHashStringList(); EXPECT_FALSE(list.empty()); EXPECT_EQ(3u, list.size()); - EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); + EXPECT_EQ(md5.HashValue(), list.find("MD5Sum")->HashValue()); EXPECT_EQ(NULL, list.find("SHA1")); EXPECT_EQ(NULL, list.find("SHA256")); - EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(sha512.HashValue(), list.find("SHA512")->HashValue()); EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); fd.Seek(0); Hashes hashes2(list); @@ -210,39 +214,39 @@ TEST(HashSumsTest, FileBased) list = hashes2.GetHashStringList(); EXPECT_FALSE(list.empty()); EXPECT_EQ(3u, list.size()); - EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); + EXPECT_EQ(md5.HashValue(), list.find("MD5Sum")->HashValue()); EXPECT_EQ(NULL, list.find("SHA1")); EXPECT_EQ(NULL, list.find("SHA256")); - EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(sha512.HashValue(), list.find("SHA512")->HashValue()); EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); } fd.Seek(0); { - MD5Summation MD5; + Hashes MD5(Hashes::MD5SUM); MD5.AddFD(fd.Fd()); - EXPECT_EQ(md5.Value(), MD5.Result().Value()); + EXPECT_EQ(md5, MD5.GetHashString(Hashes::MD5SUM)); } fd.Seek(0); { - SHA1Summation SHA1; + Hashes SHA1(Hashes::SHA1SUM); SHA1.AddFD(fd.Fd()); - EXPECT_EQ(sha1.Value(), SHA1.Result().Value()); + EXPECT_EQ(sha1, SHA1.GetHashString(Hashes::SHA1SUM)); } fd.Seek(0); { - SHA256Summation SHA2; + Hashes SHA2(Hashes::SHA256SUM); SHA2.AddFD(fd.Fd()); - EXPECT_EQ(sha256.Value(), SHA2.Result().Value()); + EXPECT_EQ(sha256, SHA2.GetHashString(Hashes::SHA256SUM)); } fd.Seek(0); { - SHA512Summation SHA2; + Hashes SHA2(Hashes::SHA512SUM); SHA2.AddFD(fd.Fd()); - EXPECT_EQ(sha512.Value(), SHA2.Result().Value()); + EXPECT_EQ(sha512, SHA2.GetHashString(Hashes::SHA512SUM)); } fd.Close(); - HashString sha2file("SHA512", sha512.Value()); + HashString sha2file("SHA512", sha512.HashValue()); EXPECT_TRUE(sha2file.VerifyFile("/etc/os-release")); HashString sha2wrong("SHA512", "00000000000"); EXPECT_FALSE(sha2wrong.VerifyFile("/etc/os-release")); @@ -251,9 +255,9 @@ TEST(HashSumsTest, FileBased) EXPECT_NE(sha2file, sha2wrong); EXPECT_TRUE(sha2file != sha2wrong); - HashString sha2big("SHA256", sha256.Value()); + HashString sha2big("SHA256", sha256.HashValue()); EXPECT_TRUE(sha2big.VerifyFile("/etc/os-release")); - HashString sha2small("sha256:" + sha256.Value()); + HashString sha2small("sha256:" + sha256.HashValue()); EXPECT_TRUE(sha2small.VerifyFile("/etc/os-release")); EXPECT_EQ(sha2big, sha2small); EXPECT_TRUE(sha2big == sha2small); -- cgit v1.2.3-70-g09d2 From 8c1a37e12790a23f3b132899485e011f9134b483 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 7 Jan 2020 21:21:35 +0100 Subject: Remove includes of (md5|sha1|sha2).h headers Remove it everywhere, except where it is still needed. --- apt-pkg/acquire-method.cc | 3 --- apt-pkg/contrib/sha256.h | 1 - apt-pkg/deb/deblistparser.h | 1 - apt-pkg/edsp/edsplistparser.cc | 2 +- apt-pkg/edsp/edsplistparser.h | 1 - apt-pkg/pkgcachegen.cc | 1 - apt-pkg/pkgcachegen.h | 1 - cmdline/apt-get.cc | 1 - ftparchive/cachedb.cc | 3 --- ftparchive/writer.cc | 3 --- 10 files changed, 1 insertion(+), 16 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc index f2a61a144..9656caf14 100644 --- a/apt-pkg/acquire-method.cc +++ b/apt-pkg/acquire-method.cc @@ -21,9 +21,6 @@ #include #include #include -#include -#include -#include #include #include diff --git a/apt-pkg/contrib/sha256.h b/apt-pkg/contrib/sha256.h index 15146c948..93b2bc09e 100644 --- a/apt-pkg/contrib/sha256.h +++ b/apt-pkg/contrib/sha256.h @@ -1,7 +1,6 @@ #ifndef APTPKG_SHA256_H #define APTPKG_SHA256_H -#include "sha2.h" #warning "This header is deprecated, please include sha2.h instead" diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index c041585e6..a04187c45 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -11,7 +11,6 @@ #define PKGLIB_DEBLISTPARSER_H #include -#include #include #include #include diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc index 31bded9ca..96de2b997 100644 --- a/apt-pkg/edsp/edsplistparser.cc +++ b/apt-pkg/edsp/edsplistparser.cc @@ -15,10 +15,10 @@ #include #include #include -#include #include #include #include +#include #include #include diff --git a/apt-pkg/edsp/edsplistparser.h b/apt-pkg/edsp/edsplistparser.h index 6087e77e6..2c136026d 100644 --- a/apt-pkg/edsp/edsplistparser.h +++ b/apt-pkg/edsp/edsplistparser.h @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 183750acb..75bd4c853 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index 2db2237da..55bf57418 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -19,7 +19,6 @@ #define PKGLIB_PKGCACHEGEN_H #include -#include #include #include diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 5d81c08a4..efb5cfd73 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc index 1890c28d0..dedb01eaa 100644 --- a/ftparchive/cachedb.cc +++ b/ftparchive/cachedb.cc @@ -17,9 +17,6 @@ #include #include #include -#include -#include -#include #include #include diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index edf548f3a..5dcb98c9c 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -19,10 +19,7 @@ #include #include #include -#include #include -#include -#include #include #include -- cgit v1.2.3-70-g09d2