Skip to content

Commit f125ec4

Browse files
committed
Add in calls to finalize
1 parent 7aefb57 commit f125ec4

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

include/boost/crypt2/hash/sha512.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ BOOST_CRYPT_EXPORT BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha512(compat::span<co
2222
{
2323
sha512_hasher hasher;
2424
hasher.process_bytes(data);
25+
hasher.finalize();
2526
return hasher.get_digest();
2627
}
2728

@@ -30,6 +31,7 @@ BOOST_CRYPT_EXPORT BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha512(SizedRange&& da
3031
{
3132
sha512_hasher hasher;
3233
hasher.process_bytes(data);
34+
hasher.finalize();
3335
return hasher.get_digest();
3436
}
3537

@@ -56,6 +58,7 @@ inline auto sha512_file_impl(detail::file_reader<64U>& reader) -> sha512_hasher:
5658
hasher.process_bytes(buffer_span);
5759
}
5860

61+
hasher.finalize();
5962
return hasher.get_digest();
6063
}
6164

test/test_sha512.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ void string_view_test()
125125
boost::crypt::sha512_hasher hasher;
126126
const auto current_state = hasher.process_bytes(string_view_message);
127127
BOOST_TEST(current_state == boost::crypt::state::success);
128+
hasher.finalize();
128129
const auto result2 = hasher.get_digest();
129130
for (std::size_t i {}; i < message_result.size(); ++i)
130131
{
@@ -149,6 +150,7 @@ void test_class()
149150
hasher.init();
150151
const auto msg {std::get<0>(test_value)};
151152
hasher.process_bytes(msg);
153+
hasher.finalize();
152154
const auto message_result {hasher.get_digest()};
153155

154156
const auto valid_result {std::get<1>(test_value)};
@@ -272,19 +274,32 @@ void files_test()
272274
consteval bool immediate_test()
273275
{
274276
constexpr std::array<std::byte, 3> vals = {std::byte{0x61}, std::byte{0x62}, std::byte{0x63}};
275-
const auto expected_res = std::array<std::uint8_t, 64>{0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba, 0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31, 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2, 0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a, 0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8, 0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd, 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e, 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f};
277+
constexpr std::array<std::byte, 64> expected_res {
278+
std::byte{0xdd}, std::byte{0xaf}, std::byte{0x35}, std::byte{0xa1}, std::byte{0x93}, std::byte{0x61},
279+
std::byte{0x7a}, std::byte{0xba}, std::byte{0xcc}, std::byte{0x41}, std::byte{0x73}, std::byte{0x49},
280+
std::byte{0xae}, std::byte{0x20}, std::byte{0x41}, std::byte{0x31}, std::byte{0x12}, std::byte{0xe6},
281+
std::byte{0xfa}, std::byte{0x4e}, std::byte{0x89}, std::byte{0xa9}, std::byte{0x7e}, std::byte{0xa2},
282+
std::byte{0x0a}, std::byte{0x9e}, std::byte{0xee}, std::byte{0xe6}, std::byte{0x4b}, std::byte{0x55},
283+
std::byte{0xd3}, std::byte{0x9a}, std::byte{0x21}, std::byte{0x92}, std::byte{0x99}, std::byte{0x2a},
284+
std::byte{0x27}, std::byte{0x4f}, std::byte{0xc1}, std::byte{0xa8}, std::byte{0x36}, std::byte{0xba},
285+
std::byte{0x3c}, std::byte{0x23}, std::byte{0xa3}, std::byte{0xfe}, std::byte{0xeb}, std::byte{0xbd},
286+
std::byte{0x45}, std::byte{0x4d}, std::byte{0x44}, std::byte{0x23}, std::byte{0x64}, std::byte{0x3c},
287+
std::byte{0xe8}, std::byte{0x0e}, std::byte{0x2a}, std::byte{0x9a}, std::byte{0xc9}, std::byte{0x4f},
288+
std::byte{0xa5}, std::byte{0x4c}, std::byte{0xa4}, std::byte{0x9f}
289+
};
276290

277291
std::span<const std::byte> byte_span {vals};
278292

279293
boost::crypt::sha512_hasher hasher;
280294
hasher.init();
281295
hasher.process_bytes(byte_span);
296+
hasher.finalize();
282297
const auto res = hasher.get_digest();
283298

284299
bool correct {true};
285300
for (std::size_t i {}; i < res.size(); ++i)
286301
{
287-
if (res[i] != static_cast<std::byte>(expected_res[i]))
302+
if (res[i] != expected_res[i])
288303
{
289304
correct = false;
290305
break;

0 commit comments

Comments
 (0)