multihash implementation in c++.
Multihash is delivered as
The supplied dockerfile produces a reproducable build image which can be used to compile the source:
docker build -t lockblox/multihash multihash
docker run -it --rm -v multihash:/root/src lockblox/multihash
Multihash requires some dependencies to be met before building, which are provided via vcpkg as follows:
git clone https://github.com/lockblox/vcpkg.git \
cd vcpkg \
./bootstrap-vcpkg.sh \
./vcpkg integrate install \
./vcpkg install gtest cryptopp ms-gsl varint
Multihash uses cmake for builds. In order for cmake to find the required dependencies, the -DCMAKE_TOOLCHAIN_FILE
option should be supplied, for example:
cmake -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake" ../multihash
cmake --build .
At the lowest level, there is the abstract type multihash::algorithm
.
A multihash::algorithm
defines the steps required to compute a hash from
input data.
multihash::algorithm
instances are created by a factory and each factory is
registered under a unique hash code identifier.
auto code = multihash::code::sha3_256;
auto algorithm = multihash::algorithm::create(code);
auto buffer = std::string{"hello, world"};
algorithm->update(buffer);
auto result = std::string(256, '=');
algorithm->digest(result);
A multihash::function
is a hash functor which operates on iterator pairs.
auto multihash = multihash::function(code)(input.begin(), input.end());
A multihash::multihash
combines the hash code and multihash in a binary payload.
auto code = multihash.code();
auto multihash = multihash.multihash();
multihash is released under the MIT License.