diff --git a/.github/workflows/metal.yml b/.github/workflows/metal.yml index e4be6c8..592b4f1 100644 --- a/.github/workflows/metal.yml +++ b/.github/workflows/metal.yml @@ -21,6 +21,10 @@ jobs: defaults: run: shell: bash + strategy: + fail-fast: false + matrix: + testcase: [ hasher_256, hasher_512 ] steps: - uses: actions/checkout@v4 with: @@ -37,9 +41,9 @@ jobs: - name: build benchmark_single-stm32f429 run: | mkdir -p bin - 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_NO_EXCEPTIONS -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 - 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 - ls -la ./bin/app_benchmark_hasher.elf ./bin/app_benchmark_hasher.hex ./bin/app_benchmark_hasher.map + 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_NO_EXCEPTIONS -DBOOST_CRYPT_DISABLE_IOSTREAM -DAPP_BENCHMARK_STANDALONE_MAIN app_benchmark_${{ matrix.testcase }}.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_${{ matrix.testcase }}.map -T ./target/micros/stm32f429/make/stm32f429.ld --specs=nano.specs --specs=nosys.specs -Wl,--print-memory-usage -o ./bin/app_benchmark_${{ matrix.testcase }}.elf + emu_env/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-objcopy ./bin/app_benchmark_${{ matrix.testcase }}.elf -O ihex ./bin/app_benchmark_${{ matrix.testcase }}.hex + ls -la ./bin/app_benchmark_${{ matrix.testcase }}.elf ./bin/app_benchmark_${{ matrix.testcase }}.hex ./bin/app_benchmark_${{ matrix.testcase }}.map working-directory: ./test/metal/ - name: emulate-target stm32f429 run: | @@ -47,7 +51,7 @@ jobs: working-directory: ./test/metal/ - name: run-test-on-target run: | - ./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 + ./emu_env/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gdb-py ./bin/app_benchmark_${{ matrix.testcase }}.elf -x ./target/build/test_app_benchmarks_emulator.py qemu_result=$? echo "qemu_result" "$qemu_result" echo "qemu_result" "$qemu_result" | grep 'qemu_result 0' diff --git a/include/boost/crypt/hash/sha512.hpp b/include/boost/crypt/hash/sha512.hpp index d704d9c..681b639 100644 --- a/include/boost/crypt/hash/sha512.hpp +++ b/include/boost/crypt/hash/sha512.hpp @@ -222,6 +222,8 @@ auto sha512_file_impl(utility::file_reader& reader) noexcept -> sha5 } // namespace detail +#ifndef BOOST_CRYPT_DISABLE_IOSTREAM + BOOST_CRYPT_EXPORT inline auto sha512_file(const std::string& filepath) noexcept -> sha512_hasher::return_type { try @@ -253,7 +255,9 @@ BOOST_CRYPT_EXPORT inline auto sha512_file(const char* filepath) noexcept -> sha } } -#ifdef BOOST_CRYPT_HAS_STRING_VIEW +#endif // !BOOST_CRYPT_DISABLE_IOSTREAM + +#if (defined(BOOST_CRYPT_HAS_STRING_VIEW) && !defined(BOOST_CRYPT_DISABLE_IOSTREAM)) BOOST_CRYPT_EXPORT inline auto sha512_file(std::string_view filepath) noexcept -> sha512_hasher::return_type { @@ -268,7 +272,7 @@ BOOST_CRYPT_EXPORT inline auto sha512_file(std::string_view filepath) noexcept - } } -#endif // BOOST_CRYPT_HAS_STRING_VIEW +#endif // BOOST_CRYPT_HAS_STRING_VIEW && !BOOST_CRYPT_DISABLE_IOSTREAM #endif // BOOST_CRYPT_HAS_CUDA diff --git a/test/metal/app_benchmark_hasher.cpp b/test/metal/app_benchmark_hasher_256.cpp similarity index 70% rename from test/metal/app_benchmark_hasher.cpp rename to test/metal/app_benchmark_hasher_256.cpp index 6aeda68..20865e0 100644 --- a/test/metal/app_benchmark_hasher.cpp +++ b/test/metal/app_benchmark_hasher_256.cpp @@ -1,20 +1,15 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2023. +// Copyright Christopher Kormanyos 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif - // cd /mnt/c/ChrisGitRepos/cppalliance/crypt/test/metal // mkdir -p bin -// 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 -// arm-none-eabi-objcopy ./bin/app_benchmark_hasher.elf -O ihex ./bin/app_benchmark_hasher.hex -// ls -la ./bin/app_benchmark_hasher.elf ./bin/app_benchmark_hasher.hex ./bin/app_benchmark_hasher.map +// 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 -ftemplate-depth=128 -mcpu=cortex-m4 -mtune=cortex-m4 -mthumb -mfloat-abi=soft -mno-unaligned-access -mno-long-calls -I../../include -DBOOST_CRYPT_DISABLE_IOSTREAM -DBOOST_CRYPT_NO_EXCEPTIONS -DAPP_BENCHMARK_STANDALONE_MAIN app_benchmark_hasher_256.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_256.map -T ./target/micros/stm32f429/make/stm32f429.ld --specs=nano.specs --specs=nosys.specs -Wl,--print-memory-usage -o ./bin/app_benchmark_hasher_256.elf +// arm-none-eabi-objcopy ./bin/app_benchmark_hasher_256.elf -O ihex ./bin/app_benchmark_hasher_256.hex +// ls -la ./bin/app_benchmark_hasher_256.elf ./bin/app_benchmark_hasher_256.hex ./bin/app_benchmark_hasher_256.map #if !defined(BOOST_CRYPT_STANDALONE) #define BOOST_DECIMAL_STANDALONE @@ -28,7 +23,7 @@ namespace detail { } // namespace detail -auto run_hasher() -> bool; +auto run_hasher_256() -> bool; } // namespace benchmark } // namespace app @@ -40,12 +35,12 @@ namespace local } // namespace local -auto app::benchmark::run_hasher() -> bool +auto app::benchmark::run_hasher_256() -> bool { auto app_benchmark_result_is_ok = true; // "abc" - const std::array message = + const std::array message = {{ 0x61U, 0x62U, 0x63U }}; @@ -53,7 +48,7 @@ auto app::benchmark::run_hasher() -> bool using local_hasher_type = local::hasher_type; using local_result_type = typename local_hasher_type::return_type; - const local_result_type control = + constexpr local_result_type control = {{ 0xBAU, 0x78U, 0x16U, 0xBFU, 0x8FU, 0x01U, 0xCFU, 0xEAU, 0x41U, 0x41U, 0x40U, 0xDEU, 0x5DU, 0xAEU, 0x22U, 0x23U, @@ -67,7 +62,7 @@ auto app::benchmark::run_hasher() -> bool my_hasher.process_bytes(message.data(), message.size()); - const local_result_type result = my_hasher.get_digest(); + const local_result_type result { my_hasher.get_digest() }; const bool result_hash_is_ok { result == control }; @@ -92,7 +87,7 @@ extern "C" for(unsigned i = 0U; i < 64U; ++i) { - result_is_ok &= app::benchmark::run_hasher(); + result_is_ok &= app::benchmark::run_hasher_256(); } app_benchmark_standalone_result = @@ -128,6 +123,3 @@ extern "C" } #endif // APP_BENCHMARK_STANDALONE_MAIN -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif diff --git a/test/metal/app_benchmark_hasher_512.cpp b/test/metal/app_benchmark_hasher_512.cpp new file mode 100644 index 0000000..8f6ffbd --- /dev/null +++ b/test/metal/app_benchmark_hasher_512.cpp @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +// cd /mnt/c/ChrisGitRepos/cppalliance/crypt/test/metal +// mkdir -p 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 -ftemplate-depth=128 -mcpu=cortex-m4 -mtune=cortex-m4 -mthumb -mfloat-abi=soft -mno-unaligned-access -mno-long-calls -I../../include -DBOOST_CRYPT_DISABLE_IOSTREAM -DBOOST_CRYPT_NO_EXCEPTIONS -DAPP_BENCHMARK_STANDALONE_MAIN app_benchmark_hasher_512.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_512.map -T ./target/micros/stm32f429/make/stm32f429.ld --specs=nano.specs --specs=nosys.specs -Wl,--print-memory-usage -o ./bin/app_benchmark_hasher_512.elf +// arm-none-eabi-objcopy ./bin/app_benchmark_hasher_512.elf -O ihex ./bin/app_benchmark_hasher_512.hex +// ls -la ./bin/app_benchmark_hasher_512.elf ./bin/app_benchmark_hasher_512.hex ./bin/app_benchmark_hasher_512.map + +#if !defined(BOOST_CRYPT_STANDALONE) +#define BOOST_DECIMAL_STANDALONE +#endif + +#include + +namespace app { namespace benchmark { + +namespace detail { + +} // namespace detail + +auto run_hasher_512() -> bool; + +} // namespace benchmark +} // namespace app + +namespace local +{ + + using hasher_type = boost::crypt::sha512_hasher; + +} // namespace local + +auto app::benchmark::run_hasher_512() -> bool +{ + auto app_benchmark_result_is_ok = true; + + // "abc" + const std::array message = + {{ + 0x61U, 0x62U, 0x63U + }}; + + using local_hasher_type = local::hasher_type; + using local_result_type = typename local_hasher_type::return_type; + + constexpr local_result_type control = + {{ + 0xDDU, 0xAFU, 0x35U, 0xA1U, 0x93U, 0x61U, 0x7AU, 0xBAU, + 0xCCU, 0x41U, 0x73U, 0x49U, 0xAEU, 0x20U, 0x41U, 0x31U, + 0x12U, 0xE6U, 0xFAU, 0x4EU, 0x89U, 0xA9U, 0x7EU, 0xA2U, + 0x0AU, 0x9EU, 0xEEU, 0xE6U, 0x4BU, 0x55U, 0xD3U, 0x9AU, + 0x21U, 0x92U, 0x99U, 0x2AU, 0x27U, 0x4FU, 0xC1U, 0xA8U, + 0x36U, 0xBAU, 0x3CU, 0x23U, 0xA3U, 0xFEU, 0xEBU, 0xBDU, + 0x45U, 0x4DU, 0x44U, 0x23U, 0x64U, 0x3CU, 0xE8U, 0x0EU, + 0x2AU, 0x9AU, 0xC9U, 0x4FU, 0xA5U, 0x4CU, 0xA4U, 0x9FU, + }}; + + local_hasher_type my_hasher { }; + + my_hasher.init(); + + my_hasher.process_bytes(message.data(), message.size()); + + const local_result_type result { my_hasher.get_digest() }; + + const bool result_hash_is_ok { result == control }; + + app_benchmark_result_is_ok = (result_hash_is_ok && app_benchmark_result_is_ok); + + return app_benchmark_result_is_ok; +} + +#if defined(APP_BENCHMARK_STANDALONE_MAIN) +constexpr auto app_benchmark_standalone_foodcafe = static_cast(UINT32_C(0xF00DCAFE)); + +extern "C" +{ + extern volatile std::uint32_t app_benchmark_standalone_result; + + auto app_benchmark_run_standalone (void) -> bool; + auto app_benchmark_get_standalone_result(void) -> bool; + + auto app_benchmark_run_standalone(void) -> bool + { + auto result_is_ok = true; + + for(unsigned i = 0U; i < 64U; ++i) + { + result_is_ok &= app::benchmark::run_hasher_512(); + } + + app_benchmark_standalone_result = + static_cast + ( + result_is_ok ? app_benchmark_standalone_foodcafe : static_cast(UINT32_C(0xFFFFFFFF)) + ); + + return result_is_ok; + } + + auto app_benchmark_get_standalone_result(void) -> bool + { + volatile auto result_is_ok = (app_benchmark_standalone_result == static_cast(UINT32_C(0xF00DCAFE))); + + return result_is_ok; + } +} + +auto main() -> int +{ + auto result_is_ok = true; + + result_is_ok = (::app_benchmark_run_standalone () && result_is_ok); + result_is_ok = (::app_benchmark_get_standalone_result() && result_is_ok); + + return (result_is_ok ? 0 : -1); +} + +extern "C" +{ + volatile std::uint32_t app_benchmark_standalone_result; +} +#endif // APP_BENCHMARK_STANDALONE_MAIN +