Skip to content

Commit c8ff9a6

Browse files
authored
Merge pull request #712 from ckormanyos/hash_syntax
Hash syntax
2 parents 9929592 + 1aa27d0 commit c8ff9a6

File tree

24 files changed

+304
-241
lines changed

24 files changed

+304
-241
lines changed

examples/chapter11_07a/src/app/led/app_led.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{
1414
#endif
1515

16-
void app_led_task_background (void* pv);
16+
void app_led_task_background(void* pv);
1717
void app_led_task_toggle_led0(void* pv);
1818

1919
#if defined(__cplusplus)

examples/chapter11_07a/src/app/pi_spigot/pi_spigot.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///////////////////////////////////////////////////////////////////
22
// //
33
// Copyright Iliass Mahjoub 2022. //
4-
// Copyright Christopher Kormanyos 2019 - 2025. //
4+
// Copyright Christopher Kormanyos 2019 - 2026. //
55
// Distributed under the Boost Software License, //
66
// Version 1.0. (See accompanying file LICENSE_1_0.txt //
77
// or copy at http://www.boost.org/LICENSE_1_0.txt) //
@@ -49,11 +49,11 @@ namespace local
4949
return instance;
5050
}
5151

52-
auto pi_output_digits10 = static_cast<std::uint32_t>(UINT8_C(0));
52+
auto pi_output_digits10 = std::uint32_t { UINT8_C(0) };
5353

5454
using benchmark_port_type = ::mcal::benchmark::benchmark_port_type;
5555

56-
constexpr auto pi_spigot_input_start_address = static_cast<mcal_sram_uintptr_t>(UINT8_C(0));
56+
constexpr auto pi_spigot_input_start_address = mcal_sram_uintptr_t { UINT8_C(0) };
5757

5858
using pi_spigot_input_container_type = mcal::memory::sram::array<std::uint32_t,
5959
pi_spigot_type::get_input_static_size(),

examples/chapter11_07a/src/app/pi_spigot/pi_spigot_callback.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///////////////////////////////////////////////////////////////////
22
// //
3-
// Copyright Christopher Kormanyos 2023 - 2025. //
3+
// Copyright Christopher Kormanyos 2023 - 2026. //
44
// Distributed under the Boost Software License, //
55
// Version 1.0. (See accompanying file LICENSE_1_0.txt //
66
// or copy at http://www.boost.org/LICENSE_1_0.txt) //
@@ -18,7 +18,7 @@ auto pi_lcd_progress(const std::uint32_t pi_output_digits10) -> void;
1818

1919
auto pi_lcd_progress(const std::uint32_t pi_output_digits10) -> void
2020
{
21-
char p_str[std::size_t { UINT8_C(20) }];
21+
char p_str[std::size_t { UINT8_C(16) }];
2222

2323
{
2424
std::fill(p_str, p_str + sizeof(p_str), char { INT8_C(0) });

examples/chapter11_07a/src/math/checksums/hash/hash_base.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2013 - 2025.
2+
// Copyright Christopher Kormanyos 2013 - 2026.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -63,7 +63,7 @@
6363

6464
if(message_index == message_buffer_static_size())
6565
{
66-
my_perform_algorithm();
66+
perform_algorithm();
6767
}
6868

6969
process_chunk_size = (std::min)(static_cast<count_type>(count - process_index),
@@ -95,7 +95,7 @@
9595

9696
if(message_top > message_buffer_static_size())
9797
{
98-
my_perform_algorithm();
98+
perform_algorithm();
9999
}
100100

101101
// Encode the total number of bits in the final transform buffer.
@@ -131,7 +131,7 @@
131131
);
132132
}
133133

134-
my_perform_algorithm();
134+
perform_algorithm();
135135
}
136136

137137
auto get_result(typename result_type::pointer result) -> void
@@ -185,15 +185,15 @@
185185
);
186186
}
187187

188-
virtual auto perform_algorithm() -> void = 0;
188+
virtual auto my_perform_algorithm() -> void = 0;
189189

190-
auto my_perform_algorithm() -> void
190+
auto perform_algorithm() -> void
191191
{
192-
this->perform_algorithm();
192+
this->my_perform_algorithm();
193193

194-
message_index = static_cast<std::uint_least32_t>(UINT8_C(0));
194+
message_index = std::uint_least32_t { UINT8_C(0) };
195195

196-
message_buffer.fill(static_cast<std::uint8_t>(UINT8_C(0)));
196+
message_buffer.fill(std::uint8_t { UINT8_C(0) });
197197
}
198198
};
199199

examples/chapter11_07a/src/math/checksums/hash/hash_detail.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright Christopher Kormanyos 2013 - 2025.
1+
// Copyright Christopher Kormanyos 2013 - 2026.
22
// Distributed under the Boost Software License,
33
// Version 1.0. (See accompanying file LICENSE_1_0.txt
44
// or copy at http://www.boost.org/LICENSE_1_0.txt)

examples/chapter11_07a/src/math/checksums/hash/hash_sha1.h

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2013 - 2025.
2+
// Copyright Christopher Kormanyos 2013 - 2026.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -46,17 +46,17 @@
4646
{
4747
base_class_type::initialize();
4848

49-
base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(0))] = static_cast<std::uint32_t>(UINT32_C(0x67452301));
50-
base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(1))] = static_cast<std::uint32_t>(UINT32_C(0xEFCDAB89));
51-
base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(2))] = static_cast<std::uint32_t>(UINT32_C(0x98BADCFE));
52-
base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(3))] = static_cast<std::uint32_t>(UINT32_C(0x10325476));
53-
base_class_type::transform_context[static_cast<std::size_t>(UINT8_C(4))] = static_cast<std::uint32_t>(UINT32_C(0xC3D2E1F0));
49+
base_class_type::transform_context[std::size_t { UINT8_C(0) }] = std::uint32_t { UINT32_C(0x67452301) };
50+
base_class_type::transform_context[std::size_t { UINT8_C(1) }] = std::uint32_t { UINT32_C(0xEFCDAB89) };
51+
base_class_type::transform_context[std::size_t { UINT8_C(2) }] = std::uint32_t { UINT32_C(0x98BADCFE) };
52+
base_class_type::transform_context[std::size_t { UINT8_C(3) }] = std::uint32_t { UINT32_C(0x10325476) };
53+
base_class_type::transform_context[std::size_t { UINT8_C(4) }] = std::uint32_t { UINT32_C(0xC3D2E1F0) };
5454
}
5555

5656
private:
5757
static const std::array<transform_function_type, static_cast<std::size_t>(UINT8_C(4))> transform_functions;
5858

59-
auto perform_algorithm() -> void override;
59+
auto my_perform_algorithm() -> void override;
6060
};
6161

6262
const std::array<hash_sha1::transform_function_type, static_cast<std::size_t>(UINT8_C(4))>
@@ -68,18 +68,18 @@
6868
[](const std::uint32_t* p) -> std::uint32_t { return (static_cast<std::uint32_t>( p[1U] ^ p[2U]) ^ p[3U]); }
6969
};
7070

71-
auto hash_sha1::perform_algorithm() -> void
71+
auto hash_sha1::my_perform_algorithm() -> void
7272
{
7373
// Apply the hash transformation algorithm to a full data block.
7474

7575
using transform_constants_array_type = std::array<std::uint32_t, static_cast<std::size_t>(UINT8_C(4))>;
7676

7777
const transform_constants_array_type transform_constants
7878
{
79-
static_cast<std::uint32_t>(UINT32_C(0x5A827999)),
80-
static_cast<std::uint32_t>(UINT32_C(0x6ED9EBA1)),
81-
static_cast<std::uint32_t>(UINT32_C(0x8F1BBCDC)),
82-
static_cast<std::uint32_t>(UINT32_C(0xCA62C1D6))
79+
std::uint32_t { UINT32_C(0x5A827999) },
80+
std::uint32_t { UINT32_C(0x6ED9EBA1) },
81+
std::uint32_t { UINT32_C(0x8F1BBCDC) },
82+
std::uint32_t { UINT32_C(0xCA62C1D6) }
8383
};
8484

8585
using transform_block_type = std::array<std::uint32_t, static_cast<std::size_t>(UINT8_C(16))>;
@@ -139,11 +139,14 @@
139139
}
140140

141141
// Update the hash state with the transformation results.
142-
std::transform(base_class_type::transform_context.cbegin(),
143-
base_class_type::transform_context.cend (),
144-
hash_tmp.cbegin (),
145-
base_class_type::transform_context.begin (),
146-
std::plus<std::uint32_t> ());
142+
std::transform
143+
(
144+
base_class_type::transform_context.cbegin(),
145+
base_class_type::transform_context.cend(),
146+
hash_tmp.cbegin(),
147+
base_class_type::transform_context.begin(),
148+
std::plus<std::uint32_t>()
149+
);
147150
}
148151

149152
} } } // namespace math::checksums::hash

examples/chapter11_07a/src/math/checksums/hash/hash_sha256.h

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2013 - 2025.
2+
// Copyright Christopher Kormanyos 2013 - 2026.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,15 +17,12 @@
1717

1818
namespace math { namespace checksums { namespace hash {
1919

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)),
2321
static_cast<std::uint16_t>(UINT8_C(64)),
2422
static_cast<std::uint16_t>(UINT8_C(64))>
2523
{
2624
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)),
2926
static_cast<std::uint16_t>(UINT8_C(64)),
3027
static_cast<std::uint16_t>(UINT8_C(64))>;
3128

@@ -49,27 +46,26 @@
4946
{
5047
base_class_type::initialize();
5148

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) };
6057
}
6158

6259
private:
63-
auto perform_algorithm() -> void override;
60+
auto my_perform_algorithm() -> void override;
6461

6562
static constexpr auto transform_function1(std::uint32_t x) -> std::uint32_t; // BSIG0
6663
static constexpr auto transform_function2(std::uint32_t x) -> std::uint32_t; // BSIG1
6764
static constexpr auto transform_function3(std::uint32_t x) -> std::uint32_t; // SSIG0
6865
static constexpr auto transform_function4(std::uint32_t x) -> std::uint32_t; // SSIG1
6966
};
7067

71-
template <typename my_count_type>
72-
auto hash_sha256<my_count_type>::perform_algorithm() -> void
68+
auto hash_sha256::my_perform_algorithm() -> void
7369
{
7470
// Apply the hash transformation algorithm to a full data block.
7571

@@ -163,29 +159,31 @@
163159
)
164160
);
165161

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);
177173
}
178174

179175
// 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+
);
185184
}
186185

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
189187
{
190188
// BSIG0
191189
return
@@ -197,8 +195,7 @@
197195
);
198196
}
199197

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
202199
{
203200
// BSIG1
204201
return
@@ -210,8 +207,7 @@
210207
);
211208
}
212209

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
215211
{
216212
// SSIG0
217213
return
@@ -223,8 +219,7 @@
223219
);
224220
}
225221

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
228223
{
229224
// SSIG1
230225
return

examples/chapter11_07a/src/math/checksums/hash/hash_stream_base.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2013 - 2023.
2+
// Copyright Christopher Kormanyos 2013 - 2026.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -20,8 +20,15 @@
2020
using count_type = std::uint32_t;
2121

2222
hash_stream_base() = default;
23+
24+
hash_stream_base(const hash_stream_base&) = default;
25+
hash_stream_base(hash_stream_base&&) = default;
26+
2327
virtual ~hash_stream_base() = default;
2428

29+
auto operator=(const hash_stream_base&) -> hash_stream_base& = default;
30+
auto operator=(hash_stream_base&&) -> hash_stream_base& = default;
31+
2532
virtual auto initialize() -> void = 0;
2633

2734
virtual auto process(const std::uint8_t* message, const count_type count) -> void = 0;

examples/chapter11_07a/target/micros/avr/make/avr_flags.gmk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright Christopher Kormanyos 2007 - 2025.
2+
# Copyright Christopher Kormanyos 2007 - 2026.
33
# Distributed under the Boost Software License,
44
# Version 1.0. (See accompanying file LICENSE_1_0.txt
55
# or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -12,7 +12,7 @@
1212
GCC_TARGET = avr
1313
GCC_PREFIX = avr
1414

15-
GCC_VERSION = 15.1.0
15+
GCC_VERSION = 15.2.0
1616

1717
TGT_SUFFIX = elf
1818

@@ -31,7 +31,7 @@ TGT_ALLFLAGS := $(TGT_ALLFLAGS)
3131

3232
INC_PREFIX := -isystem
3333
STD_C := c11
34-
STD_CPP := c++20
34+
STD_CPP := c++23
3535

3636
else
3737

ref_app/ref_app.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,7 @@
14771477
<ClInclude Include="src\math\checksums\hash\hash_detail.h" />
14781478
<ClInclude Include="src\math\checksums\hash\hash_sha1.h" />
14791479
<ClInclude Include="src\math\checksums\hash\hash_sha256.h" />
1480+
<ClInclude Include="src\math\checksums\hash\hash_stream_base.h" />
14801481
<ClInclude Include="src\math\constants\constants.h" />
14811482
<ClInclude Include="src\math\constants\constant_functions.h" />
14821483
<ClInclude Include="src\math\constants\pi_spigot_base.h" />

0 commit comments

Comments
 (0)