Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
hashers.test.cpp
Go to the documentation of this file.
1#include <gtest/gtest.h>
2
3#include "../hashers/hashers.hpp"
4
5#include <array>
6#include <cstddef>
7#include <stdint.h>
8#include <vector>
9
10using namespace bb;
11using namespace bb::crypto;
12
13namespace {
14
15std::string bytes_to_hex_string(const std::vector<uint8_t>& bytes)
16{
17 static constexpr std::array<char, 16> HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7',
18 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
19 std::string hex(bytes.size() * 2, '\0');
20 for (size_t i = 0; i < bytes.size(); ++i) {
21 hex[2 * i] = HEX_CHARS[bytes[i] >> 4];
22 hex[(2 * i) + 1] = HEX_CHARS[bytes[i] & 0x0f];
23 }
24 return hex;
25}
26
27} // namespace
28
29TEST(Sha256, EmptyHash)
30{
31 auto hash = Sha256Hasher::hash(std::vector<uint8_t>{});
32 std::vector<uint8_t> hash_vec(hash.begin(), hash.end());
33 auto hash_string = bytes_to_hex_string(hash_vec);
34 EXPECT_EQ(hash_string, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
35}
36
37TEST(Keccak, EmptyHash)
38{
39 auto hash = KeccakHasher::hash(std::vector<uint8_t>{});
40 std::vector<uint8_t> hash_vec(hash.begin(), hash.end());
41 auto hash_string = bytes_to_hex_string(hash_vec);
42 EXPECT_EQ(hash_string, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
43}
44
45TEST(Blake2s, EmptyHash)
46{
47 auto hash = Blake2sHasher::hash(std::vector<uint8_t>{});
48 std::vector<uint8_t> hash_vec(hash.begin(), hash.end());
49 auto hash_string = bytes_to_hex_string(hash_vec);
50 EXPECT_EQ(hash_string, "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9");
51}
A wrapper class used to construct KeccakTranscript.
Definition keccak.hpp:52
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
std::string bytes_to_hex_string(const std::vector< uint8_t > &bytes)
Convert bytes to a hex string with 0x prefix.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static auto hash(const std::vector< uint8_t > &message)
Definition hashers.hpp:42
static std::vector< uint8_t > hash(const std::vector< uint8_t > &message)
Definition hashers.hpp:20
static auto hash(const B &message)
Definition hashers.hpp:36