aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-02-23 23:18:10 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-02-23 23:18:10 +0000
commit583a7b5c74239aa9e645ea5b604e4504b323271f (patch)
treec75211ab32fbbb897808c920177e8f0c9a019f6f /src/common
parentMerge pull request #1775 (diff)
downloadmonero-583a7b5c74239aa9e645ea5b604e4504b323271f.tar.xz
core: protect precomputed block hashes with SHA256
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.cpp12
-rw-r--r--src/common/util.h1
2 files changed, 13 insertions, 0 deletions
diff --git a/src/common/util.cpp b/src/common/util.cpp
index cc2b5b8ff..046961b06 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -587,6 +587,18 @@ std::string get_nix_version_display_string()
return 0;
}
+ bool sha256sum(const uint8_t *data, size_t len, crypto::hash &hash)
+ {
+ SHA256_CTX ctx;
+ if (!SHA256_Init(&ctx))
+ return false;
+ if (!SHA256_Update(&ctx, data, len))
+ return false;
+ if (!SHA256_Final((unsigned char*)hash.data, &ctx))
+ return false;
+ return true;
+ }
+
bool sha256sum(const std::string &filename, crypto::hash &hash)
{
if (!epee::file_io_utils::is_file_exist(filename))
diff --git a/src/common/util.h b/src/common/util.h
index 1d4b3a153..4291d7e18 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -185,5 +185,6 @@ namespace tools
bool is_local_address(const std::string &address);
int vercmp(const char *v0, const char *v1); // returns < 0, 0, > 0, similar to strcmp, but more human friendly than lexical - does not attempt to validate
+ bool sha256sum(const uint8_t *data, size_t len, crypto::hash &hash);
bool sha256sum(const std::string &filename, crypto::hash &hash);
}