diff --git a/include/base/hash/sha256.hpp b/include/base/hash/sha256.hpp index c2e51f3..e08be57 100644 --- a/include/base/hash/sha256.hpp +++ b/include/base/hash/sha256.hpp @@ -6,5 +6,6 @@ #define SHA256_DIGEST_LENGTH 32 namespace hash { - std::vector sha256(const std::vector &data); + void sha256(const uint8_t *data, uint64_t data_size, const uint8_t *hash) noexcept; + std::vector sha256(const std::vector &data) noexcept; } \ No newline at end of file diff --git a/src/hash/sha256.cpp b/src/hash/sha256.cpp index fd4d82a..0703130 100644 --- a/src/hash/sha256.cpp +++ b/src/hash/sha256.cpp @@ -161,15 +161,19 @@ static void sha256_final(SHA256_CTX *ctx, uint8_t *hash) } } -namespace btc::hash +namespace hash { - std::vector sha256(const std::vector &data) + void sha256(const uint8_t *data, uint64_t data_size, const uint8_t *hash) noexcept { - std::vector hash(SHA256_DIGEST_LENGTH); SHA256_CTX ctx; sha256_init(&ctx); - sha256_update(&ctx, data.data(), data.size()); - sha256_final(&ctx, hash.data()); + sha256_update(&ctx, data, data_size); + sha256_final(&ctx, hash); + } + std::vector sha256(const std::vector &data) noexcept + { + std::vector hash(SHA256_DIGEST_LENGTH); + sha256(data.data(), data.size(), hash.data()); return hash; } } \ No newline at end of file