-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinal_hash.go
59 lines (51 loc) · 1.53 KB
/
final_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
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
package cryptonight
import (
"crypto/sha512"
"hash"
"sync"
"unsafe"
"github.com/ngchain/cryptonight-go/groestl"
"github.com/ngchain/cryptonight-go/jh"
"github.com/aead/skein"
"github.com/dchest/blake256"
"github.com/jzelinskie/whirlpool"
"github.com/phoreproject/go-x11/bmw"
"github.com/phoreproject/go-x11/cubed"
"github.com/phoreproject/go-x11/echo"
"github.com/phoreproject/go-x11/luffa"
"github.com/phoreproject/go-x11/shavite"
"github.com/phoreproject/go-x11/simd"
)
// make ASIC-resistant
var hashPool = [...]*sync.Pool{
{New: func() interface{} { return blake256.New() }},
{New: func() interface{} { return bmw.New() }},
{New: func() interface{} { return cubed.New() }},
{New: func() interface{} { return echo.New() }},
{New: func() interface{} { return groestl.New256() }},
{New: func() interface{} { return jh.New256() }},
{New: func() interface{} { return luffa.New() }},
{New: func() interface{} { return skein.New256(nil) }},
{New: func() interface{} { return simd.New() }},
{New: func() interface{} { return shavite.New() }},
{New: func() interface{} { return sha512.New() }},
{New: func() interface{} { return whirlpool.New() }},
}
func (cc *cache) finalHash() []byte {
sum := (*[200]byte)(unsafe.Pointer(&cc.finalState))[:]
for i := uint64(0); i < (cc.finalState[0] & 0x0b); i++ {
sum = finalPod(sum[:])
}
return sum
}
func finalPod(b []byte) []byte {
var dst [32]byte
hp := hashPool[b[0]&0x0b]
h := hp.Get().(hash.Hash)
h.Reset()
h.Write(b)
sum := h.Sum(nil)
hp.Put(h)
copy(dst[:], sum)
return dst[:]
}