45 lines
967 B
C++
45 lines
967 B
C++
#include "HashUtils.h"
|
|
|
|
#include <cryptopp/sha.h>
|
|
#include <cryptopp/files.h>
|
|
#include <cryptopp/hex.h>
|
|
|
|
using CryptoPP::SHA256;
|
|
using CryptoPP::FileSource;
|
|
using CryptoPP::HashFilter;
|
|
using CryptoPP::HexEncoder;
|
|
using CryptoPP::StringSink;
|
|
namespace fs = boost::filesystem;
|
|
|
|
std::string calcSHA256(const fs::path& file)
|
|
{
|
|
SHA256 hash;
|
|
std::string digest;
|
|
|
|
FileSource f(
|
|
file.native().c_str(),
|
|
true,
|
|
new HashFilter(
|
|
hash,
|
|
new HexEncoder(
|
|
new StringSink(
|
|
digest))));
|
|
|
|
return digest;
|
|
}
|
|
|
|
uint64_t fletcher64(uint32_t *data, int count)
|
|
{
|
|
uint64_t sum1 = 0;
|
|
uint64_t sum2 = 0;
|
|
int index;
|
|
|
|
for (index = 0; index < count; ++index)
|
|
{
|
|
sum1 = (sum1 + data[index]) % std::numeric_limits<uint32_t>::max();
|
|
sum2 = (sum2 + sum1) % std::numeric_limits<uint32_t>::max();
|
|
}
|
|
|
|
return (sum2 << std::numeric_limits<uint32_t>::digits) | sum1;
|
|
}
|