feat(sha256): uint8_t * overloading

This commit is contained in:
2024-09-11 16:38:43 +03:00
parent f2d9318a45
commit 050efca4cc
2 changed files with 11 additions and 6 deletions

View File

@ -6,5 +6,6 @@
#define SHA256_DIGEST_LENGTH 32 #define SHA256_DIGEST_LENGTH 32
namespace hash { namespace hash {
std::vector<uint8_t> sha256(const std::vector<uint8_t> &data); void sha256(const uint8_t *data, uint64_t data_size, const uint8_t *hash) noexcept;
std::vector<uint8_t> sha256(const std::vector<uint8_t> &data) noexcept;
} }

View File

@ -161,15 +161,19 @@ static void sha256_final(SHA256_CTX *ctx, uint8_t *hash)
} }
} }
namespace btc::hash namespace hash
{ {
std::vector<uint8_t> sha256(const std::vector<uint8_t> &data) void sha256(const uint8_t *data, uint64_t data_size, const uint8_t *hash) noexcept
{ {
std::vector<uint8_t> hash(SHA256_DIGEST_LENGTH);
SHA256_CTX ctx; SHA256_CTX ctx;
sha256_init(&ctx); sha256_init(&ctx);
sha256_update(&ctx, data.data(), data.size()); sha256_update(&ctx, data, data_size);
sha256_final(&ctx, hash.data()); sha256_final(&ctx, hash);
}
std::vector<uint8_t> sha256(const std::vector<uint8_t> &data) noexcept
{
std::vector<uint8_t> hash(SHA256_DIGEST_LENGTH);
sha256(data.data(), data.size(), hash.data());
return hash; return hash;
} }
} }