|
1 | 1 | /////////////////////////////////////////////////////////////////////////////// |
2 | | -// Copyright Christopher Kormanyos 2013 - 2025. |
| 2 | +// Copyright Christopher Kormanyos 2013 - 2026. |
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) |
|
17 | 17 |
|
18 | 18 | namespace math { namespace checksums { namespace hash { |
19 | 19 |
|
20 | | - template<typename CountType> |
21 | | - class hash_sha256 : public hash_base<CountType, |
22 | | - static_cast<std::uint16_t>(UINT16_C(256)), |
| 20 | + class hash_sha256 : public hash_base<static_cast<std::uint16_t>(UINT16_C(256)), |
23 | 21 | static_cast<std::uint16_t>(UINT8_C(64)), |
24 | 22 | static_cast<std::uint16_t>(UINT8_C(64))> |
25 | 23 | { |
26 | 24 | private: |
27 | | - using base_class_type = hash_base<CountType, |
28 | | - static_cast<std::uint16_t>(UINT16_C(256)), |
| 25 | + using base_class_type = hash_base<static_cast<std::uint16_t>(UINT16_C(256)), |
29 | 26 | static_cast<std::uint16_t>(UINT8_C(64)), |
30 | 27 | static_cast<std::uint16_t>(UINT8_C(64))>; |
31 | 28 |
|
|
49 | 46 | { |
50 | 47 | base_class_type::initialize(); |
51 | 48 |
|
52 | | - base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(0))] = static_cast<std::uint32_t>(UINT32_C(0x6A09E667)); |
53 | | - base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(1))] = static_cast<std::uint32_t>(UINT32_C(0xBB67AE85)); |
54 | | - base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(2))] = static_cast<std::uint32_t>(UINT32_C(0x3C6EF372)); |
55 | | - base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(3))] = static_cast<std::uint32_t>(UINT32_C(0xA54FF53A)); |
56 | | - base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(4))] = static_cast<std::uint32_t>(UINT32_C(0x510E527F)); |
57 | | - base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(5))] = static_cast<std::uint32_t>(UINT32_C(0x9B05688C)); |
58 | | - base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(6))] = static_cast<std::uint32_t>(UINT32_C(0x1F83D9AB)); |
59 | | - base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(7))] = static_cast<std::uint32_t>(UINT32_C(0x5BE0CD19)); |
| 49 | + base_class_type::transform_context[std::size_t { UINT8_C(0) }] = std::uint32_t { UINT32_C(0x6A09E667) }; |
| 50 | + base_class_type::transform_context[std::size_t { UINT8_C(1) }] = std::uint32_t { UINT32_C(0xBB67AE85) }; |
| 51 | + base_class_type::transform_context[std::size_t { UINT8_C(2) }] = std::uint32_t { UINT32_C(0x3C6EF372) }; |
| 52 | + base_class_type::transform_context[std::size_t { UINT8_C(3) }] = std::uint32_t { UINT32_C(0xA54FF53A) }; |
| 53 | + base_class_type::transform_context[std::size_t { UINT8_C(4) }] = std::uint32_t { UINT32_C(0x510E527F) }; |
| 54 | + base_class_type::transform_context[std::size_t { UINT8_C(5) }] = std::uint32_t { UINT32_C(0x9B05688C) }; |
| 55 | + base_class_type::transform_context[std::size_t { UINT8_C(6) }] = std::uint32_t { UINT32_C(0x1F83D9AB) }; |
| 56 | + base_class_type::transform_context[std::size_t { UINT8_C(7) }] = std::uint32_t { UINT32_C(0x5BE0CD19) }; |
60 | 57 | } |
61 | 58 |
|
62 | 59 | private: |
63 | | - auto perform_algorithm() -> void override; |
| 60 | + auto my_perform_algorithm() -> void override; |
64 | 61 |
|
65 | 62 | static constexpr auto transform_function1(std::uint32_t x) -> std::uint32_t; // BSIG0 |
66 | 63 | static constexpr auto transform_function2(std::uint32_t x) -> std::uint32_t; // BSIG1 |
67 | 64 | static constexpr auto transform_function3(std::uint32_t x) -> std::uint32_t; // SSIG0 |
68 | 65 | static constexpr auto transform_function4(std::uint32_t x) -> std::uint32_t; // SSIG1 |
69 | 66 | }; |
70 | 67 |
|
71 | | - template <typename my_count_type> |
72 | | - auto hash_sha256<my_count_type>::perform_algorithm() -> void |
| 68 | + auto hash_sha256::my_perform_algorithm() -> void |
73 | 69 | { |
74 | 70 | // Apply the hash transformation algorithm to a full data block. |
75 | 71 |
|
|
163 | 159 | ) |
164 | 160 | ); |
165 | 161 |
|
166 | | - hash_tmp[static_cast<std::size_t>(UINT8_C(7))] = hash_tmp[static_cast<std::size_t>(UINT8_C(6))]; |
167 | | - hash_tmp[static_cast<std::size_t>(UINT8_C(6))] = hash_tmp[static_cast<std::size_t>(UINT8_C(5))]; |
168 | | - hash_tmp[static_cast<std::size_t>(UINT8_C(5))] = hash_tmp[static_cast<std::size_t>(UINT8_C(4))]; |
169 | | - hash_tmp[static_cast<std::size_t>(UINT8_C(4))] = static_cast<std::uint32_t> |
170 | | - ( |
171 | | - hash_tmp[static_cast<std::size_t>(UINT8_C(3))] + tmp1 |
172 | | - ); |
173 | | - hash_tmp[static_cast<std::size_t>(UINT8_C(3))] = hash_tmp[static_cast<std::size_t>(UINT8_C(2))]; |
174 | | - hash_tmp[static_cast<std::size_t>(UINT8_C(2))] = hash_tmp[static_cast<std::size_t>(UINT8_C(1))]; |
175 | | - hash_tmp[static_cast<std::size_t>(UINT8_C(1))] = hash_tmp[static_cast<std::size_t>(UINT8_C(0))]; |
176 | | - hash_tmp[static_cast<std::size_t>(UINT8_C(0))] = static_cast<std::uint32_t>(tmp1 + tmp2); |
| 162 | + hash_tmp[std::size_t { UINT8_C(7) }] = hash_tmp[std::size_t { UINT8_C(6) }]; |
| 163 | + hash_tmp[std::size_t { UINT8_C(6) }] = hash_tmp[std::size_t { UINT8_C(5) }]; |
| 164 | + hash_tmp[std::size_t { UINT8_C(5) }] = hash_tmp[std::size_t { UINT8_C(4) }]; |
| 165 | + hash_tmp[std::size_t { UINT8_C(4) }] = static_cast<std::uint32_t> |
| 166 | + ( |
| 167 | + hash_tmp[static_cast<std::size_t>(UINT8_C(3))] + tmp1 |
| 168 | + ); |
| 169 | + hash_tmp[std::size_t { UINT8_C(3) }] = hash_tmp[std::size_t { UINT8_C(2) }]; |
| 170 | + hash_tmp[std::size_t { UINT8_C(2) }] = hash_tmp[std::size_t { UINT8_C(1) }]; |
| 171 | + hash_tmp[std::size_t { UINT8_C(1) }] = hash_tmp[std::size_t { UINT8_C(0) }]; |
| 172 | + hash_tmp[std::size_t { UINT8_C(0) }] = static_cast<std::uint32_t>(tmp1 + tmp2); |
177 | 173 | } |
178 | 174 |
|
179 | 175 | // Update the hash state with the transformation results. |
180 | | - std::transform(base_class_type::transform_context.cbegin(), |
181 | | - base_class_type::transform_context.cend (), |
182 | | - hash_tmp.cbegin (), |
183 | | - base_class_type::transform_context.begin (), |
184 | | - std::plus<std::uint32_t> ()); |
| 176 | + std::transform |
| 177 | + ( |
| 178 | + base_class_type::transform_context.cbegin(), |
| 179 | + base_class_type::transform_context.cend(), |
| 180 | + hash_tmp.cbegin(), |
| 181 | + base_class_type::transform_context.begin(), |
| 182 | + std::plus<std::uint32_t>() |
| 183 | + ); |
185 | 184 | } |
186 | 185 |
|
187 | | - template <typename my_count_type> |
188 | | - constexpr auto hash_sha256<my_count_type>::transform_function1(std::uint32_t x) -> std::uint32_t |
| 186 | + constexpr auto hash_sha256::transform_function1(std::uint32_t x) -> std::uint32_t |
189 | 187 | { |
190 | 188 | // BSIG0 |
191 | 189 | return |
|
197 | 195 | ); |
198 | 196 | } |
199 | 197 |
|
200 | | - template <typename my_count_type> |
201 | | - constexpr auto hash_sha256<my_count_type>::transform_function2(std::uint32_t x) -> std::uint32_t |
| 198 | + constexpr auto hash_sha256::transform_function2(std::uint32_t x) -> std::uint32_t |
202 | 199 | { |
203 | 200 | // BSIG1 |
204 | 201 | return |
|
210 | 207 | ); |
211 | 208 | } |
212 | 209 |
|
213 | | - template <typename my_count_type> |
214 | | - constexpr auto hash_sha256<my_count_type>::transform_function3(std::uint32_t x) -> std::uint32_t |
| 210 | + constexpr auto hash_sha256::transform_function3(std::uint32_t x) -> std::uint32_t |
215 | 211 | { |
216 | 212 | // SSIG0 |
217 | 213 | return |
|
223 | 219 | ); |
224 | 220 | } |
225 | 221 |
|
226 | | - template <typename my_count_type> |
227 | | - constexpr auto hash_sha256<my_count_type>::transform_function4(std::uint32_t x) -> std::uint32_t |
| 222 | + constexpr auto hash_sha256::transform_function4(std::uint32_t x) -> std::uint32_t |
228 | 223 | { |
229 | 224 | // SSIG1 |
230 | 225 | return |
|
0 commit comments