29TEST(stdlib_sha256, test_sha256_block_NIST_vector_one)
34 constexpr std::array<uint32_t, 8> H_INIT = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
35 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
43 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
44 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
49 constexpr std::array<uint32_t, 8> EXPECTED = { 0xba7816bf, 0x8f01cfea, 0x414140de, 0x5dae2223,
50 0xb00361a3, 0x96177a9c, 0xb410ff61, 0xf20015ad };
54 for (
size_t i = 0; i < 8; i++) {
55 EXPECT_EQ(native_output[i], EXPECTED[i]) <<
"Native mismatch at index " << i;
60 for (
size_t i = 0; i < 8; i++) {
65 for (
size_t i = 0; i < 16; i++) {
76 for (
size_t i = 0; i < 8; i++) {
77 uint32_t circuit_val =
static_cast<uint32_t
>(
uint256_t(circuit_output[i].get_value()));
78 EXPECT_EQ(circuit_val, EXPECTED[i]) <<
"Circuit mismatch at index " << i;
81 info(
"sha256_block num gates = ",
builder.get_num_finalized_gates_inefficient());
94TEST(stdlib_sha256, test_sha256_block_NIST_vector_two)
99 constexpr std::array<uint32_t, 8> H_INIT = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
100 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
106 0x61626364, 0x62636465, 0x63646566, 0x64656667,
107 0x65666768, 0x66676869, 0x6768696a, 0x68696a6b,
108 0x696a6b6c, 0x6a6b6c6d, 0x6b6c6d6e, 0x6c6d6e6f,
109 0x6d6e6f70, 0x6e6f7071, 0x80000000, 0x00000000
114 0x00000000, 0x00000000, 0x00000000, 0x00000000,
115 0x00000000, 0x00000000, 0x00000000, 0x00000000,
116 0x00000000, 0x00000000, 0x00000000, 0x000001c0 };
119 constexpr std::array<uint32_t, 8> EXPECTED = { 0x248d6a61, 0xd20638b8, 0xe5c02693, 0x0c3e6039,
120 0xa33ce459, 0x64ff2167, 0xf6ecedd4, 0x19db06c1 };
125 for (
size_t i = 0; i < 8; i++) {
126 EXPECT_EQ(native_output[i], EXPECTED[i]) <<
"Native mismatch at index " << i;
131 for (
size_t i = 0; i < 8; i++) {
136 for (
size_t i = 0; i < 16; i++) {
144 for (
size_t i = 0; i < 16; i++) {
154 for (
size_t i = 0; i < 8; i++) {
155 uint32_t circuit_val =
static_cast<uint32_t
>(
uint256_t(circuit_output[i].get_value()));
156 EXPECT_EQ(circuit_val, EXPECTED[i]) <<
"Circuit mismatch at index " << i;
159 info(
"sha256_block (2 blocks) num gates = ",
builder.get_num_finalized_gates_inefficient());
170TEST(stdlib_sha256, test_extend_witness_constraints)
178 for (
size_t i = 0; i < 16; i++) {
192 bool any_modification_passed =
false;
193 for (
auto& single_extended_witness : w_ext) {
195 uint32_t variable_index = single_extended_witness.get_witness_index();
198 while (
builder.get_variable(variable_index) ==
fr(random32bits)) {
202 auto backup =
builder.get_variable(variable_index);
203 builder.set_variable(variable_index,
fr(random32bits));
207 any_modification_passed =
true;
210 builder.set_variable(variable_index, backup);
214 EXPECT_FALSE(any_modification_passed);
static std::array< field_ct, 8 > sha256_block(const std::array< field_ct, 8 > &h_init, const std::array< field_ct, 16 > &input)
Apply the SHA-256 compression function to a single 512-bit message block.
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)