|
19 | 19 | package crypto |
20 | 20 |
|
21 | 21 | import ( |
22 | | - "hash" |
23 | | - |
24 | 22 | "github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime" |
25 | 23 | "github.com/ethereum/go-ethereum/common" |
26 | 24 | "golang.org/x/crypto/sha3" |
27 | 25 | ) |
28 | 26 |
|
29 | | -// KeccakState wraps sha3.state. In addition to the usual hash methods, it also supports |
30 | | -// Read to get a variable amount of data from the hash state. Read is faster than Sum |
31 | | -// because it doesn't copy the internal state, but also modifies the internal state. |
32 | | -type KeccakState interface { |
33 | | - hash.Hash |
34 | | - Read([]byte) (int, error) |
35 | | -} |
36 | | - |
37 | 27 | // NewKeccakState creates a new KeccakState |
38 | 28 | // For now, we fallback to the original implementation for the stateful interface. |
39 | 29 | // TODO: Implement a stateful wrapper around zkvm_runtime.Keccak256 if needed. |
40 | 30 | func NewKeccakState() KeccakState { |
41 | 31 | return sha3.NewLegacyKeccak256().(KeccakState) |
42 | 32 | } |
43 | 33 |
|
44 | | -// HashData hashes the provided data using the KeccakState and returns a 32 byte hash |
45 | | -// For now, we fallback to the original implementation for the stateful interface. |
46 | | -func HashData(kh KeccakState, data []byte) (h common.Hash) { |
47 | | - kh.Reset() |
48 | | - kh.Write(data) |
49 | | - kh.Read(h[:]) |
50 | | - return h |
51 | | -} |
52 | | - |
53 | 34 | // Keccak256 calculates and returns the Keccak256 hash using the Ziren zkvm_runtime implementation. |
54 | 35 | func Keccak256(data ...[]byte) []byte { |
55 | 36 | // For multiple data chunks, concatenate them |
@@ -78,14 +59,6 @@ func Keccak256(data ...[]byte) []byte { |
78 | 59 | } |
79 | 60 |
|
80 | 61 | // Keccak256Hash calculates and returns the Keccak256 hash as a Hash using the Ziren zkvm_runtime implementation. |
81 | | -func Keccak256Hash(data ...[]byte) (h common.Hash) { |
82 | | - hash := Keccak256(data...) |
83 | | - copy(h[:], hash) |
84 | | - return h |
85 | | -} |
86 | | - |
87 | | -// Keccak512 calculates and returns the Keccak512 hash of the input data. |
88 | | -func Keccak512(data ...[]byte) []byte { |
89 | | - panic("Keccak512 not implemented in ziren mode") |
| 62 | +func Keccak256Hash(data ...[]byte) common.Hash { |
| 63 | + return common.Hash(Keccak256(data...)) |
90 | 64 | } |
91 | | - |
0 commit comments