From 050efca4cc0764a985b5fd5ff6d0def0c7643298 Mon Sep 17 00:00:00 2001 From: SEK1RO Date: Wed, 11 Sep 2024 16:38:43 +0300 Subject: [PATCH] feat(sha256): uint8_t * overloading --- include/base/hash/sha256.hpp | 3 ++- src/hash/sha256.cpp | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) 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