A simple implementation of SHA-256 in C++ (header-only). This implementation uses little endian byte order.
- The following program shows a test example
// Create an object of hash_sha256
hash_sha256 hash1;
// Original message
const std::array<std::uint8_t, 3U> msg1 = {'a', 'b', 'c' };
// Initialize hash
hash1.sha256_init();
// Update the hash with given data
hash1.sha256_update(msg1.data(), msg1.size());
// Get hash result
sha256_output_type hash_result1 = hash1.sha256_final();
Testing and continuous integration runs on GitHub Actions. Various OS/compiler combinations are used including GCC/clang/MSVC.
Code coverage uses GCC/gcov/lcov and has a quality-gate with comparison/baseline-check provided by third-party Codecov.
Additional quality checks are performed on pull-request and merge to master using modern third party open-source services. These include LGTM and CodeSonar.
The following picture shows the real-time measurement of the sha256
benchmark run on 32-bit microcontrollers (ARM Cortex™ M4) of the NUCLEO-F446RE
board.
The hash calculation takes about 32 µs
Algorithm specification can be found here: