https://github.com/newyaroslav/siphash-cpp
SipHash Headers Only C ++ Library
https://github.com/newyaroslav/siphash-cpp
c-plus-plus cpp11 cpp17 cryptographic-hash-functions cryptography hash library pseudorandom-functions siphash
Last synced: 26 days ago
JSON representation
SipHash Headers Only C ++ Library
- Host: GitHub
- URL: https://github.com/newyaroslav/siphash-cpp
- Owner: NewYaroslav
- License: cc0-1.0
- Created: 2021-10-09T06:26:15.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-09-04T13:38:21.000Z (2 months ago)
- Last Synced: 2025-09-04T14:40:34.592Z (2 months ago)
- Topics: c-plus-plus, cpp11, cpp17, cryptographic-hash-functions, cryptography, hash, library, pseudorandom-functions, siphash
- Language: C++
- Homepage:
- Size: 43.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# siphash_cpp
[](https://github.com/NewYaroslav/siphash-cpp/actions/workflows/CI-Linux.yml)
[](https://github.com/NewYaroslav/siphash-cpp/actions/workflows/CI-Win.yml)
[SipHash](https://en.wikipedia.org/wiki/SipHash) header only C ++ library.
SipHash is a family of keyed hash functions optimized for short messages. It is widely used to protect hash tables from collision attacks and to authenticate lightweight data.
### Advantages
- Secret key makes hash-flooding attacks impractical
- Small, simple code that runs quickly on short inputs
### Limitations
- Slower than non-cryptographic hashes such as MurmurHash
- 64-bit output is not meant for high-security message authentication or large files
The key must contain at least 16 bytes.
Example:
```cpp
#include "siphash.hpp"
\\...
std::array key = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
std::string data("hello");
std::cout << "SipHash-2-4 for 'hello': " << siphash_cpp::siphash_2_4(data, key) << std::endl;
std::cout << "SipHash-4-8 for 'hello': " << siphash_cpp::siphash_4_8(data, key) << std::endl;
std::cout << "SipHash-4-8 for 'hello': " << siphash_cpp::siphash(data, key, 4, 8) << std::endl;
siphash_cpp::SipHash siphash;
siphash.init(key, 2, 4);
std::cout << "SipHash-2-4 for 'hello': " << siphash.update(data).digest() << std::endl;
```
## Installation
### vcpkg
This library can be installed with [vcpkg](https://github.com/microsoft/vcpkg):
```sh
vcpkg install siphash-cpp
```
After installation, a CMake project may use:
```cmake
find_package(siphash_cpp CONFIG REQUIRED)
target_link_libraries(your_app PRIVATE siphash_cpp::siphash_cpp)
```
To verify the build with vcpkg, run:
```sh
VCPKG_ROOT=/path/to/vcpkg ./scripts/run_tests.sh
```
### Git submodule
```sh
git submodule add https://github.com/NewYaroslav/siphash-cpp.git external/siphash-cpp
```
Then add the subdirectory and link the target in your `CMakeLists.txt`:
```cmake
add_subdirectory(external/siphash-cpp)
target_link_libraries(your_app PRIVATE siphash_cpp::siphash_cpp)
```
## Related Projects
- [hmac-cpp](https://github.com/NewYaroslav/hmac-cpp)
- [aes-cpp](https://github.com/NewYaroslav/aes-cpp)