-
Notifications
You must be signed in to change notification settings - Fork 0
/
sum.go
44 lines (33 loc) · 1 KB
/
sum.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
34
35
36
37
38
39
40
41
42
43
44
package lyra2re2
import (
"golang.org/x/crypto/sha3"
"github.com/deatil/go-hash/bmw"
"github.com/deatil/go-hash/skein"
"github.com/deatil/go-hash/blake256"
"github.com/deatil/go-hash/cubehash"
)
// Sum returns the result of Lyra2re2 hash.
func Sum(data []byte) ([]byte, error) {
blake := blake256.New()
if _, err := blake.Write(data); err != nil {
return nil, err
}
resultBlake := blake.Sum(nil)
keccak := sha3.NewLegacyKeccak256()
if _, err := keccak.Write(resultBlake); err != nil {
return nil, err
}
resultkeccak := keccak.Sum(nil)
resultcube := cubehash256(resultkeccak)
lyra2result := make([]byte, 32)
Lyra2(lyra2result, resultcube, resultcube, 1, 4, 4)
skeinresult := skein.Sum256(lyra2result, nil)
resultcube2 := cubehash256(skeinresult[:])
resultbmw := bmw.Sum256(resultcube2)
return resultbmw[:], nil
}
func cubehash256(data []byte) []byte {
h := cubehash.NewSH256()
h.Write(data)
return h.Sum(nil)
}