|
1 | 1 | /////////////////////////////////////////////////////////////////////////////// |
2 | | -// Copyright Christopher Kormanyos 2013 - 2025. |
| 2 | +// Copyright Christopher Kormanyos 2013 - 2023. |
3 | 3 | // Distributed under the Boost Software License, |
4 | 4 | // Version 1.0. (See accompanying file LICENSE_1_0.txt |
5 | 5 | // or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 | 6 | // |
7 | 7 |
|
8 | | -#ifndef HASH_BASE_2013_09_05_H |
9 | | - #define HASH_BASE_2013_09_05_H |
| 8 | +#ifndef HASH_BASE_2013_09_05_H_ |
| 9 | + #define HASH_BASE_2013_09_05_H_ |
10 | 10 |
|
11 | 11 | #include <limits> |
12 | 12 |
|
13 | 13 | #include <math/checksums/hash/hash_detail.h> |
14 | | - #include <math/checksums/hash/hash_stream_base.h> |
15 | 14 |
|
16 | 15 | namespace math { namespace checksums { namespace hash { |
17 | 16 |
|
18 | | - template<const std::uint16_t ResultBitCount, |
| 17 | + template<typename CountType, |
| 18 | + const std::uint16_t ResultBitCount, |
19 | 19 | const std::uint16_t MessageBufferSize, |
20 | 20 | const std::uint16_t MessageLengthTotalBitCount> |
21 | | - class hash_base : public hash_stream_base |
| 21 | + class hash_base |
22 | 22 | { |
23 | 23 | public: |
| 24 | + using count_type = CountType; |
| 25 | + |
24 | 26 | using result_type = std::array<std::uint8_t, static_cast<std::size_t>(ResultBitCount / static_cast<std::uint16_t>(UINT8_C(8)))>; |
25 | 27 |
|
26 | 28 | static_assert |
|
38 | 40 |
|
39 | 41 | virtual auto initialize() -> void |
40 | 42 | { |
41 | | - message_index = static_cast<std::uint_least32_t>(UINT8_C(0)); |
| 43 | + message_index = static_cast<std::uint_least16_t>(UINT8_C(0)); |
42 | 44 | message_length_total = static_cast<count_type>(UINT8_C(0)); |
43 | 45 |
|
44 | 46 | message_buffer.fill(static_cast<std::uint8_t>(UINT8_C(0))); |
45 | 47 | } |
46 | 48 |
|
47 | | - virtual auto process(const std::uint8_t* message, const count_type count) -> void |
| 49 | + auto process(const std::uint8_t* message, const count_type count) -> void |
48 | 50 | { |
49 | 51 | auto process_index = count_type { }; |
50 | 52 | auto process_chunk_size = count_type { }; |
51 | 53 |
|
52 | 54 | while(process_index < count) |
53 | 55 | { |
54 | | - message_index = static_cast<std::uint_least32_t>(message_index + process_chunk_size); |
| 56 | + message_index = static_cast<std::uint_least16_t>(message_index + process_chunk_size); |
55 | 57 | message_length_total = static_cast<count_type> (message_length_total + process_chunk_size); |
56 | 58 | process_index = static_cast<count_type> (process_index + process_chunk_size); |
57 | 59 |
|
|
70 | 72 | } |
71 | 73 | } |
72 | 74 |
|
73 | | - virtual auto finalize() -> void |
| 75 | + auto finalize() -> void |
74 | 76 | { |
75 | 77 | // Create the padding. Begin by setting the leading padding byte to 0x80. |
76 | | - message_buffer[static_cast<std::size_t>(message_index)] = static_cast<std::uint8_t>(UINT8_C(0x80)); |
| 78 | + message_buffer[message_index] = static_cast<std::uint8_t>(UINT8_C(0x80)); |
77 | 79 |
|
78 | 80 | ++message_index; |
79 | 81 |
|
|
84 | 86 | const auto message_top = |
85 | 87 | static_cast<std::uint16_t> |
86 | 88 | ( |
87 | | - message_index + static_cast<std::uint_least32_t>(message_length_total_width()) |
| 89 | + message_index + static_cast<std::uint_least16_t>(message_length_total_width()) |
88 | 90 | ); |
89 | 91 |
|
90 | 92 | if(message_top > message_buffer_static_size()) |
|
103 | 105 | ri != message_buffer.rbegin() + static_cast<std::size_t>(message_length_total_width()); |
104 | 106 | ++ri) |
105 | 107 | { |
106 | | - const std::uint_least32_t the_word = |
107 | | - static_cast<std::uint_least32_t> |
| 108 | + const std::uint_least16_t the_word = |
| 109 | + static_cast<std::uint_least16_t> |
108 | 110 | ( |
109 | | - static_cast<std::uint_least32_t>(message_length_total) << static_cast<unsigned>(UINT8_C(3)) |
| 111 | + static_cast<std::uint_least16_t>(message_length_total) << static_cast<unsigned>(UINT8_C(3)) |
110 | 112 | ); |
111 | 113 |
|
112 | 114 | *ri = static_cast<std::uint8_t>(the_word | carry); |
|
156 | 158 | return static_cast<std::uint16_t>(std::tuple_size<message_block_type>::value); |
157 | 159 | } |
158 | 160 |
|
159 | | - std::uint_least32_t message_index { }; |
| 161 | + std::uint_least16_t message_index { }; |
160 | 162 | count_type message_length_total { }; |
161 | 163 | message_block_type message_buffer { }; |
162 | 164 | context_type transform_context { }; |
|
185 | 187 | { |
186 | 188 | this->perform_algorithm(); |
187 | 189 |
|
188 | | - message_index = static_cast<std::uint_least32_t>(UINT8_C(0)); |
| 190 | + message_index = static_cast<std::uint_least16_t>(UINT8_C(0)); |
189 | 191 |
|
190 | 192 | message_buffer.fill(static_cast<std::uint8_t>(UINT8_C(0))); |
191 | 193 | } |
192 | 194 | }; |
193 | 195 |
|
194 | 196 | } } } // namespace math::checksums::hash |
195 | 197 |
|
196 | | -#endif // HASH_BASE_2013_09_05_H |
| 198 | +#endif // HASH_BASE_2013_09_05_H_ |
0 commit comments