github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/consensus/scrypt/algorithm.go (about) 1 // Copyright (c) 2019 Simplechain 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Lesser General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Lesser General Public License for more details. 12 // 13 // You should have received a copy of the GNU Lesser General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package scrypt 17 18 import ( 19 "github.com/bigzoro/my_simplechain/crypto" 20 "github.com/bigzoro/my_simplechain/crypto/scrypt" 21 ) 22 23 func ScryptHash(hash []byte, nonce uint64) ([]byte, []byte) { 24 hashT := make([]byte, 80) 25 copy(hashT[0:32], hash[:]) 26 copy(hashT[32:64], hash[:]) 27 copy(hashT[72:], []byte{ 28 byte(nonce >> 56), 29 byte(nonce >> 48), 30 byte(nonce >> 40), 31 byte(nonce >> 32), 32 byte(nonce >> 24), 33 byte(nonce >> 16), 34 byte(nonce >> 8), 35 byte(nonce), 36 }) 37 38 if digest, err := scrypt.Key(hashT, hashT, 1024, 1, 1, 32, ScryptMode); err == nil { 39 return crypto.Keccak256(digest), digest 40 } else { 41 panic(err.Error()) 42 } 43 }