Skip to content

Commit a8a88f8

Browse files
committed
set up GitHub mirror
1 parent 21d2fed commit a8a88f8

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Diff for: LICENSE

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
zlib License
2+
3+
Copyright (c) 2014,2015 Stephan Brumme
4+
5+
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
6+
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
7+
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
8+
If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
9+
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
10+
3. This notice may not be removed or altered from any source distribution.

Diff for: readme.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Portable C++ Hashing Library
2+
3+
This is a mirror of my library hosted at https://create.stephan-brumme.com/hash-library/
4+
5+
In a nutshell:
6+
7+
- computes CRC32, MD5, SHA1 and SHA256 (most common member of the SHA2 functions), Keccak and its SHA3 sibling
8+
- optional HMAC (keyed-hash message authentication code)
9+
- no external dependencies, small code size
10+
- can work chunk-wise (for example when reading streams block-by-block)
11+
- portable: supports Windows and Linux, tested on Little Endian and Big Endian CPUs
12+
- roughly as fast as Linux core hashing functions
13+
- open source, zlib license
14+
15+
You can find code examples, benchmarks and much more on my website https://create.stephan-brumme.com/hash-library/
16+
17+
# How to use
18+
19+
This example computes SHA256 hashes but the API is more or less identical for all hash algorithms:
20+
21+
``` cpp
22+
// SHA2 test program
23+
#include "sha256.h"
24+
#include <iostream> // for std::cout only, not needed for hashing library
25+
26+
int main(int, char**)
27+
{
28+
// create a new hashing object
29+
SHA256 sha256;
30+
31+
// hashing an std::string
32+
std::cout << sha256("Hello World") << std::endl;
33+
// => a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e
34+
35+
// hashing a buffer of bytes
36+
const char* buffer = "How are you";
37+
std::cout << sha256(buffer, 11) << std::endl;
38+
// => 9c7d5b046878838da72e40ceb3179580958df544b240869b80d0275cc07209cc
39+
40+
// or in a streaming fashion (re-use "How are you")
41+
SHA256 sha256stream;
42+
const char* url = "create.stephan-brumme.com"; // 25 bytes
43+
int step = 5;
44+
for (int i = 0; i < 25; i += step)
45+
sha256stream.add(url + i, step); // add five bytes at a time
46+
std::cout << sha256stream.getHash() << std::endl;
47+
// => 82aa771f1183c52f973c798c9243a1c73833ea40961c73e55e12430ec77b69f6
48+
49+
return 0;
50+
}
51+
```

0 commit comments

Comments
 (0)