forked from ferranbt/fastssz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.go
33 lines (28 loc) · 650 Bytes
/
hash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package ssz
import (
"hash"
)
type HashFn func(dst []byte, input []byte) error
const hashSize = 32
func NativeHashWrapper(hashFn hash.Hash) HashFn {
return func(dst []byte, input []byte) error {
hash := func(dst []byte, src []byte) {
hashFn.Write(src[:32])
hashFn.Write(src[32:64])
result := hashFn.Sum(nil)
if len(result) != hashSize {
dst = append(dst, make([]byte, hashSize-len(result))...)
}
_ = append(dst, result...)
hashFn.Reset()
}
layerLen := len(input) / 32
if layerLen%2 == 1 {
layerLen++
}
for i := 0; i < layerLen; i += 2 {
hash(input[(i/2)*32:][:0], input[i*32:])
}
return nil
}
}