Skip to content

imahjoub/hash_sha256

Repository files navigation

hash_sha256

Build Status Issues CodeQL Codacy Badge Quality Gate Status code coverage Boost Software License 1.0

A simple implementation of SHA-256 in C++ (header-only). This implementation uses little endian byte order.

Using the hash_sha256

  • The following program shows a test example, which is compiled sucessfully int he following short link to godbolt.
// Create an object of hash_sha256
hash_sha256 hash;

// Original message
const std::array<std::uint8_t, 3U> msg = {'a', 'b', 'c' };

// Initialize hash
hash.sha256_init();

// Update the hash with given data
hash.sha256_update(msg.data(), msg.size());

// Get hash result
sha256_output_type hash_result = hash.sha256_final();

Testing, continuous integration and quality

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.

Algorithm efficiency

This measurement follows the technique described in ckormanyos/real-time-cpp, in particular from the Benchmarks.

  • The test equipment is shown in the picture below

bench_equipement

  • 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 31 µs

bench_2

References

Algorithm specification can be found here: