-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathx11.go
98 lines (79 loc) · 2.02 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
96
97
98
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package x11
import (
"github.com/phoreproject/go-x11/blake"
"github.com/phoreproject/go-x11/bmw"
"github.com/phoreproject/go-x11/cubed"
"github.com/phoreproject/go-x11/echo"
"github.com/phoreproject/go-x11/groest"
"github.com/phoreproject/go-x11/hash"
"github.com/phoreproject/go-x11/jhash"
"github.com/phoreproject/go-x11/keccak"
"github.com/phoreproject/go-x11/luffa"
"github.com/phoreproject/go-x11/shavite"
"github.com/phoreproject/go-x11/simd"
"github.com/phoreproject/go-x11/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
cubed hash.Digest
echo hash.Digest
groest hash.Digest
jhash 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.cubed = cubed.New()
ref.echo = echo.New()
ref.groest = groest.New()
ref.jhash = jhash.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.groest.Write(ta)
ref.groest.Close(tb, 0, 0)
ref.skein.Write(tb)
ref.skein.Close(ta, 0, 0)
ref.jhash.Write(ta)
ref.jhash.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.cubed.Write(tb)
ref.cubed.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)
}