Longfellow ZK 0290cb32

Loading...
Searching...
No Matches
sha3_reference.h
1// Copyright 2025 Google LLC.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_REFERENCE_H_
16#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_REFERENCE_H_
17
18// !!!!! DO NOT USE IN PRODUCTION !!!!!
19
20/* This is a simple reference implementation of sha3
21 to be used to design zero-knowledge circuits. DO NOT USE
22 THIS CODE IN PRODUCTION. */
23#include <cstdint>
24#include <cstdlib>
25
26 namespace proofs {
27 class Sha3Reference {
28 size_t mdlen_;
29 size_t rate_;
30 size_t wrptr_;
31 uint8_t buf_[200];
32 uint64_t a_[5][5];
33
34 static void keccak_f_1600(uint64_t A[5][5]);
35
36 public:
37 explicit Sha3Reference(size_t mdlen)
38 : mdlen_(mdlen), rate_(200 - 2 * mdlen), wrptr_(0), buf_{}, a_{} {}
39
40 void update(const char* data, size_t n);
41 void final(uint8_t digest[/*mdlen*/]);
42
43 static void keccak_f_1600_DEBUG_ONLY(uint64_t A[5][5]);
44};
45} // namespace proofs
46#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_SHA3_SHA3_REFERENCE_H_