-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblake2b.cpp
42 lines (32 loc) · 942 Bytes
/
blake2b.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <dice/hash/blake/Blake2b.hpp>
#include <iostream>
#include <string_view>
#include <vector>
void print_bytes(std::span<std::byte const> bytes) noexcept {
for (auto b : bytes) {
std::cout << std::hex << static_cast<unsigned>(b);
}
std::cout << "\n\n";
}
int main() {
using namespace std::string_view_literals;
using namespace dice::hash::blake2b;
auto data1 = as_bytes(std::span<char const>{"spherical cow"sv});
auto data2 = as_bytes(std::span<char const>{"hello world"sv});
auto data3 = as_bytes(std::span<char const>{"penguins"sv});
{ // stateful hashing
Blake2b blake{max_output_extent};
blake.digest(data1);
blake.digest(data2);
std::vector<std::byte> output;
output.resize(max_output_extent);
std::move(blake).finish(output);
print_bytes(output);
}
{ // one-off hashing
std::vector<std::byte> output;
output.resize(32);
Blake2b<>::hash_single(data3, output);
print_bytes(output);
}
}