Hash
C++14 header-only easy-to-use cryptographic hash library
[AppVeyor_badge]: https://ci.appveyor.com/api/projects/status/github/Chocobo1/Hash?branch=master&svg=true [AppVeyor_link]: https://ci.appveyor.com/project/Chocobo1/Hash [GithubAction_badge]: https://github.com/Chocobo1/Hash/workflows/CI/badge.svg [GithubAction_link]: https://github.com/Chocobo1/Hash/actions The project is written primarily in C++, distributed under the GNU General Public License v3.0 license, first published in 2017. Key topics include: cpp, crc32, hash, md5, sha2.
Hash

C++14 header-only easy-to-use hash library
What is included in this library:
If you are concerned about security, state-of-the-art performance or whatsoever issue,
then take your time and go setup OpenSSL or other proven library
Now some features:
- No/none tweaking knobs, it just works!
<br /> Works out-of-the-box on little endian & big endian machines - Have similar performance to C implementations: see my rudimentary benchmark: Benchmark.md
Prerequisites
- Library only:
- Tests & driver program:
Usage
To use this library in your project:
-
Download this repository and unzip it
-
Use it like:
c// include the header #include "pathToLib/sha1.h" // If you are using C++14 or C++17, don't forget the "gsl" folder! void example() { // Get an instance Chocobo1::SHA1 sha1; // Feed data & data length to it sha1.addData("hello", 5); // ... or just sha1.addData("hello"); // Tell it to wrap it up sha1.finalize(); // Profit! oops, not really... std::string result = sha1.toString(); // A one-liner std::string result2 = Chocobo1::SHA1().addData("hello").finalize().toString(); // In byte array form auto bytes = Chocobo1::SHA1().addData("hello").finalize().toArray(); // std::array<uint8_t, 20> // Some hash algorithm provides constexpr result under C++17 constexpr uint8_t data[] = {0x00, 0xFF}; constexpr auto bytes2 = Chocobo1::SHA1().addData(data).finalize().toArray(); } -
There is also a driver program included, you can find it at "src/program"
-
Compile:
shellcd src/program meson _builddir # initialize build folder cd _builddir ninja # call the `ninja` to build our program -
Run:
shell$ ./hash -md5 /path/to/file
-
Run Tests
shellcd tests meson _build cd _build ninja ./run_tests
Dependencies
- Microsoft/GSL
This library is only required when compiling with C++14 and C++17. In C++20 or later,
std::spanwill be used in place ofgsl::span.
No need to download or install it. This repository included a modified version that will
compile locally (only forgsl::spanrelated headers).
License
See LICENSE file
Like it?
Please consider donate
Contributors
Showing top 3 contributors by commit count.
