Skip to content

Commit e0e60ce

Browse files
committed
Restore previous hash architecture
1 parent af899cf commit e0e60ce

7 files changed

Lines changed: 39 additions & 78 deletions

File tree

ref_app/ref_app.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,6 @@
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" />
14811480
<ClInclude Include="src\math\constants\constants.h" />
14821481
<ClInclude Include="src\math\constants\constant_functions.h" />
14831482
<ClInclude Include="src\math\constants\pi_spigot_base.h" />

ref_app/ref_app.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,9 +3042,6 @@
30423042
<ClInclude Include="src\mcal_memory\mcal_memory_sram_types.h">
30433043
<Filter>src\mcal_memory</Filter>
30443044
</ClInclude>
3045-
<ClInclude Include="src\math\checksums\hash\hash_stream_base.h">
3046-
<Filter>src\math\checksums\hash</Filter>
3047-
</ClInclude>
30483045
</ItemGroup>
30493046
<ItemGroup>
30503047
<None Include="src\util\STL\algorithm">

ref_app/src/math/checksums/hash/hash_base.h

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2013 - 2025.
2+
// Copyright Christopher Kormanyos 2013 - 2023.
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)
66
//
77

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_
1010

1111
#include <limits>
1212

1313
#include <math/checksums/hash/hash_detail.h>
14-
#include <math/checksums/hash/hash_stream_base.h>
1514

1615
namespace math { namespace checksums { namespace hash {
1716

18-
template<const std::uint16_t ResultBitCount,
17+
template<typename CountType,
18+
const std::uint16_t ResultBitCount,
1919
const std::uint16_t MessageBufferSize,
2020
const std::uint16_t MessageLengthTotalBitCount>
21-
class hash_base : public hash_stream_base
21+
class hash_base
2222
{
2323
public:
24+
using count_type = CountType;
25+
2426
using result_type = std::array<std::uint8_t, static_cast<std::size_t>(ResultBitCount / static_cast<std::uint16_t>(UINT8_C(8)))>;
2527

2628
static_assert
@@ -38,20 +40,20 @@
3840

3941
virtual auto initialize() -> void
4042
{
41-
message_index = static_cast<std::uint_least32_t>(UINT8_C(0));
43+
message_index = static_cast<std::uint_least16_t>(UINT8_C(0));
4244
message_length_total = static_cast<count_type>(UINT8_C(0));
4345

4446
message_buffer.fill(static_cast<std::uint8_t>(UINT8_C(0)));
4547
}
4648

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
4850
{
4951
auto process_index = count_type { };
5052
auto process_chunk_size = count_type { };
5153

5254
while(process_index < count)
5355
{
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);
5557
message_length_total = static_cast<count_type> (message_length_total + process_chunk_size);
5658
process_index = static_cast<count_type> (process_index + process_chunk_size);
5759

@@ -70,10 +72,10 @@
7072
}
7173
}
7274

73-
virtual auto finalize() -> void
75+
auto finalize() -> void
7476
{
7577
// 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));
7779

7880
++message_index;
7981

@@ -84,7 +86,7 @@
8486
const auto message_top =
8587
static_cast<std::uint16_t>
8688
(
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())
8890
);
8991

9092
if(message_top > message_buffer_static_size())
@@ -103,10 +105,10 @@
103105
ri != message_buffer.rbegin() + static_cast<std::size_t>(message_length_total_width());
104106
++ri)
105107
{
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>
108110
(
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))
110112
);
111113

112114
*ri = static_cast<std::uint8_t>(the_word | carry);
@@ -156,7 +158,7 @@
156158
return static_cast<std::uint16_t>(std::tuple_size<message_block_type>::value);
157159
}
158160

159-
std::uint_least32_t message_index { };
161+
std::uint_least16_t message_index { };
160162
count_type message_length_total { };
161163
message_block_type message_buffer { };
162164
context_type transform_context { };
@@ -185,12 +187,12 @@
185187
{
186188
this->perform_algorithm();
187189

188-
message_index = static_cast<std::uint_least32_t>(UINT8_C(0));
190+
message_index = static_cast<std::uint_least16_t>(UINT8_C(0));
189191

190192
message_buffer.fill(static_cast<std::uint8_t>(UINT8_C(0)));
191193
}
192194
};
193195

194196
} } } // namespace math::checksums::hash
195197

196-
#endif // HASH_BASE_2013_09_05_H
198+
#endif // HASH_BASE_2013_09_05_H_

ref_app/src/math/checksums/hash/hash_detail.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// Copyright Christopher Kormanyos 2013 - 2025.
1+
// Copyright Christopher Kormanyos 2013 - 2023.
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)
55
//
66

7-
#ifndef HASH_DETAIL_2020_05_18_H
8-
#define HASH_DETAIL_2020_05_18_H
7+
#ifndef HASH_DETAIL_2020_05_18_H_
8+
#define HASH_DETAIL_2020_05_18_H_
99

1010
#include <cstddef>
1111
#include <cstdint>
@@ -126,4 +126,4 @@
126126

127127
} } } } // namespace math::checksums::hash::detail
128128

129-
#endif // HASH_DETAIL_2020_05_18_H
129+
#endif // HASH_DETAIL_2020_05_18_H_

ref_app/src/math/checksums/hash/hash_sha1.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2013 - 2025.
2+
// Copyright Christopher Kormanyos 2013 - 2023.
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)
66
//
77

8-
#ifndef HASH_SHA1_2013_09_03_H
9-
#define HASH_SHA1_2013_09_03_H
8+
#ifndef HASH_SHA1_2013_09_03_H_
9+
#define HASH_SHA1_2013_09_03_H_
1010

1111
// See also: https://en.wikipedia.org/wiki/SHA-1
1212

@@ -18,12 +18,15 @@
1818

1919
namespace math { namespace checksums { namespace hash {
2020

21-
class hash_sha1 : public hash_base<static_cast<std::uint16_t>(UINT8_C(160)),
21+
template<typename CountType>
22+
class hash_sha1 : public hash_base<CountType,
23+
static_cast<std::uint16_t>(UINT8_C(160)),
2224
static_cast<std::uint16_t>(UINT8_C(64)),
2325
static_cast<std::uint16_t>(UINT8_C(64))>
2426
{
2527
private:
26-
using base_class_type = hash_base<static_cast<std::uint16_t>(UINT8_C(160)),
28+
using base_class_type = hash_base<CountType,
29+
static_cast<std::uint16_t>(UINT8_C(160)),
2730
static_cast<std::uint16_t>(UINT8_C(64)),
2831
static_cast<std::uint16_t>(UINT8_C(64))>;
2932

@@ -56,7 +59,8 @@
5659
auto perform_algorithm() -> void override;
5760
};
5861

59-
auto hash_sha1::perform_algorithm() -> void
62+
template <typename my_count_type>
63+
auto hash_sha1<my_count_type>::perform_algorithm() -> void
6064
{
6165
// Apply the hash transformation algorithm to a full data block.
6266

@@ -146,4 +150,4 @@
146150

147151
} } } // namespace math::checksums::hash
148152

149-
#endif // HASH_SHA1_2013_09_03_H
153+
#endif // HASH_SHA1_2013_09_03_H_

ref_app/src/math/checksums/hash/hash_sha256.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2013 - 2025.
2+
// Copyright Christopher Kormanyos 2013 - 2023.
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)
66
//
77

8-
#ifndef HASH_SHA256_2023_02_26_H
9-
#define HASH_SHA256_2023_02_26_H
8+
#ifndef HASH_SHA256_2023_02_26_H_
9+
#define HASH_SHA256_2023_02_26_H_
1010

1111
// See also: https://en.wikipedia.org/wiki/SHA-2
1212

@@ -239,4 +239,4 @@
239239

240240
} } } // namespace math::checksums::hash
241241

242-
#endif // HASH_SHA256_2023_02_26_H
242+
#endif // HASH_SHA256_2023_02_26_H_

ref_app/src/math/checksums/hash/hash_stream_base.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)