1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
12using ::testing::ElementsAreArray;
17class PureSha256Test :
public ::testing::Test {
23TEST_F(PureSha256Test, CompressionMatchesCryptoImplementation)
25 std::array<uint32_t, 8> state = {
26 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
30 0x61626380, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
31 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000018,
39 for (
size_t i = 0; i < 8; ++i) {
42 for (
size_t i = 0; i < 16; ++i) {
53 std::array<uint32_t, 8> actual_output;
54 for (
size_t i = 0; i < 8; ++i) {
57 actual_output[i] = val.as<uint32_t>();
60 EXPECT_THAT(actual_output, ElementsAreArray(expected_output));
63TEST_F(PureSha256Test, InvalidStateTagThrows)
70 for (
size_t i = 0; i < 8; ++i) {
73 memory.
set(state_addr, MemoryValue::from<uint64_t>(0));
75 for (
size_t i = 0; i < 16; ++i) {
80 "Sha256CompressionException: Invalid tag for sha256 state values.");
83TEST_F(PureSha256Test, InvalidInputTagThrows)
89 for (
size_t i = 0; i < 8; ++i) {
92 for (
size_t i = 0; i < 16; ++i) {
99 "Sha256CompressionException: Invalid tag for sha256 input values.");
102TEST_F(PureSha256Test, StateAddressOutOfRangeThrows)
109 "Sha256CompressionException: Memory address out of range for sha256 compression.");
112TEST_F(PureSha256Test, InputAddressOutOfRangeThrows)
119 "Sha256CompressionException: Memory address out of range for sha256 compression.");
122TEST_F(PureSha256Test, OutputAddressOutOfRangeThrows)
129 "Sha256CompressionException: Memory address out of range for sha256 compression.");
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
#define AVM_HIGHEST_MEM_ADDRESS
void set(MemoryAddress index, MemoryValue value) override
const MemoryValue & get(MemoryAddress index) const override
void compression(MemoryInterface &memory, MemoryAddress state_addr, MemoryAddress input_addr, MemoryAddress output_addr) override
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)
TEST_F(IPATest, ChallengesAreZero)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept