Usage

Table of Contents

Quick Start

The easiest way to use Crypto3.Hash library is to use an algorithm with implicit state usage. Following example hash byte sequence with MD5 hashes:

using namespace nil::crypto3;
int main(int argc, char *argv[]) {
std::string input = "abc";
std::string out = hash<hashes::md5>(input.begin(), input.end());
assert(out == "900150983cd24fb0d6963f7d28e17f72");
}
Definition: pair.hpp:32

Similar technique is available for ranges:

using namespace nil::crypto3;
int main(int argc, char *argv[]) {
std::string input = "abc";
std::string out = hashes<hash::md5>(input);
assert(out == "900150983cd24fb0d6963f7d28e17f72");
}

Stateful hashing

In case of accumulative hashes requirement is present, following example demonstrates accumulator usage:

using namespace nil::crypto3;
int main(int argc, char *argv[]) {
accumulator_set<hashes::md5> acc;
std::string input = "abc";
hash<hashes::md5>(input.begin(), input.end(), acc);
std::string out = std::to_string(extract::hash<hashes::md5>(acc));
assert(out == "900150983cd24fb0d6963f7d28e17f72");
}
std::string to_string(const nil::crypto3::digest< DigestBits > &d)
Definition: block/include/nil/crypto3/detail/digest.hpp:248