-
Notifications
You must be signed in to change notification settings - Fork 0
/
x11.go
135 lines (103 loc) · 3.19 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright (c) 2018 Yuriy Lisovskiy
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package x11
import (
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/blake512"
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/bmw512"
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/cubehash512"
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/echo512"
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/groestl512"
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/jh512"
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/keccak512"
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/luffa512"
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/shavite512"
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/simd512"
"github.com/YuriyLisovskiy/blockchain-go/src/crypto/sha3/skein512"
)
var (
tha [64]byte
thb [64]byte
blakeHash = blake512.New()
bmwHash = bmw512.New()
groestlHash = groestl512.New()
skeinHash = skein512.New()
jhHash = jh512.New()
keccakHash = keccak512.New()
luffaHash = luffa512.New()
cubehashHash = cubehash512.New()
shaviteHash = shavite512.New()
simdHash = simd512.New()
echoHash = echo512.New()
)
// Hash computes the hash from the src bytes and returns 32-byte hash.
func Sum256(src []byte) [32]byte {
ta := tha[:]
tb := thb[:]
blakeHash.Write(src)
blakeHash.Close(tb, 0, 0)
bmwHash.Write(tb)
bmwHash.Close(ta, 0, 0)
groestlHash.Write(ta)
groestlHash.Close(tb, 0, 0)
skeinHash.Write(tb)
skeinHash.Close(ta, 0, 0)
jhHash.Write(ta)
jhHash.Close(tb, 0, 0)
keccakHash.Write(tb)
keccakHash.Close(ta, 0, 0)
luffaHash.Write(ta)
luffaHash.Close(tb, 0, 0)
cubehashHash.Write(tb)
cubehashHash.Close(ta, 0, 0)
shaviteHash.Write(ta)
shaviteHash.Close(tb, 0, 0)
simdHash.Write(tb)
simdHash.Close(ta, 0, 0)
echoHash.Write(ta)
echoHash.Close(tb, 0, 0)
var res [32]byte
copy(res[:], tb)
return res
}
// Hash computes the hash from the src bytes and returns 64-byte hash.
func Sum512(src []byte) [64]byte {
ta := tha[:]
tb := thb[:]
blakeHash.Write(src)
blakeHash.Close(tb, 0, 0)
bmwHash.Write(tb)
bmwHash.Close(ta, 0, 0)
groestlHash.Write(ta)
groestlHash.Close(tb, 0, 0)
skeinHash.Write(tb)
skeinHash.Close(ta, 0, 0)
jhHash.Write(ta)
jhHash.Close(tb, 0, 0)
keccakHash.Write(tb)
keccakHash.Close(ta, 0, 0)
luffaHash.Write(ta)
luffaHash.Close(tb, 0, 0)
cubehashHash.Write(tb)
cubehashHash.Close(ta, 0, 0)
shaviteHash.Write(ta)
shaviteHash.Close(tb, 0, 0)
simdHash.Write(tb)
simdHash.Close(ta, 0, 0)
echoHash.Write(ta)
echoHash.Close(tb, 0, 0)
var res [64]byte
copy(res[:], tb)
return res
}