7 "github.com/bytom/crypto/scrypt"
8 "github.com/bytom/crypto/sha3pool"
9 "github.com/bytom/protocol/bc"
12 func calcSeed(blockHashs []*bc.Hash) []byte {
14 for _, blockHash := range blockHashs {
15 data = append(data, blockHash.Bytes()...)
18 sha3pool.Sum256(s[:], data)
23 func extendBytes(seed []byte, round int) []byte {
24 extSeed := make([]byte, len(seed)*(round+1))
27 for i := 0; i < round; i++ {
29 sha3pool.Sum256(h[:], extSeed[i*32:(i+1)*32])
30 copy(extSeed[(i+1)*32:(i+2)*32], h[:])
36 func calcSeedCache(seed []byte) (cache []uint32) {
37 extSeed := extendBytes(seed, 3)
38 v := make([]uint32, 32*1024)
40 // Swap the byte order on big endian systems
41 if !isLittleEndian() {
45 for i := 0; i < 128; i++ {
46 scrypt.Smix(extSeed, v)
47 cache = append(cache, v...)
53 // isLittleEndian returns whether the local system is running in little or big
55 func isLittleEndian() bool {
56 n := uint32(0x01020304)
57 return *(*byte)(unsafe.Pointer(&n)) == 0x04
60 // swap changes the byte order of the buffer assuming a uint32 representation.
61 func swap(buffer []byte) {
62 for i := 0; i < len(buffer); i += 4 {
63 binary.BigEndian.PutUint32(buffer[i:], binary.LittleEndian.Uint32(buffer[i:]))