-
Notifications
You must be signed in to change notification settings - Fork 2
/
x11.go
95 lines (76 loc) · 1.92 KB
/
x11.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package x11
import (
"github.com/samli88/go-x11-hash/blake"
"github.com/samli88/go-x11-hash/bmw"
"github.com/samli88/go-x11-hash/cubehash"
"github.com/samli88/go-x11-hash/echo"
"github.com/samli88/go-x11-hash/groestl"
"github.com/samli88/go-x11-hash/hash"
"github.com/samli88/go-x11-hash/jh"
"github.com/samli88/go-x11-hash/keccak"
"github.com/samli88/go-x11-hash/luffa"
"github.com/samli88/go-x11-hash/shavite"
"github.com/samli88/go-x11-hash/simd"
"github.com/samli88/go-x11-hash/skein"
)
// Hash contains the state objects
// required to perform the x11.Hash.
type Hash struct {
tha [64]byte
thb [64]byte
blake hash.Digest
bmw hash.Digest
cubehash hash.Digest
echo hash.Digest
groestl hash.Digest
jh hash.Digest
keccak hash.Digest
luffa hash.Digest
shavite hash.Digest
simd hash.Digest
skein hash.Digest
}
// New returns a new object to compute a x11 hash.
func New() *Hash {
ref := &Hash{}
ref.blake = blake.New()
ref.bmw = bmw.New()
ref.cubehash = cubehash.New()
ref.echo = echo.New()
ref.groestl = groestl.New()
ref.jh = jh.New()
ref.keccak = keccak.New()
ref.luffa = luffa.New()
ref.shavite = shavite.New()
ref.simd = simd.New()
ref.skein = skein.New()
return ref
}
// Hash computes the hash from the src bytes and stores the result in dst.
func (ref *Hash) Hash(src []byte, dst []byte) {
ta := ref.tha[:]
tb := ref.thb[:]
ref.blake.Write(src)
ref.blake.Close(tb, 0, 0)
ref.bmw.Write(tb)
ref.bmw.Close(ta, 0, 0)
ref.groestl.Write(ta)
ref.groestl.Close(tb, 0, 0)
ref.skein.Write(tb)
ref.skein.Close(ta, 0, 0)
ref.jh.Write(ta)
ref.jh.Close(tb, 0, 0)
ref.keccak.Write(tb)
ref.keccak.Close(ta, 0, 0)
ref.luffa.Write(ta)
ref.luffa.Close(tb, 0, 0)
ref.cubehash.Write(tb)
ref.cubehash.Close(ta, 0, 0)
ref.shavite.Write(ta)
ref.shavite.Close(tb, 0, 0)
ref.simd.Write(tb)
ref.simd.Close(ta, 0, 0)
ref.echo.Write(ta)
ref.echo.Close(tb, 0, 0)
copy(dst, tb)
}