Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
hashers.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
9#include "../blake2s/blake2s.hpp"
10#include "../keccak/keccak.hpp"
11#include "../sha256/sha256.hpp"
12
13#include "memory.h"
14#include <vector>
15
16namespace bb::crypto {
18 static constexpr size_t BLOCK_SIZE = 64;
19 static constexpr size_t OUTPUT_SIZE = 32;
20 static std::vector<uint8_t> hash(const std::vector<uint8_t>& message)
21 {
22 keccak256 hash_result = ethash_keccak256(&message[0], message.size());
23
24 std::vector<uint8_t> output;
25 output.resize(32);
26
27 memcpy((void*)&output[0], (void*)&hash_result.word64s[0], 32);
28 return output;
29 }
30};
31
33 static constexpr size_t BLOCK_SIZE = 64;
34 static constexpr size_t OUTPUT_SIZE = 32;
35
36 template <typename B = std::vector<uint8_t>> static auto hash(const B& message) { return sha256(message); }
37};
38
40 static constexpr size_t BLOCK_SIZE = 64;
41 static constexpr size_t OUTPUT_SIZE = 32;
42 static auto hash(const std::vector<uint8_t>& message) { return blake2s(message); }
43};
44} // namespace bb::crypto
struct keccak256 ethash_keccak256(const uint8_t *data, size_t size) NOEXCEPT
Definition keccak.cpp:107
Sha256Hash sha256(const ByteContainer &input)
Definition sha256.cpp:142
std::array< uint8_t, BLAKE2S_OUTBYTES > blake2s(std::vector< uint8_t > const &input)
Definition blake2s.cpp:232
static constexpr size_t BLOCK_SIZE
Definition hashers.hpp:40
static constexpr size_t OUTPUT_SIZE
Definition hashers.hpp:41
static auto hash(const std::vector< uint8_t > &message)
Definition hashers.hpp:42
static constexpr size_t BLOCK_SIZE
Definition hashers.hpp:18
static std::vector< uint8_t > hash(const std::vector< uint8_t > &message)
Definition hashers.hpp:20
static constexpr size_t OUTPUT_SIZE
Definition hashers.hpp:19
static auto hash(const B &message)
Definition hashers.hpp:36
static constexpr size_t OUTPUT_SIZE
Definition hashers.hpp:34
static constexpr size_t BLOCK_SIZE
Definition hashers.hpp:33
uint64_t word64s[4]