mirror of
https://github.com/falcosecurity/falco.git
synced 2025-08-25 17:38:53 +00:00
chore: avoid deprecated funcs to calculate sha256
Signed-off-by: Federico Aponte <federico.aponte@sysdig.com>
This commit is contained in:
parent
3277d6e00b
commit
ec2c2e801e
@ -23,7 +23,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include <re2/re2.h>
|
#include <re2/re2.h>
|
||||||
#if defined(__linux__) and !defined(MINIMAL_BUILD) and !defined(__EMSCRIPTEN__)
|
#if defined(__linux__) and !defined(MINIMAL_BUILD) and !defined(__EMSCRIPTEN__)
|
||||||
#include <openssl/sha.h>
|
#include <openssl/evp.h>
|
||||||
#endif
|
#endif
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -144,22 +144,22 @@ std::string calculate_file_sha256sum(const std::string& filename) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
SHA256_CTX sha256_context;
|
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)> ctx(EVP_MD_CTX_new(), EVP_MD_CTX_free);
|
||||||
SHA256_Init(&sha256_context);
|
EVP_DigestInit_ex(ctx.get(), EVP_sha256(), nullptr);
|
||||||
|
|
||||||
constexpr size_t buffer_size = 4096;
|
constexpr size_t buffer_size = 4096;
|
||||||
char buffer[buffer_size];
|
char buffer[buffer_size];
|
||||||
while(file.read(buffer, buffer_size)) {
|
while(file.read(buffer, buffer_size)) {
|
||||||
SHA256_Update(&sha256_context, buffer, buffer_size);
|
EVP_DigestUpdate(ctx.get(), buffer, buffer_size);
|
||||||
}
|
}
|
||||||
SHA256_Update(&sha256_context, buffer, file.gcount());
|
EVP_DigestUpdate(ctx.get(), buffer, file.gcount());
|
||||||
|
|
||||||
unsigned char digest[SHA256_DIGEST_LENGTH];
|
std::vector<uint8_t> digest(EVP_MD_size(EVP_sha256()));
|
||||||
SHA256_Final(digest, &sha256_context);
|
EVP_DigestFinal_ex(ctx.get(), digest.data(), nullptr);
|
||||||
|
|
||||||
std::stringstream ss;
|
std::ostringstream ss;
|
||||||
for(int i = 0; i < SHA256_DIGEST_LENGTH; ++i) {
|
for(auto& c : digest) {
|
||||||
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned>(digest[i]);
|
ss << std::hex << std::setw(2) << std::setfill('0') << (int)c;
|
||||||
}
|
}
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user