diff --git a/include/fileutils.h b/include/fileutils.h index b058973bf1017862140ff4ad4024691eb8c80773..7539e11c62c7c03e9341f66fdbe217b04562c449 100644 --- a/include/fileutils.h +++ b/include/fileutils.h @@ -132,9 +132,6 @@ std::ofstream ofstream(const std::string& path, std::ios_base::openmode mode = s int64_t size(const std::string& path); -std::string sha3File(const std::string& path); -std::string sha3sum(const std::vector<uint8_t>& buffer); - /** * Windows compatibility wrapper for checking read-only attribute */ diff --git a/src/fileutils.cpp b/src/fileutils.cpp index c8dbdc06e62f2c3ec9f3fb255556200252a0ae44..c3aa05959a07b985bf615f1ef491edfb6c044c1c 100644 --- a/src/fileutils.cpp +++ b/src/fileutils.cpp @@ -56,8 +56,6 @@ #include <wordexp.h> #endif -#include <nettle/sha3.h> - #include <sstream> #include <fstream> #include <iostream> @@ -786,59 +784,6 @@ size(const std::string& path) return size; } -std::string -sha3File(const std::string& path) -{ - sha3_512_ctx ctx; - sha3_512_init(&ctx); - - std::ifstream file; - try { - if (!fileutils::isFile(path)) - return {}; - openStream(file, path, std::ios::binary | std::ios::in); - if (!file) - return {}; - std::vector<char> buffer(8192, 0); - while (!file.eof()) { - file.read(buffer.data(), buffer.size()); - std::streamsize readSize = file.gcount(); - sha3_512_update(&ctx, readSize, (const uint8_t*) buffer.data()); - } - file.close(); - } catch (...) { - return {}; - } - - unsigned char digest[SHA3_512_DIGEST_SIZE]; - sha3_512_digest(&ctx, SHA3_512_DIGEST_SIZE, digest); - - char hash[SHA3_512_DIGEST_SIZE * 2]; - - for (int i = 0; i < SHA3_512_DIGEST_SIZE; ++i) - pj_val_to_hex_digit(digest[i], &hash[2 * i]); - - return {hash, SHA3_512_DIGEST_SIZE * 2}; -} - -std::string -sha3sum(const std::vector<uint8_t>& buffer) -{ - sha3_512_ctx ctx; - sha3_512_init(&ctx); - sha3_512_update(&ctx, buffer.size(), (const uint8_t*) buffer.data()); - - unsigned char digest[SHA3_512_DIGEST_SIZE]; - sha3_512_digest(&ctx, SHA3_512_DIGEST_SIZE, digest); - - char hash[SHA3_512_DIGEST_SIZE * 2]; - - for (int i = 0; i < SHA3_512_DIGEST_SIZE; ++i) - pj_val_to_hex_digit(digest[i], &hash[2 * i]); - - return {hash, SHA3_512_DIGEST_SIZE * 2}; -} - int accessFile(const std::string& file, int mode) {