diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index c6a8705cd3a3e7f37cee3a9213ce30cb4b815500..d1b8330e3d863b3fd11fc934f7af9a83d2137cc4 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -244,7 +244,7 @@ func TestMethodSignature(t *testing.T) { t.Error("signature mismatch", exp, "!=", m.Sig()) } - idexp := crypto.Sha3([]byte(exp))[:4] + idexp := crypto.Keccak256([]byte(exp))[:4] if !bytes.Equal(m.Id(), idexp) { t.Errorf("expected ids to match %x != %x", m.Id(), idexp) } @@ -264,7 +264,7 @@ func TestPack(t *testing.T) { t.FailNow() } - sig := crypto.Sha3([]byte("foo(uint32)"))[:4] + sig := crypto.Keccak256([]byte("foo(uint32)"))[:4] sig = append(sig, make([]byte, 32)...) sig[35] = 10 @@ -286,7 +286,7 @@ func TestMultiPack(t *testing.T) { t.FailNow() } - sig := crypto.Sha3([]byte("bar(uint32,uint16)"))[:4] + sig := crypto.Keccak256([]byte("bar(uint32,uint16)"))[:4] sig = append(sig, make([]byte, 64)...) sig[35] = 10 sig[67] = 11 @@ -309,7 +309,7 @@ func TestPackSlice(t *testing.T) { t.FailNow() } - sig := crypto.Sha3([]byte("slice(uint32[2])"))[:4] + sig := crypto.Keccak256([]byte("slice(uint32[2])"))[:4] sig = append(sig, make([]byte, 64)...) sig[35] = 1 sig[67] = 2 @@ -332,7 +332,7 @@ func TestPackSliceBig(t *testing.T) { t.FailNow() } - sig := crypto.Sha3([]byte("slice256(uint256[2])"))[:4] + sig := crypto.Keccak256([]byte("slice256(uint256[2])"))[:4] sig = append(sig, make([]byte, 64)...) sig[35] = 1 sig[67] = 2 diff --git a/accounts/abi/event.go b/accounts/abi/event.go index 7c4e092ea5a49cf781dbded14396d6865a32f39f..e74c7c732c774f28656faa5d65370220ef5b848a 100644 --- a/accounts/abi/event.go +++ b/accounts/abi/event.go @@ -40,5 +40,5 @@ func (e Event) Id() common.Hash { types[i] = input.Type.String() i++ } - return common.BytesToHash(crypto.Sha3([]byte(fmt.Sprintf("%v(%v)", e.Name, strings.Join(types, ","))))) + return common.BytesToHash(crypto.Keccak256([]byte(fmt.Sprintf("%v(%v)", e.Name, strings.Join(types, ","))))) } diff --git a/accounts/abi/event_test.go b/accounts/abi/event_test.go index 34a7a1684eda791d9c61527d3934312669a1fbbc..cdd182512dc1c833353c01a0ea303621cf408d17 100644 --- a/accounts/abi/event_test.go +++ b/accounts/abi/event_test.go @@ -19,8 +19,8 @@ func TestEventId(t *testing.T) { { "type" : "event", "name" : "check", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] } ]`, expectations: map[string]common.Hash{ - "balance": crypto.Sha3Hash([]byte("balance(uint256)")), - "check": crypto.Sha3Hash([]byte("check(address,uint256)")), + "balance": crypto.Keccak256Hash([]byte("balance(uint256)")), + "check": crypto.Keccak256Hash([]byte("check(address,uint256)")), }, }, } diff --git a/accounts/abi/method.go b/accounts/abi/method.go index 63194e7880915796307f85d7733684cdb545a18c..e259c09aa9f451f1bd7637ff3c50522b6f420172 100644 --- a/accounts/abi/method.go +++ b/accounts/abi/method.go @@ -72,5 +72,5 @@ func (m Method) String() string { } func (m Method) Id() []byte { - return crypto.Sha3([]byte(m.Sig()))[:4] + return crypto.Keccak256([]byte(m.Sig()))[:4] } diff --git a/cmd/geth/js_test.go b/cmd/geth/js_test.go index 4330b484c0ed6dabf6de583d5a68d54590af49f8..af435e68ce2ba78ff8c85d484c4c2a93b8df010b 100644 --- a/cmd/geth/js_test.go +++ b/cmd/geth/js_test.go @@ -396,7 +396,7 @@ multiply7 = Multiply7.at(contractaddress); if sol != nil && solcVersion != sol.Version() { modContractInfo := versionRE.ReplaceAll(contractInfo, []byte(`"compilerVersion":"`+sol.Version()+`"`)) fmt.Printf("modified contractinfo:\n%s\n", modContractInfo) - contentHash = `"` + common.ToHex(crypto.Sha3([]byte(modContractInfo))) + `"` + contentHash = `"` + common.ToHex(crypto.Keccak256([]byte(modContractInfo))) + `"` } if checkEvalJSON(t, repl, `filename = "/tmp/info.json"`, `"/tmp/info.json"`) != nil { return diff --git a/common/compiler/solidity.go b/common/compiler/solidity.go index aca3a1fc2980cd0bb91df45d12f77266a4bcca02..8d3304029e6d37080375d5776da7c88181e66def 100644 --- a/common/compiler/solidity.go +++ b/common/compiler/solidity.go @@ -220,7 +220,7 @@ func SaveInfo(info *ContractInfo, filename string) (contenthash common.Hash, err if err != nil { return } - contenthash = common.BytesToHash(crypto.Sha3(infojson)) + contenthash = common.BytesToHash(crypto.Keccak256(infojson)) err = ioutil.WriteFile(filename, infojson, 0600) return } diff --git a/common/httpclient/httpclient.go b/common/httpclient/httpclient.go index 23373ecaf5cc7cca32a1e0812e4c48443dc6abcc..a0a1efd388d681a26e5956907c007a86dbed9261 100644 --- a/common/httpclient/httpclient.go +++ b/common/httpclient/httpclient.go @@ -74,7 +74,7 @@ func (self *HTTPClient) GetAuthContent(uri string, hash common.Hash) ([]byte, er } // check hash to authenticate content - chash := crypto.Sha3Hash(content) + chash := crypto.Keccak256Hash(content) if chash != hash { return nil, fmt.Errorf("content hash mismatch %x != %x (exp)", hash[:], chash[:]) } diff --git a/common/httpclient/httpclient_test.go b/common/httpclient/httpclient_test.go index 6c3782e15a3daa8c3244e862a38dac00573d56bc..670893f8a0981081aed6f58758253f9a0f0e8b9d 100644 --- a/common/httpclient/httpclient_test.go +++ b/common/httpclient/httpclient_test.go @@ -36,7 +36,7 @@ func TestGetAuthContent(t *testing.T) { client := New(dir) text := "test" - hash := crypto.Sha3Hash([]byte(text)) + hash := crypto.Keccak256Hash([]byte(text)) if err := ioutil.WriteFile(path.Join(dir, "test.content"), []byte(text), os.ModePerm); err != nil { t.Fatal("could not write test file", err) } diff --git a/common/natspec/natspec.go b/common/natspec/natspec.go index 2e4d8d7a4a5e151dde0e2eff70fba9a853f59f92..8197018cf4b41e854e2a2b149aae7929d6d2e989 100644 --- a/common/natspec/natspec.go +++ b/common/natspec/natspec.go @@ -115,7 +115,7 @@ func FetchDocsForContract(contractAddress string, xeth *xeth.XEth, client *httpc err = fmt.Errorf("contract (%v) not found", contractAddress) return } - codehash := common.BytesToHash(crypto.Sha3(codeb)) + codehash := common.BytesToHash(crypto.Keccak256(codeb)) // set up nameresolver with natspecreg + urlhint contract addresses reg := registrar.New(xeth) @@ -197,7 +197,7 @@ type userDoc struct { func (self *NatSpec) makeAbi2method(abiKey [8]byte) (meth *method) { for signature, m := range self.userDoc.Methods { name := strings.Split(signature, "(")[0] - hash := []byte(common.Bytes2Hex(crypto.Sha3([]byte(signature)))) + hash := []byte(common.Bytes2Hex(crypto.Keccak256([]byte(signature)))) var key [8]byte copy(key[:], hash[:8]) if bytes.Equal(key[:], abiKey[:]) { diff --git a/common/natspec/natspec_e2e_test.go b/common/natspec/natspec_e2e_test.go index 4a9b92eb67e44ce73faa4ce4d083a7dca86e0be8..0730391c744ca1ebceaf7a7197afe2bc2976b7ea 100644 --- a/common/natspec/natspec_e2e_test.go +++ b/common/natspec/natspec_e2e_test.go @@ -238,11 +238,11 @@ func TestNatspecE2E(t *testing.T) { // create a contractInfo file (mock cloud-deployed contract metadocs) // incidentally this is the info for the HashReg contract itself ioutil.WriteFile("/tmp/"+testFileName, []byte(testContractInfo), os.ModePerm) - dochash := crypto.Sha3Hash([]byte(testContractInfo)) + dochash := crypto.Keccak256Hash([]byte(testContractInfo)) // take the codehash for the contract we wanna test codeb := tf.xeth.CodeAtBytes(registrar.HashRegAddr) - codehash := crypto.Sha3Hash(codeb) + codehash := crypto.Keccak256Hash(codeb) reg := registrar.New(tf.xeth) _, err := reg.SetHashToHash(addr, codehash, dochash) diff --git a/common/registrar/ethreg/api.go b/common/registrar/ethreg/api.go index 1ba422c4d8946bd5e63dac023d75d4234a82c769..79a6c2191e3d02715e3194a1c78c9f463ea12fcb 100644 --- a/common/registrar/ethreg/api.go +++ b/common/registrar/ethreg/api.go @@ -86,7 +86,7 @@ func (api *PrivateRegistarAPI) Register(sender common.Address, addr common.Addre } codeb := state.GetCode(addr) - codeHash := common.BytesToHash(crypto.Sha3(codeb)) + codeHash := common.BytesToHash(crypto.Keccak256(codeb)) contentHash := common.HexToHash(contentHashHex) _, err = registrar.New(api.be).SetHashToHash(sender, codeHash, contentHash) diff --git a/common/registrar/registrar.go b/common/registrar/registrar.go index 24e45edb35cf5b2294ab5bee01a48890c41e5c5f..0606f6985fb6ba86acec4787139d867b23bdc419 100644 --- a/common/registrar/registrar.go +++ b/common/registrar/registrar.go @@ -68,7 +68,7 @@ const ( ) func abiSignature(s string) string { - return common.ToHex(crypto.Sha3([]byte(s))[:4]) + return common.ToHex(crypto.Keccak256([]byte(s))[:4]) } var ( @@ -401,7 +401,7 @@ func storageMapping(addr, key []byte) []byte { data := make([]byte, 64) copy(data[0:32], key[0:32]) copy(data[32:64], addr[0:32]) - sha := crypto.Sha3(data) + sha := crypto.Keccak256(data) return sha } diff --git a/common/registrar/registrar_test.go b/common/registrar/registrar_test.go index 68ee65ab4dd8b0a96421f6026a7856bd48d7b688..b2287803c296c0e67ec72dbc61242707a448ba26 100644 --- a/common/registrar/registrar_test.go +++ b/common/registrar/registrar_test.go @@ -31,7 +31,7 @@ type testBackend struct { var ( text = "test" codehash = common.StringToHash("1234") - hash = common.BytesToHash(crypto.Sha3([]byte(text))) + hash = common.BytesToHash(crypto.Keccak256([]byte(text))) url = "bzz://bzzhash/my/path/contr.act" ) diff --git a/compression/rle/read_write.go b/compression/rle/read_write.go index 19133119b3dcf0476e8efdea7f54519333856495..03dffd607db63e09ebca4284de148b90c4a45956 100644 --- a/compression/rle/read_write.go +++ b/compression/rle/read_write.go @@ -31,8 +31,8 @@ const ( tokenToken = 0xff ) -var empty = crypto.Sha3([]byte("")) -var emptyList = crypto.Sha3([]byte{0x80}) +var empty = crypto.Keccak256([]byte("")) +var emptyList = crypto.Keccak256([]byte{0x80}) func Decompress(dat []byte) ([]byte, error) { buf := new(bytes.Buffer) diff --git a/compression/rle/read_write_test.go b/compression/rle/read_write_test.go index ba39650256a745de46f4d78ede2187ae9d44039b..20a23a1960ac7987db49f5db1958b5168c23b6c6 100644 --- a/compression/rle/read_write_test.go +++ b/compression/rle/read_write_test.go @@ -67,8 +67,8 @@ func (s *CompressionRleSuite) TestDecompressSimple(c *checker.C) { // } // var exp []byte -// exp = append(exp, crypto.Sha3([]byte(""))...) -// exp = append(exp, crypto.Sha3([]byte{0x80})...) +// exp = append(exp, crypto.Keccak256([]byte(""))...) +// exp = append(exp, crypto.Keccak256([]byte{0x80})...) // exp = append(exp, make([]byte, 10)...) // if bytes.Compare(res, res) != 0 { @@ -82,12 +82,12 @@ func (s *CompressionRleSuite) TestDecompressSimple(c *checker.C) { // t.Error("5 * zero", res) // } -// res = Compress(crypto.Sha3([]byte(""))) +// res = Compress(crypto.Keccak256([]byte(""))) // if bytes.Compare(res, []byte{token, emptyShaToken}) != 0 { // t.Error("empty sha", res) // } -// res = Compress(crypto.Sha3([]byte{0x80})) +// res = Compress(crypto.Keccak256([]byte{0x80})) // if bytes.Compare(res, []byte{token, emptyListShaToken}) != 0 { // t.Error("empty list sha", res) // } @@ -100,8 +100,8 @@ func (s *CompressionRleSuite) TestDecompressSimple(c *checker.C) { // func TestCompressMulti(t *testing.T) { // in := []byte{0, 0, 0, 0, 0} -// in = append(in, crypto.Sha3([]byte(""))...) -// in = append(in, crypto.Sha3([]byte{0x80})...) +// in = append(in, crypto.Keccak256([]byte(""))...) +// in = append(in, crypto.Keccak256([]byte{0x80})...) // in = append(in, token) // res := Compress(in) @@ -116,8 +116,8 @@ func (s *CompressionRleSuite) TestDecompressSimple(c *checker.C) { // for i := 0; i < 20; i++ { // in = append(in, []byte{0, 0, 0, 0, 0}...) -// in = append(in, crypto.Sha3([]byte(""))...) -// in = append(in, crypto.Sha3([]byte{0x80})...) +// in = append(in, crypto.Keccak256([]byte(""))...) +// in = append(in, crypto.Keccak256([]byte{0x80})...) // in = append(in, []byte{123, 2, 19, 89, 245, 254, 255, token, 98, 233}...) // in = append(in, token) // } diff --git a/core/state/state_object.go b/core/state/state_object.go index 6095fc96a4ce540501234e48c2a89377281aa5ad..0f86325c60036ab71e23572422c983fa1b9d187c 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -30,7 +30,7 @@ import ( "github.com/ethereum/go-ethereum/trie" ) -var emptyCodeHash = crypto.Sha3(nil) +var emptyCodeHash = crypto.Keccak256(nil) type Code []byte @@ -225,7 +225,7 @@ func (self *StateObject) Code() []byte { func (self *StateObject) SetCode(code []byte) { self.code = code - self.codeHash = crypto.Sha3(code) + self.codeHash = crypto.Keccak256(code) self.dirty = true } diff --git a/core/types/bloom9.go b/core/types/bloom9.go index 372045ab21ed26cf224ae7a7e0892be6d414a931..ecf2bffc2e891b1522074c3f3d1f7906d7e36132 100644 --- a/core/types/bloom9.go +++ b/core/types/bloom9.go @@ -101,7 +101,7 @@ func LogsBloom(logs vm.Logs) *big.Int { } func bloom9(b []byte) *big.Int { - b = crypto.Sha3(b[:]) + b = crypto.Keccak256(b[:]) r := new(big.Int) diff --git a/core/types/bloom9_test.go b/core/types/bloom9_test.go index 5744bec6cbceec5f494a2bb4524ff27078b45dee..58e8f707316f6e4337aa7b6230717a500cac646a 100644 --- a/core/types/bloom9_test.go +++ b/core/types/bloom9_test.go @@ -73,7 +73,7 @@ func TestBloom9(t *testing.T) { func TestAddress(t *testing.T) { block := &Block{} block.Coinbase = common.Hex2Bytes("22341ae42d6dd7384bc8584e50419ea3ac75b83f") - fmt.Printf("%x\n", crypto.Sha3(block.Coinbase)) + fmt.Printf("%x\n", crypto.Keccak256(block.Coinbase)) bin := CreateBloom(block) fmt.Printf("bin = %x\n", common.LeftPadBytes(bin, 64)) diff --git a/core/types/transaction.go b/core/types/transaction.go index 0c9c1ce18329e0124a7298badc8dbf49989a223d..37715ee53b3124beb5beb4167eee2c9af586dce2 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -202,7 +202,7 @@ func doFrom(tx *Transaction, homestead bool) (common.Address, error) { return common.Address{}, err } var addr common.Address - copy(addr[:], crypto.Sha3(pubkey[1:])[12:]) + copy(addr[:], crypto.Keccak256(pubkey[1:])[12:]) tx.from.Store(addr) return addr, nil } diff --git a/core/vm/contracts.go b/core/vm/contracts.go index f204432a2cd52a8f5295b5c65ae3a55d2f7c9dd0..5cc9f903b5836914f8154ae6d4d4cada5c99ce61 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -111,7 +111,7 @@ func ecrecoverFunc(in []byte) []byte { } // the first byte of pubkey is bitcoin heritage - return common.LeftPadBytes(crypto.Sha3(pubKey[1:])[12:], 32) + return common.LeftPadBytes(crypto.Keccak256(pubKey[1:])[12:], 32) } func memCpy(in []byte) []byte { diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 26f7671ff5295a0ef132965a3e7c56c84aa8ef25..1e1086b133300ca4511efbe3e1890a98fb1bc830 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -316,7 +316,7 @@ func opMulmod(instr instruction, pc *uint64, env Environment, contract *Contract func opSha3(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) { offset, size := stack.pop(), stack.pop() - hash := crypto.Sha3(memory.Get(offset.Int64(), size.Int64())) + hash := crypto.Keccak256(memory.Get(offset.Int64(), size.Int64())) stack.push(common.BytesToBig(hash)) } diff --git a/core/vm/jit.go b/core/vm/jit.go index 504aab52307d56138ad1cf563ac266eaa333b4f1..5404730c14a4aa7d1ac63c9243e2383f0eb97e7e 100644 --- a/core/vm/jit.go +++ b/core/vm/jit.go @@ -96,7 +96,7 @@ type Program struct { // NewProgram returns a new JIT program func NewProgram(code []byte) *Program { program := &Program{ - Id: crypto.Sha3Hash(code), + Id: crypto.Keccak256Hash(code), mapping: make(map[uint64]uint64), destinations: make(map[uint64]struct{}), code: code, diff --git a/core/vm/jit_test.go b/core/vm/jit_test.go index e8e078a4638c93520b294641a3b2b353ce155b03..4174c666f0e489bc31b26de91138ced3de5ef9d3 100644 --- a/core/vm/jit_test.go +++ b/core/vm/jit_test.go @@ -189,7 +189,7 @@ func (self *Env) Db() Database { return nil } func (self *Env) GasLimit() *big.Int { return self.gasLimit } func (self *Env) VmType() Type { return StdVmTy } func (self *Env) GetHash(n uint64) common.Hash { - return common.BytesToHash(crypto.Sha3([]byte(big.NewInt(int64(n)).String()))) + return common.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(n)).String()))) } func (self *Env) AddLog(log *Log) { } diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 1fa06e9801c96f438da9dcece3d1512f71064263..565ce7b732e463c973869666e049dadb2a4f379c 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -67,7 +67,7 @@ func setDefaults(cfg *Config) { } if cfg.GetHashFn == nil { cfg.GetHashFn = func(n uint64) common.Hash { - return common.BytesToHash(crypto.Sha3([]byte(new(big.Int).SetUint64(n).String()))) + return common.BytesToHash(crypto.Keccak256([]byte(new(big.Int).SetUint64(n).String()))) } } } diff --git a/core/vm/vm.go b/core/vm/vm.go index 320135ff268d34737065b2052adb2d8bf5ad46e6..d45d136b5584bdc07df77e33383568df2cc20a7d 100644 --- a/core/vm/vm.go +++ b/core/vm/vm.go @@ -58,7 +58,7 @@ func (self *Vm) Run(contract *Contract, input []byte) (ret []byte, err error) { } var ( - codehash = crypto.Sha3Hash(contract.Code) // codehash is used when doing jump dest caching + codehash = crypto.Keccak256Hash(contract.Code) // codehash is used when doing jump dest caching program *Program ) if EnableJit { diff --git a/core/vm/vm_jit.go b/core/vm/vm_jit.go index 07cb52d4a056fe05f3b39fb37edf764a4bed47c0..589c30fa814c1cc779a0088b3b4c7790c71c29ef 100644 --- a/core/vm/vm_jit.go +++ b/core/vm/vm_jit.go @@ -200,7 +200,7 @@ func (self *JitVm) Run(me, caller ContextRef, code []byte, value, gas, price *bi self.data.timestamp = self.env.Time() self.data.code = getDataPtr(code) self.data.codeSize = uint64(len(code)) - self.data.codeHash = hash2llvm(crypto.Sha3(code)) // TODO: Get already computed hash? + self.data.codeHash = hash2llvm(crypto.Keccak256(code)) // TODO: Get already computed hash? jit := C.evmjit_create() retCode := C.evmjit_run(jit, unsafe.Pointer(&self.data), unsafe.Pointer(self)) @@ -242,7 +242,7 @@ func (self *JitVm) Env() Environment { //export env_sha3 func env_sha3(dataPtr *byte, length uint64, resultPtr unsafe.Pointer) { data := llvm2bytesRef(dataPtr, length) - hash := crypto.Sha3(data) + hash := crypto.Keccak256(data) result := (*i256)(resultPtr) *result = hash2llvm(hash) } diff --git a/crypto/crypto.go b/crypto/crypto.go index 850be4da604e3f99ae98101fb58e75e2c745d95c..f8e03acc5d4f7cd7dbdcef41a8af5d81d92df684 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -43,7 +43,7 @@ import ( "golang.org/x/crypto/ripemd160" ) -func Sha3(data ...[]byte) []byte { +func Keccak256(data ...[]byte) []byte { d := sha3.NewKeccak256() for _, b := range data { d.Write(b) @@ -51,7 +51,7 @@ func Sha3(data ...[]byte) []byte { return d.Sum(nil) } -func Sha3Hash(data ...[]byte) (h common.Hash) { +func Keccak256Hash(data ...[]byte) (h common.Hash) { d := sha3.NewKeccak256() for _, b := range data { d.Write(b) @@ -63,7 +63,7 @@ func Sha3Hash(data ...[]byte) (h common.Hash) { // Creates an ethereum address given the bytes and the nonce func CreateAddress(b common.Address, nonce uint64) common.Address { data, _ := rlp.EncodeToBytes([]interface{}{b, nonce}) - return common.BytesToAddress(Sha3(data)[12:]) + return common.BytesToAddress(Keccak256(data)[12:]) //return Sha3(common.NewValue([]interface{}{b, nonce}).Encode())[12:] } @@ -265,7 +265,7 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error if err != nil { return nil, err } - ethPriv := Sha3(plainText) + ethPriv := Keccak256(plainText) ecKey := ToECDSA(ethPriv) key = &Key{ Id: nil, @@ -330,7 +330,7 @@ func PKCS7Unpad(in []byte) []byte { func PubkeyToAddress(p ecdsa.PublicKey) common.Address { pubBytes := FromECDSAPub(&p) - return common.BytesToAddress(Sha3(pubBytes[1:])[12:]) + return common.BytesToAddress(Keccak256(pubBytes[1:])[12:]) } func zeroBytes(bytes []byte) { diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index 1681c7fefa6be44611d70162ff7c285a3f1d95f9..58b29da4901e4a403709113acfbf8a0d6ab9a45f 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -40,13 +40,13 @@ var testPrivHex = "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232 func TestSha3(t *testing.T) { msg := []byte("abc") exp, _ := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45") - checkhash(t, "Sha3-256", func(in []byte) []byte { return Sha3(in) }, msg, exp) + checkhash(t, "Sha3-256", func(in []byte) []byte { return Keccak256(in) }, msg, exp) } func TestSha3Hash(t *testing.T) { msg := []byte("abc") exp, _ := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45") - checkhash(t, "Sha3-256-array", func(in []byte) []byte { h := Sha3Hash(in); return h[:] }, msg, exp) + checkhash(t, "Sha3-256-array", func(in []byte) []byte { h := Keccak256Hash(in); return h[:] }, msg, exp) } func TestSha256(t *testing.T) { @@ -66,7 +66,7 @@ func BenchmarkSha3(b *testing.B) { amount := 1000000 start := time.Now() for i := 0; i < amount; i++ { - Sha3(a) + Keccak256(a) } fmt.Println(amount, ":", time.Since(start)) @@ -84,7 +84,7 @@ func TestSign(t *testing.T) { key, _ := HexToECDSA(testPrivHex) addr := common.HexToAddress(testAddrHex) - msg := Sha3([]byte("foo")) + msg := Keccak256([]byte("foo")) sig, err := Sign(msg, key) if err != nil { t.Errorf("Sign error: %s", err) @@ -238,7 +238,7 @@ func TestPythonIntegration(t *testing.T) { k0, _ := HexToECDSA(kh) k1 := FromECDSA(k0) - msg0 := Sha3([]byte("foo")) + msg0 := Keccak256([]byte("foo")) sig0, _ := secp256k1.Sign(msg0, k1) msg1 := common.FromHex("00000000000000000000000000000000") diff --git a/crypto/key_store_passphrase.go b/crypto/key_store_passphrase.go index 94411d2f94db6572a1ca2c7760c883c4f1c7ec93..b7ae9e1de9c897d5a02868f889c1c35b8f351ce4 100644 --- a/crypto/key_store_passphrase.go +++ b/crypto/key_store_passphrase.go @@ -110,7 +110,7 @@ func (ks keyStorePassphrase) StoreKey(key *Key, auth string) (err error) { return err } - mac := Sha3(derivedKey[16:32], cipherText) + mac := Keccak256(derivedKey[16:32], cipherText) scryptParamsJSON := make(map[string]interface{}, 5) scryptParamsJSON["n"] = ks.scryptN @@ -210,7 +210,7 @@ func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byt return nil, nil, err } - calculatedMAC := Sha3(derivedKey[16:32], cipherText) + calculatedMAC := Keccak256(derivedKey[16:32], cipherText) if !bytes.Equal(calculatedMAC, mac) { return nil, nil, errors.New("Decryption failed: MAC mismatch") } @@ -244,12 +244,12 @@ func decryptKeyV1(keyProtected *encryptedKeyJSONV1, auth string) (keyBytes []byt return nil, nil, err } - calculatedMAC := Sha3(derivedKey[16:32], cipherText) + calculatedMAC := Keccak256(derivedKey[16:32], cipherText) if !bytes.Equal(calculatedMAC, mac) { return nil, nil, errors.New("Decryption failed: MAC mismatch") } - plainText, err := aesCBCDecrypt(Sha3(derivedKey[:16])[:16], cipherText, iv) + plainText, err := aesCBCDecrypt(Keccak256(derivedKey[:16])[:16], cipherText, iv) if err != nil { return nil, nil, err } diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 9d0f2914d3131de2916653c20d8f78a4ec866de3..cfc669a9d62f48d85b0a2cb2db4dd71fe88261a5 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -977,7 +977,7 @@ func (q *queue) DeliverNodeData(id string, data [][]byte, callback func(error, i process := []trie.SyncResult{} for _, blob := range data { // Skip any state trie entires that were not requested - hash := common.BytesToHash(crypto.Sha3(blob)) + hash := common.BytesToHash(crypto.Keccak256(blob)) if _, ok := request.Hashes[hash]; !ok { errs = append(errs, fmt.Errorf("non-requested state data %x", hash)) continue diff --git a/eth/handler_test.go b/eth/handler_test.go index 148d56cc60f63598ef28efdee4d6f00f192778a5..e5974c23cfd753b33e1851a13bc82f5f3d9861ae 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -481,7 +481,7 @@ func testGetNodeData(t *testing.T, protocol int) { } // Verify that all hashes correspond to the requested data, and reconstruct a state tree for i, want := range hashes { - if hash := crypto.Sha3Hash(data[i]); hash != want { + if hash := crypto.Keccak256Hash(data[i]); hash != want { fmt.Errorf("data hash mismatch: have %x, want %x", hash, want) } } diff --git a/light/odr.go b/light/odr.go index 5ed4f2325e01ef8e2c7bcd6f63c4f57f6b53d68e..4c69040ef869738cf76457ddba766cdaa42a2e5f 100644 --- a/light/odr.go +++ b/light/odr.go @@ -53,7 +53,7 @@ func (req *TrieRequest) StoreResult(db ethdb.Database) { // storeProof stores the new trie nodes obtained from a merkle proof in the database func storeProof(db ethdb.Database, proof []rlp.RawValue) { for _, buf := range proof { - hash := crypto.Sha3(buf) + hash := crypto.Keccak256(buf) val, _ := db.Get(hash) if val == nil { db.Put(hash, buf) @@ -78,7 +78,7 @@ func (req *NodeDataRequest) StoreResult(db ethdb.Database) { db.Put(req.hash[:], req.GetData()) } -var sha3_nil = crypto.Sha3Hash(nil) +var sha3_nil = crypto.Keccak256Hash(nil) // retrieveNodeData tries to retrieve node data with the given hash from the network func retrieveNodeData(ctx context.Context, odr OdrBackend, hash common.Hash) ([]byte, error) { diff --git a/light/state_object.go b/light/state_object.go index d67fd7e40fe335d576355815164f3b17cb93426d..fbb37400cba3664356daea166f68b0baf42e1acf 100644 --- a/light/state_object.go +++ b/light/state_object.go @@ -29,7 +29,7 @@ import ( "golang.org/x/net/context" ) -var emptyCodeHash = crypto.Sha3(nil) +var emptyCodeHash = crypto.Keccak256(nil) // Code represents a contract code in binary form type Code []byte @@ -220,7 +220,7 @@ func (self *StateObject) Code() []byte { // SetCode sets the contract code func (self *StateObject) SetCode(code []byte) { self.code = code - self.codeHash = crypto.Sha3(code) + self.codeHash = crypto.Keccak256(code) self.dirty = true } diff --git a/node/api.go b/node/api.go index 48cbd0150079785a36c4ed6b2e30f7684b16025c..8a257841048683c509bccc2cbabb3d72170aab15 100644 --- a/node/api.go +++ b/node/api.go @@ -269,5 +269,5 @@ func (s *PublicWeb3API) ClientVersion() string { // Sha3 applies the ethereum sha3 implementation on the input. // It assumes the input is hex encoded. func (s *PublicWeb3API) Sha3(input string) string { - return common.ToHex(crypto.Sha3(common.FromHex(input))) + return common.ToHex(crypto.Keccak256(common.FromHex(input))) } diff --git a/p2p/discover/database.go b/p2p/discover/database.go index e8e3371ff9ca7999af6e85813517a816c942a34d..6d448515de63dda9d242cc4d638324c8d23a3f65 100644 --- a/p2p/discover/database.go +++ b/p2p/discover/database.go @@ -188,7 +188,7 @@ func (db *nodeDB) node(id NodeID) *Node { glog.V(logger.Warn).Infof("failed to decode node RLP: %v", err) return nil } - node.sha = crypto.Sha3Hash(node.ID[:]) + node.sha = crypto.Keccak256Hash(node.ID[:]) return node } diff --git a/p2p/discover/node.go b/p2p/discover/node.go index c4a3b501176d9ced8d9d8e451710be155b6a989f..139a95d8035bf930feca8f4198afd9882b62ebe0 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -67,7 +67,7 @@ func NewNode(id NodeID, ip net.IP, udpPort, tcpPort uint16) *Node { UDP: udpPort, TCP: tcpPort, ID: id, - sha: crypto.Sha3Hash(id[:]), + sha: crypto.Keccak256Hash(id[:]), } } diff --git a/p2p/discover/table.go b/p2p/discover/table.go index abb7980f859ee1cee87d5b9e43cdea903175a201..1de045f0471b6724651b462e092c734e3f1815e9 100644 --- a/p2p/discover/table.go +++ b/p2p/discover/table.go @@ -195,7 +195,7 @@ func (tab *Table) SetFallbackNodes(nodes []*Node) error { cpy := *n // Recompute cpy.sha because the node might not have been // created by NewNode or ParseNode. - cpy.sha = crypto.Sha3Hash(n.ID[:]) + cpy.sha = crypto.Keccak256Hash(n.ID[:]) tab.nursery = append(tab.nursery, &cpy) } tab.mutex.Unlock() @@ -208,7 +208,7 @@ func (tab *Table) SetFallbackNodes(nodes []*Node) error { func (tab *Table) Resolve(targetID NodeID) *Node { // If the node is present in the local table, no // network interaction is required. - hash := crypto.Sha3Hash(targetID[:]) + hash := crypto.Keccak256Hash(targetID[:]) tab.mutex.Lock() cl := tab.closest(hash, 1) tab.mutex.Unlock() @@ -236,7 +236,7 @@ func (tab *Table) Lookup(targetID NodeID) []*Node { func (tab *Table) lookup(targetID NodeID, refreshIfEmpty bool) []*Node { var ( - target = crypto.Sha3Hash(targetID[:]) + target = crypto.Keccak256Hash(targetID[:]) asked = make(map[NodeID]bool) seen = make(map[NodeID]bool) reply = make(chan []*Node, alpha) diff --git a/p2p/discover/table_test.go b/p2p/discover/table_test.go index 30a418f441d66093d1e54e8d72dc789c6cb112d1..1a24057408eb26149e7de03d15986a13635196ed 100644 --- a/p2p/discover/table_test.go +++ b/p2p/discover/table_test.go @@ -530,12 +530,12 @@ func (*preminedTestnet) ping(toid NodeID, toaddr *net.UDPAddr) error { return ni // various distances to the given target. func (n *preminedTestnet) mine(target NodeID) { n.target = target - n.targetSha = crypto.Sha3Hash(n.target[:]) + n.targetSha = crypto.Keccak256Hash(n.target[:]) found := 0 for found < bucketSize*10 { k := newkey() id := PubkeyID(&k.PublicKey) - sha := crypto.Sha3Hash(id[:]) + sha := crypto.Keccak256Hash(id[:]) ld := logdist(n.targetSha, sha) if len(n.dists[ld]) < bucketSize { n.dists[ld] = append(n.dists[ld], id) diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go index 81674f5524e641603da63b849455933a8ab58cdf..92b37b1f33c4fb6972851e0881d8b5fe6edf6d08 100644 --- a/p2p/discover/udp.go +++ b/p2p/discover/udp.go @@ -448,7 +448,7 @@ func encodePacket(priv *ecdsa.PrivateKey, ptype byte, req interface{}) ([]byte, return nil, err } packet := b.Bytes() - sig, err := crypto.Sign(crypto.Sha3(packet[headSize:]), priv) + sig, err := crypto.Sign(crypto.Keccak256(packet[headSize:]), priv) if err != nil { glog.V(logger.Error).Infoln("could not sign packet:", err) return nil, err @@ -457,7 +457,7 @@ func encodePacket(priv *ecdsa.PrivateKey, ptype byte, req interface{}) ([]byte, // add the hash to the front. Note: this doesn't protect the // packet in any way. Our public key will be part of this hash in // The future. - copy(packet, crypto.Sha3(packet[macSize:])) + copy(packet, crypto.Keccak256(packet[macSize:])) return packet, nil } @@ -509,11 +509,11 @@ func decodePacket(buf []byte) (packet, NodeID, []byte, error) { return nil, NodeID{}, nil, errPacketTooSmall } hash, sig, sigdata := buf[:macSize], buf[macSize:headSize], buf[headSize:] - shouldhash := crypto.Sha3(buf[macSize:]) + shouldhash := crypto.Keccak256(buf[macSize:]) if !bytes.Equal(hash, shouldhash) { return nil, NodeID{}, nil, errBadHash } - fromID, err := recoverNodeID(crypto.Sha3(buf[headSize:]), sig) + fromID, err := recoverNodeID(crypto.Keccak256(buf[headSize:]), sig) if err != nil { return nil, NodeID{}, hash, err } @@ -575,7 +575,7 @@ func (req *findnode) handle(t *udp, from *net.UDPAddr, fromID NodeID, mac []byte // (which is a much bigger packet than findnode) to the victim. return errUnknownNode } - target := crypto.Sha3Hash(req.Target[:]) + target := crypto.Keccak256Hash(req.Target[:]) t.mutex.Lock() closest := t.closest(target, bucketSize).entries t.mutex.Unlock() diff --git a/p2p/discover/udp_test.go b/p2p/discover/udp_test.go index 66fc4cf2c3b1183fc55381b1a12b1d8e6ab6a79c..3939a69a7580497eb2c4767b1f22eea2307aa22d 100644 --- a/p2p/discover/udp_test.go +++ b/p2p/discover/udp_test.go @@ -286,7 +286,7 @@ func TestUDP_findnode(t *testing.T) { // put a few nodes into the table. their exact // distribution shouldn't matter much, altough we need to // take care not to overflow any bucket. - targetHash := crypto.Sha3Hash(testTarget[:]) + targetHash := crypto.Keccak256Hash(testTarget[:]) nodes := &nodesByDistance{target: targetHash} for i := 0; i < bucketSize; i++ { nodes.push(nodeAtDistance(test.table.self.sha, i+2), bucketSize) diff --git a/p2p/rlpx.go b/p2p/rlpx.go index 9d6cba5b67c7ec7023ecb9e3a3d1f899c2882053..ddfafe9a4b89d452183c76e39be23429384c8dd8 100644 --- a/p2p/rlpx.go +++ b/p2p/rlpx.go @@ -232,12 +232,12 @@ func (h *encHandshake) secrets(auth, authResp []byte) (secrets, error) { } // derive base secrets from ephemeral key agreement - sharedSecret := crypto.Sha3(ecdheSecret, crypto.Sha3(h.respNonce, h.initNonce)) - aesSecret := crypto.Sha3(ecdheSecret, sharedSecret) + sharedSecret := crypto.Keccak256(ecdheSecret, crypto.Keccak256(h.respNonce, h.initNonce)) + aesSecret := crypto.Keccak256(ecdheSecret, sharedSecret) s := secrets{ RemoteID: h.remoteID, AES: aesSecret, - MAC: crypto.Sha3(ecdheSecret, aesSecret), + MAC: crypto.Keccak256(ecdheSecret, aesSecret), } // setup sha3 instances for the MACs @@ -426,7 +426,7 @@ func (h *encHandshake) makeAuthResp() (msg *authRespV4, err error) { func (msg *authMsgV4) sealPlain(h *encHandshake) ([]byte, error) { buf := make([]byte, authMsgLen) n := copy(buf, msg.Signature[:]) - n += copy(buf[n:], crypto.Sha3(exportPubkey(&h.randomPrivKey.PublicKey))) + n += copy(buf[n:], crypto.Keccak256(exportPubkey(&h.randomPrivKey.PublicKey))) n += copy(buf[n:], msg.InitiatorPubkey[:]) n += copy(buf[n:], msg.Nonce[:]) buf[n] = 0 // token-flag diff --git a/p2p/rlpx_test.go b/p2p/rlpx_test.go index f9583e224c877aae7ca27aa864c8a41b5eb4008c..f4cefa650bd467987d04bb8255e181289508b87c 100644 --- a/p2p/rlpx_test.go +++ b/p2p/rlpx_test.go @@ -267,8 +267,8 @@ func TestRLPXFrameFake(t *testing.T) { buf := new(bytes.Buffer) hash := fakeHash([]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) rw := newRLPXFrameRW(buf, secrets{ - AES: crypto.Sha3(), - MAC: crypto.Sha3(), + AES: crypto.Keccak256(), + MAC: crypto.Keccak256(), IngressMAC: hash, EgressMAC: hash, }) diff --git a/tests/util.go b/tests/util.go index 8196d7fd6c540137d745a7bfba32c3e2abb883bd..29f4c9b723582b2ee68f1c4e70316aa0f6cdb9a9 100644 --- a/tests/util.go +++ b/tests/util.go @@ -183,7 +183,7 @@ func (self *Env) Db() vm.Database { return self.state } func (self *Env) GasLimit() *big.Int { return self.gasLimit } func (self *Env) VmType() vm.Type { return vm.StdVmTy } func (self *Env) GetHash(n uint64) common.Hash { - return common.BytesToHash(crypto.Sha3([]byte(big.NewInt(int64(n)).String()))) + return common.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(n)).String()))) } func (self *Env) AddLog(log *vm.Log) { self.state.AddLog(log) diff --git a/trie/secure_trie_test.go b/trie/secure_trie_test.go index 13c6cd02e9e3a1218519fa54cf7f8f8023a7ef28..0be5b3d15ebd0d9d421220b8e72b004b1034de58 100644 --- a/trie/secure_trie_test.go +++ b/trie/secure_trie_test.go @@ -63,7 +63,7 @@ func TestSecureGetKey(t *testing.T) { key := []byte("foo") value := []byte("bar") - seckey := crypto.Sha3(key) + seckey := crypto.Keccak256(key) if !bytes.Equal(trie.Get(key), value) { t.Errorf("Get did not return bar") diff --git a/trie/trie.go b/trie/trie.go index 9dfde45294fc056a68b523105d2f77e8fc07da6e..cc5dcf2a6585666e17e59f7f2a59d77adfa6ef3f 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -40,7 +40,7 @@ var ( emptyRoot = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") // This is the known hash of an empty state trie entry. - emptyState = crypto.Sha3Hash(nil) + emptyState = crypto.Keccak256Hash(nil) ) // ClearGlobalCache clears the global trie cache diff --git a/whisper/envelope.go b/whisper/envelope.go index b231c6b44f62fb026a73cfba031e4ca7d4d4801f..97d489b961d983b55f9a0f2ee04bc6aa1806be69 100644 --- a/whisper/envelope.go +++ b/whisper/envelope.go @@ -66,7 +66,7 @@ func (self *Envelope) Seal(pow time.Duration) { for i := 0; i < 1024; i++ { binary.BigEndian.PutUint32(d[60:], nonce) - firstBit := common.FirstBitSet(common.BigD(crypto.Sha3(d))) + firstBit := common.FirstBitSet(common.BigD(crypto.Keccak256(d))) if firstBit > bestBit { self.Nonce, bestBit = nonce, firstBit } @@ -123,7 +123,7 @@ func (self *Envelope) Open(key *ecdsa.PrivateKey) (msg *Message, err error) { func (self *Envelope) Hash() common.Hash { if (self.hash == common.Hash{}) { enc, _ := rlp.EncodeToBytes(self) - self.hash = crypto.Sha3Hash(enc) + self.hash = crypto.Keccak256Hash(enc) } return self.hash } @@ -142,6 +142,6 @@ func (self *Envelope) DecodeRLP(s *rlp.Stream) error { if err := rlp.DecodeBytes(raw, (*rlpenv)(self)); err != nil { return err } - self.hash = crypto.Sha3Hash(raw) + self.hash = crypto.Keccak256Hash(raw) return nil } diff --git a/whisper/message.go b/whisper/message.go index 506f142edd58eb3c1d091ff2e11cfe2ef211a619..f05b5d8b5421248f40475b8229dbd8c91d40572b 100644 --- a/whisper/message.go +++ b/whisper/message.go @@ -146,7 +146,7 @@ func (self *Message) decrypt(key *ecdsa.PrivateKey) error { // hash calculates the SHA3 checksum of the message flags and payload. func (self *Message) hash() []byte { - return crypto.Sha3(append([]byte{self.Flags}, self.Payload...)) + return crypto.Keccak256(append([]byte{self.Flags}, self.Payload...)) } // bytes flattens the message contents (flags, signature and payload) into a diff --git a/whisper/topic.go b/whisper/topic.go index 7ac3e8dc1dfe244d39380518d40da36174db6e26..d37eb25ee141426fd89a9ed800dbb5296cd6ec80 100644 --- a/whisper/topic.go +++ b/whisper/topic.go @@ -31,7 +31,7 @@ type Topic [4]byte // Note, empty topics are considered the wildcard, and cannot be used in messages. func NewTopic(data []byte) Topic { prefix := [4]byte{} - copy(prefix[:], crypto.Sha3(data)[:4]) + copy(prefix[:], crypto.Keccak256(data)[:4]) return Topic(prefix) }