Awesome Open Source
Awesome Open Source


Purpose

Hash++ is a C++20 header-only library that allows a user to retrieve multiple types of hashes from data, files, and files in nested directories. The original purpose behind this library was to create a header-file only implementation of multiple different hash algorithms. You can find a list of the currently supported hash algorithms below.

Supported Algorithms

  • MD5
  • MD4
  • MD2
  • SHA-1
  • SHA2-224
  • SHA2-256
  • SHA2-384
  • SHA2-512
  • SHA2-512/224
  • SHA2-512/256
  • Upcoming (Sooner-or-Later) Algorithms:
    • SHA3
    • BLAKE
    • Whirlpool
    • RIPEMD-160
    • etc...

Hash++ also aims to be a suitable alternative to heavier, statically and dynamically-linked libraries such as OpenSSL and Crypto++. I created it keeping in mind the mindset of a programmer who simply wants a header-only file that lets them easily and comfortably "just hash sh*t." Does it really have to be that difficult?

No, it doesn't.

Algorithm Metrics

Below you can find single-threaded speed metrics of each algorithm when generating ten million hashes of 4 repetitions of the upper and lowercase alphabet, plus base 10 digits: 4(a-z+A-Z+0-9)
+----------------------------------------------------------------+
|    Algorithms    |            Computational Metrics            |
|------------------|---------------------------------------------|
| 64-bit test:     |           |           |                     |
|   [MD5]          | 8793   ms | 8.793   s | 1,137,268  hashes/s |
|   [MD4]          | 7258   ms | 7.258   s | 1,377,790  hashes/s |
|   [MD2]          | 323220 ms | 323.220 s | 30,939     hashes/s | 
|   [SHA1]         | 10020  ms | 10.020  s | 998,004    hashes/s |
|   [SHA2-224]     | 13442  ms | 13.442  s | 743,937    hashes/s |
|   [SHA2-256]     | 13668  ms | 13.668  s | 731,636    hashes/s |
|   [SHA2-384]     | 10324  ms | 10.324  s | 968,617    hashes/s |
|   [SHA2-512]     | 10680  ms | 10.680  s | 936,330    hashes/s |
|   [SHA2-512/224] | 9748   ms | 9.748   s | 1,025,852  hashes/s |
|   [SHA2-512/256] | 9965   ms | 9.965   s | 1,003,512  hashes/s |
|------------------|-----------|-----------|---------------------|
| 32-bit test:     |           |           |                     |
|   [MD5]          | 10707  ms | 10.707  s | 933,968    hashes/s |
|   [MD4]          | 7815   ms | 7.815   s | 1,279,591  hashes/s |
|   [MD2]          | 204250 ms | 204.250 s | 48,960     hashes/s |
|   [SHA1]         | 11942  ms | 11.942  s | 837,381    hashes/s |
|   [SHA2-224]     | 16518  ms | 16.518  s | 605,400    hashes/s |
|   [SHA2-256]     | 16306  ms | 16.306  s | 613,271    hashes/s |
|   [SHA2-384]     | 25171  ms | 25.171  s | 397,283    hashes/s |
|   [SHA2-512]     | 26746  ms | 26.746  s | 373,888    hashes/s |
|   [SHA2-512/224] | 24418  ms | 24.418  s | 409,534    hashes/s |
|   [SHA2-512/256] | 24343  ms | 24.343  s | 410,796    hashes/s |
+----------------------------------------------------------------+
*Updated as of 11/15/2021; all computed on a stock i9 12900K

Using Hash++

My original design idea behind Hash++ was for it to be simple. This has remained unchanged.

Below you can find the signatures of the only functions necessary to accomplish retrieving hashes from both single or multiple sets of data, files, and files in nested directories. All functions are located in the hashpp namespace under class get (hashpp::get).

You can find examples of Hash++ in use in the /examples and /tests directories.

getHash

Retrieve a single hash from a single piece of data.
// function to return a resulting hash from selected ALGORITHM and passed data
constexpr static hashpp::hash getHash(hashpp::ALGORITHMS algorithm, std::string data)

getHashes

Retrieve a collection of hashes from multiple pieces of data.
// function to return a collection of resulting hashes from selected ALGORITHMS and passed data
static hashpp::hashCollection getHashes(std::vector<std::pair<hashpp::ALGORITHMS, std::vector<std::string>>> algorithmDataPairs)

getFileHash

Retrieve a single hash from a single file.
// function to return a resulting hash from selected ALGORITHM and passed file
static hashpp::hash getFileHash(hashpp::ALGORITHMS algorithm, std::string path)

getFilesHashes

Retrieve a collection of hashes from multiple files or files in nested directories.
// function to return a collection of resulting hashes from selected ALGORITHMS and passed files (with recursive directory support)
static hashpp::hashCollection getFilesHashes(std::vector<std::pair<hashpp::ALGORITHMS, std::vector<std::string>>> algorithmPathPairs)

Notes

I designed this library without machine endianness in mind. A lot of common architectures are either little-endian or bi-endian, so, I decided to simply design it following what byte-order is most common. This has only been tested on little-endian architectures.

I have noticed some strange behavior with getFilesHashes and some duplicate hashes showing up for different files. This could have been an error on my part during testing, but I am keeping an eye on it.
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
C Plus Plus (235,506
Algorithms (37,370
Hash (11,361
Cryptography (10,601
Openssl (4,346
Hashing (2,824
Md5 (1,396
Sha256 (830
Header Only (808
Sha1 (722
Sha512 (139
Hashes (66
Sha2 (61
Sha384 (55
Sha224 (37
Md2 (14
Md4 (14