Skip to content

Commit ae56059

Browse files
committed
Try hasher 256 on the metal in CI
1 parent ff0c6df commit ae56059

File tree

10 files changed

+852
-2
lines changed

10 files changed

+852
-2
lines changed

.github/workflows/metal.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# ------------------------------------------------------------------------------
2+
# Copyright Matt Borland 2023 - 2024.
3+
# Copyright Christopher Kormanyos 2023 - 2024.
4+
# Distributed under the Boost Software License,
5+
# Version 1.0. (See accompanying file LICENSE_1_0.txt
6+
# or copy at http://www.boost.org/LICENSE_1_0.txt)
7+
# ------------------------------------------------------------------------------
8+
9+
name: metal
10+
on:
11+
push:
12+
branches:
13+
- master
14+
- develop
15+
- feature/**
16+
pull_request:
17+
types: [opened, synchronize, reopened]
18+
jobs:
19+
benchmark_single-stm32f429-qemu:
20+
runs-on: ubuntu-latest
21+
defaults:
22+
run:
23+
shell: bash
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
fetch-depth: '0'
28+
- name: update-tools
29+
run: |
30+
sudo apt install libncurses5 libpython2.7
31+
mkdir -p emu_env && cd emu_env
32+
wget --no-check-certificate https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
33+
tar -xf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
34+
wget --no-check-certificate https://github.com/xpack-dev-tools/qemu-arm-xpack/releases/download/v7.1.0-1/xpack-qemu-arm-7.1.0-1-linux-x64.tar.gz
35+
tar -xzf xpack-qemu-arm-7.1.0-1-linux-x64.tar.gz
36+
working-directory: ./test/metal/
37+
- name: build benchmark_single-stm32f429
38+
run: |
39+
mkdir -p bin
40+
emu_env/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-g++ -std=c++20 -Wall -Wextra -Wpedantic -Os -g -gdwarf-2 -ffunction-sections -fdata-sections -x c++ -fno-rtti -fno-use-cxa-atexit -fno-exceptions -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs -fno-inline-functions -mcpu=cortex-m4 -mtune=cortex-m4 -mthumb -mfloat-abi=soft -mno-unaligned-access -mno-long-calls -I../../include -DBOOST_CRYPT_DISABLE_IOSTREAM -DAPP_BENCHMARK_STANDALONE_MAIN app_benchmark_hasher.cpp ./target/micros/stm32f429/make/single/crt.cpp ./target/micros/stm32f429/make/single/mcal_gcc_cxx_completion_with_stdlib.cpp -nostartfiles -Wl,--gc-sections -Wl,-Map,./bin/app_benchmark_hasher.map -T ./target/micros/stm32f429/make/stm32f429.ld --specs=nano.specs --specs=nosys.specs -Wl,--print-memory-usage -o ./bin/app_benchmark_hasher.elf
41+
emu_env/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-objcopy ./bin/app_benchmark_hasher.elf -O ihex ./bin/app_benchmark_hasher.hex
42+
ls -la ./bin/app_benchmark_hasher.elf ./bin/app_benchmark_hasher.hex ./bin/app_benchmark_hasher.map
43+
working-directory: ./test/metal/
44+
- name: emulate-target stm32f429
45+
run: |
46+
./emu_env/xpack-qemu-arm-7.1.0-1/bin/qemu-system-gnuarmeclipse --verbose --mcu STM32F429ZI --nographic --gdb tcp::9999 -d unimp,guest_errors &
47+
working-directory: ./test/metal/
48+
- name: run-test-on-target
49+
run: |
50+
./emu_env/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gdb-py ./bin/app_benchmark_hasher.elf -x ./target/build/test_app_benchmarks_emulator.py
51+
qemu_result=$?
52+
echo "qemu_result" "$qemu_result"
53+
echo "qemu_result" "$qemu_result" | grep 'qemu_result 0'
54+
working-directory: ./test/metal/

include/boost/crypt/hash/sha256.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ auto sha256_file_impl(utility::file_reader<block_size>& reader) noexcept -> sha2
217217

218218
} // namespace detail
219219

220+
#ifndef BOOST_CRYPT_DISABLE_IOSTREAM
221+
220222
BOOST_CRYPT_EXPORT inline auto sha256_file(const std::string& filepath) noexcept -> sha256_hasher::return_type
221223
{
222224
try
@@ -248,7 +250,9 @@ BOOST_CRYPT_EXPORT inline auto sha256_file(const char* filepath) noexcept -> sha
248250
}
249251
}
250252

251-
#ifdef BOOST_CRYPT_HAS_STRING_VIEW
253+
#endif // !BOOST_CRYPT_DISABLE_IOSTREAM
254+
255+
#if (defined(BOOST_CRYPT_HAS_STRING_VIEW) && !defined(BOOST_CRYPT_DISABLE_IOSTREAM))
252256

253257
BOOST_CRYPT_EXPORT inline auto sha256_file(std::string_view filepath) noexcept -> sha256_hasher::return_type
254258
{
@@ -263,7 +267,7 @@ BOOST_CRYPT_EXPORT inline auto sha256_file(std::string_view filepath) noexcept -
263267
}
264268
}
265269

266-
#endif // BOOST_CRYPT_HAS_STRING_VIEW
270+
#endif // BOOST_CRYPT_HAS_STRING_VIEW && !BOOST_CRYPT_DISABLE_IOSTREAM
267271

268272
#endif // BOOST_CRYPT_HAS_CUDA
269273

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2024 Matt Borland
2+
// Copyright 2024 Christopher Kormanyos
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// https://www.boost.org/LICENSE_1_0.txt
5+
6+
#ifndef BOOST_CRYPT_UTILITIES_ALGORITHM_HPP
7+
#define BOOST_CRYPT_UTILITIES_ALGORITHM_HPP
8+
9+
#include <boost/crypt/utility/config.hpp>
10+
11+
namespace boost { namespace crypt {
12+
13+
template<class InputIt1, class InputIt2>
14+
BOOST_CRYPT_GPU_ENABLED constexpr auto equal(InputIt1 first1, InputIt1 last1, InputIt2 first2) -> bool
15+
{
16+
while(first1 != last1)
17+
{
18+
if(!(*first1 == *first2))
19+
{
20+
return false;
21+
}
22+
23+
++first1;
24+
++first2;
25+
}
26+
27+
return true;
28+
}
29+
30+
template<class InputIt1, class InputIt2>
31+
BOOST_CRYPT_GPU_ENABLED constexpr auto lexicographical_compare(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) -> bool
32+
{
33+
while((first1 != last1) && (first2 != last2))
34+
{
35+
if(*first1 < *first2)
36+
{
37+
return true;
38+
}
39+
40+
if(*first2 < *first1)
41+
{
42+
return false;
43+
}
44+
45+
++first1;
46+
++first2;
47+
}
48+
49+
return ((first1 == last1) && (first2 != last2));
50+
}
51+
52+
} // namespace crypt
53+
} // namespace boost
54+
55+
#endif // BOOST_CRYPT_UTILITIES_ALGORITHM_HPP

include/boost/crypt/utility/array.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define BOOST_CRYPT_UTILITIES_ARRAY_HPP
88

99
#include <boost/crypt/utility/config.hpp>
10+
#include <boost/crypt/utility/algorithm.hpp>
1011
#include <boost/crypt/utility/cstdint.hpp>
1112
#include <boost/crypt/utility/cstddef.hpp>
1213
#include <boost/crypt/utility/type_traits.hpp>
@@ -126,6 +127,42 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto fill_array(ForwardIter first, ForwardIter
126127
}
127128
}
128129

130+
template<typename T, size_t N>
131+
BOOST_CRYPT_GPU_ENABLED constexpr auto operator==(const array<T, N>& left, const array<T, N>& right) -> bool
132+
{
133+
return boost::crypt::equal(left.begin(), left.end(), right.begin());
134+
}
135+
136+
template<typename T, size_t N>
137+
BOOST_CRYPT_GPU_ENABLED constexpr auto operator<(const array<T, N>& left, const array<T, N>& right) -> bool
138+
{
139+
return boost::crypt::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end());
140+
}
141+
142+
template<typename T, size_t N>
143+
BOOST_CRYPT_GPU_ENABLED constexpr auto operator!=(const array<T, N>& left, const array<T, N>& right) -> bool
144+
{
145+
return (!(left == right));
146+
}
147+
148+
template<typename T, size_t N>
149+
BOOST_CRYPT_GPU_ENABLED constexpr auto operator>(const array<T, N>& left, const array<T, N>& right) -> bool
150+
{
151+
return (right < left);
152+
}
153+
154+
template<typename T, size_t N>
155+
BOOST_CRYPT_GPU_ENABLED constexpr auto operator>=(const array<T, N>& left, const array<T, N>& right) -> bool
156+
{
157+
return (!(left < right));
158+
}
159+
160+
template<typename T, size_t N>
161+
BOOST_CRYPT_GPU_ENABLED constexpr auto operator<=(const array<T, N>& left, const array<T, N>& right) -> bool
162+
{
163+
return (!(right < left));
164+
}
165+
129166
template<typename T>
130167
class tuple_size;
131168

test/metal/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin

test/metal/app_benchmark_hasher.cpp

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// Copyright Christopher Kormanyos 2023.
3+
// Distributed under the Boost Software License,
4+
// Version 1.0. (See accompanying file LICENSE_1_0.txt
5+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
8+
#if defined(__GNUC__)
9+
#pragma GCC diagnostic push
10+
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
11+
#endif
12+
13+
// cd /mnt/c/ChrisGitRepos/cppalliance/crypt/test/metal
14+
// mkdir -p bin
15+
// arm-none-eabi-g++ -std=c++17 -Wall -Wextra -Wpedantic -O0 -g -gdwarf-2 -ffunction-sections -fdata-sections -x c++ -fno-rtti -fno-use-cxa-atexit -fno-exceptions -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs -ftemplate-depth=128 -mcpu=cortex-m4 -mtune=cortex-m4 -mthumb -mfloat-abi=soft -mno-unaligned-access -mno-long-calls -I../../include -DBOOST_DECIMAL_DISABLE_CLIB -DAPP_BENCHMARK_STANDALONE_MAIN app_benchmark_hasher.cpp ./target/micros/stm32f429/make/single/crt.cpp ./target/micros/stm32f429/make/single/mcal_gcc_cxx_completion_with_stdlib.cpp -nostartfiles -Wl,--gc-sections -Wl,-Map,./bin/app_benchmark_hasher.map -T ./target/micros/stm32f429/make/stm32f429.ld --specs=nano.specs --specs=nosys.specs -Wl,--print-memory-usage -o ./bin/app_benchmark_hasher.elf
16+
// arm-none-eabi-objcopy ./bin/app_benchmark_hasher.elf -O ihex ./bin/app_benchmark_hasher.hex
17+
// ls -la ./bin/app_benchmark_hasher.elf ./bin/app_benchmark_hasher.hex ./bin/app_benchmark_hasher.map
18+
19+
#if !defined(BOOST_CRYPT_STANDALONE)
20+
#define BOOST_DECIMAL_STANDALONE
21+
#endif
22+
23+
#include <boost/crypt/hash/sha256.hpp>
24+
25+
namespace app { namespace benchmark {
26+
27+
namespace detail {
28+
29+
} // namespace detail
30+
31+
auto run_hasher() -> bool;
32+
33+
} // namespace benchmark
34+
} // namespace app
35+
36+
namespace local
37+
{
38+
39+
using hasher_type = boost::crypt::sha256_hasher;
40+
41+
} // namespace local
42+
43+
auto app::benchmark::run_hasher() -> bool
44+
{
45+
auto app_benchmark_result_is_ok = true;
46+
47+
// "abc"
48+
const std::array<std::uint8_t, 3U> message =
49+
{{
50+
0x61U, 0x62U, 0x63U
51+
}};
52+
53+
using local_hasher_type = local::hasher_type;
54+
using local_result_type = typename local_hasher_type::return_type;
55+
56+
const local_result_type control =
57+
{{
58+
0xBAU, 0x78U, 0x16U, 0xBFU, 0x8FU, 0x01U, 0xCFU, 0xEAU,
59+
0x41U, 0x41U, 0x40U, 0xDEU, 0x5DU, 0xAEU, 0x22U, 0x23U,
60+
0xB0U, 0x03U, 0x61U, 0xA3U, 0x96U, 0x17U, 0x7AU, 0x9CU,
61+
0xB4U, 0x10U, 0xFFU, 0x61U, 0xF2U, 0x00U, 0x15U, 0xADU,
62+
}};
63+
64+
local_hasher_type my_hasher { };
65+
66+
my_hasher.init();
67+
68+
my_hasher.process_bytes(message.data(), message.size());
69+
70+
const local_result_type result = my_hasher.get_digest();
71+
72+
const bool result_hash_is_ok { result == control };
73+
74+
app_benchmark_result_is_ok = (result_hash_is_ok && app_benchmark_result_is_ok);
75+
76+
return app_benchmark_result_is_ok;
77+
}
78+
79+
#if defined(APP_BENCHMARK_STANDALONE_MAIN)
80+
constexpr auto app_benchmark_standalone_foodcafe = static_cast<std::uint32_t>(UINT32_C(0xF00DCAFE));
81+
82+
extern "C"
83+
{
84+
extern volatile std::uint32_t app_benchmark_standalone_result;
85+
86+
auto app_benchmark_run_standalone (void) -> bool;
87+
auto app_benchmark_get_standalone_result(void) -> bool;
88+
89+
auto app_benchmark_run_standalone(void) -> bool
90+
{
91+
auto result_is_ok = true;
92+
93+
for(unsigned i = 0U; i < 64U; ++i)
94+
{
95+
result_is_ok &= app::benchmark::run_hasher();
96+
}
97+
98+
app_benchmark_standalone_result =
99+
static_cast<std::uint32_t>
100+
(
101+
result_is_ok ? app_benchmark_standalone_foodcafe : static_cast<std::uint32_t>(UINT32_C(0xFFFFFFFF))
102+
);
103+
104+
return result_is_ok;
105+
}
106+
107+
auto app_benchmark_get_standalone_result(void) -> bool
108+
{
109+
volatile auto result_is_ok = (app_benchmark_standalone_result == static_cast<std::uint32_t>(UINT32_C(0xF00DCAFE)));
110+
111+
return result_is_ok;
112+
}
113+
}
114+
115+
auto main() -> int
116+
{
117+
auto result_is_ok = true;
118+
119+
result_is_ok = (::app_benchmark_run_standalone () && result_is_ok);
120+
result_is_ok = (::app_benchmark_get_standalone_result() && result_is_ok);
121+
122+
return (result_is_ok ? 0 : -1);
123+
}
124+
125+
extern "C"
126+
{
127+
volatile std::uint32_t app_benchmark_standalone_result;
128+
}
129+
#endif // APP_BENCHMARK_STANDALONE_MAIN
130+
131+
#if defined(__GNUC__)
132+
#pragma GCC diagnostic pop
133+
#endif

0 commit comments

Comments
 (0)