mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-02 20:26:43 +00:00

* Add another hash domain for HeavyHash * Add a xoShiRo256PlusPlus implementation * Add a HeavyHash implementation * Replace our current PoW algorithm with oPoW * Change to pow hash to keccak256 * Fix genesis * Fix tests Co-authored-by: Elichai Turkel <elichai.turkel@gmail.com>
38 lines
781 B
Go
38 lines
781 B
Go
package pow
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"math/bits"
|
|
)
|
|
|
|
type xoShiRo256PlusPlus struct {
|
|
s0 uint64
|
|
s1 uint64
|
|
s2 uint64
|
|
s3 uint64
|
|
}
|
|
|
|
func newxoShiRo256PlusPlus(hash *externalapi.DomainHash) *xoShiRo256PlusPlus {
|
|
hashArray := hash.ByteArray()
|
|
return &xoShiRo256PlusPlus{
|
|
s0: binary.LittleEndian.Uint64(hashArray[:8]),
|
|
s1: binary.LittleEndian.Uint64(hashArray[8:16]),
|
|
s2: binary.LittleEndian.Uint64(hashArray[16:24]),
|
|
s3: binary.LittleEndian.Uint64(hashArray[24:32]),
|
|
}
|
|
}
|
|
|
|
func (x *xoShiRo256PlusPlus) Uint64() uint64 {
|
|
res := bits.RotateLeft64(x.s0+x.s3, 23) + x.s0
|
|
t := x.s1 << 17
|
|
x.s2 ^= x.s0
|
|
x.s3 ^= x.s1
|
|
x.s1 ^= x.s2
|
|
x.s0 ^= x.s3
|
|
|
|
x.s2 ^= t
|
|
x.s3 = bits.RotateLeft64(x.s3, 45)
|
|
return res
|
|
}
|