Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
sha256.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
10#include "stdint.h"
11#include <array>
12#include <iomanip>
13#include <ostream>
14#include <vector>
15
16namespace bb::crypto {
17
18using Sha256Hash = std::array<uint8_t, 32>;
19
20Sha256Hash sha256_block(const std::vector<uint8_t>& input);
21
22template <typename T> Sha256Hash sha256(const T& input);
23
24inline bb::fr sha256_to_field(std::vector<uint8_t> const& input)
25{
26 auto result = sha256(input);
27 return from_buffer<bb::fr>(&result[0]);
28}
29
30inline bool operator==(Sha256Hash const& lhs, std::vector<uint8_t> const& rhs)
31{
32 return std::equal(lhs.begin(), lhs.end(), rhs.begin());
33}
34
35} // namespace bb::crypto
36
37namespace std {
38inline bool operator==(std::vector<uint8_t> const& lhs, bb::crypto::Sha256Hash const& rhs)
39{
40 return std::equal(lhs.begin(), lhs.end(), rhs.begin());
41}
42
43inline std::ostream& operator<<(std::ostream& os, bb::crypto::Sha256Hash const& arr)
44{
45 std::ios_base::fmtflags f(os.flags());
46 os << std::hex << std::setfill('0');
47 for (auto byte : arr) {
48 os << std::setw(2) << +(unsigned char)byte;
49 }
50 os.flags(f);
51 return os;
52}
53} // namespace std
Sha256Hash sha256(const ByteContainer &input)
Definition sha256.cpp:142
std::array< uint8_t, 32 > Sha256Hash
Definition sha256.hpp:18
bool operator==(ecdsa_signature const &lhs, ecdsa_signature const &rhs)
Definition ecdsa.hpp:45
std::array< uint32_t, 8 > sha256_block(const std::array< uint32_t, 8 > &h_init, const std::array< uint32_t, 16 > &input)
Definition sha256.cpp:48
bb::fr sha256_to_field(std::vector< uint8_t > const &input)
Definition sha256.hpp:24
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
bool operator==(std::vector< uint8_t > const &lhs, bb::crypto::Sha256Hash const &rhs)
Definition sha256.hpp:38
std::ostream & operator<<(std::ostream &os, const T &obj)
Automatically derived stream operator for any object that defines .msgpack() (implicitly defined by M...
Definition streams.hpp:79