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
9#include "stdint.h"
10#include <array>
11#include <iomanip>
12#include <ostream>
13#include <vector>
14
15namespace bb::crypto {
16
17using Sha256Hash = std::array<uint8_t, 32>;
18
19// SHA-256 compression function (FIPS 180-4 Section 6.2.2)
20std::array<uint32_t, 8> sha256_block(const std::array<uint32_t, 8>& h_init, const std::array<uint32_t, 16>& input);
21
22template <typename T> Sha256Hash sha256(const T& input);
23
24inline bool operator==(Sha256Hash const& lhs, std::vector<uint8_t> const& rhs)
25{
26 return std::equal(lhs.begin(), lhs.end(), rhs.begin());
27}
28
29} // namespace bb::crypto
30
31namespace std {
32inline bool operator==(std::vector<uint8_t> const& lhs, bb::crypto::Sha256Hash const& rhs)
33{
34 return std::equal(lhs.begin(), lhs.end(), rhs.begin());
35}
36
37inline std::ostream& operator<<(std::ostream& os, bb::crypto::Sha256Hash const& arr)
38{
39 std::ios_base::fmtflags f(os.flags());
40 os << std::hex << std::setfill('0');
41 for (auto byte : arr) {
42 os << std::setw(2) << +(unsigned char)byte;
43 }
44 os.flags(f);
45 return os;
46}
47} // namespace std
Sha256Hash sha256(const ByteContainer &input)
SHA-256 hash function (FIPS 180-4)
Definition sha256.cpp:150
std::array< uint8_t, 32 > Sha256Hash
Definition sha256.hpp:17
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)
SHA-256 compression function (FIPS 180-4 Section 6.2.2)
Definition sha256.cpp:73
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:32
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