From 436fc8d76a4871d67a61dc86c1a635e20594a0e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Catalinas=20Jim=C3=A9nez?= Date: Sun, 21 Feb 2016 18:40:27 +0000 Subject: all: Rename crypto.Sha3{,Hash}() to crypto.Keccak256{,Hash}() As we aren't really using the standarized SHA-3 --- crypto/crypto.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crypto/crypto.go') diff --git a/crypto/crypto.go b/crypto/crypto.go index 850be4da6..f8e03acc5 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) { -- cgit v1.2.3 From 0c6665558a122bd7485fd4548801da54c520d7aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Catalinas=20Jim=C3=A9nez?= Date: Sun, 21 Feb 2016 22:45:08 +0000 Subject: crypto: Add backward compatible aliases for Sha3{,Hash}() --- crypto/crypto.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'crypto/crypto.go') diff --git a/crypto/crypto.go b/crypto/crypto.go index f8e03acc5..a947d84d2 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -60,6 +60,10 @@ func Keccak256Hash(data ...[]byte) (h common.Hash) { return h } +// Deprecated: For backward compatibility as other packages depend on these +func Sha3(data ...[]byte) []byte { return Keccak256(data...) } +func Sha3Hash(data ...[]byte) common.Hash { return Keccak256Hash(data...) } + // 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}) -- cgit v1.2.3 From 3d971c5a34ad14b13c6cc446e2ff41156b202c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Catalinas=20Jim=C3=A9nez?= Date: Sun, 21 Feb 2016 20:05:22 +0000 Subject: crypto: Remove dead code --- crypto/crypto.go | 1 - 1 file changed, 1 deletion(-) (limited to 'crypto/crypto.go') diff --git a/crypto/crypto.go b/crypto/crypto.go index a947d84d2..f1f6affac 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -68,7 +68,6 @@ func Sha3Hash(data ...[]byte) common.Hash { return Keccak256Hash(data...) } func CreateAddress(b common.Address, nonce uint64) common.Address { data, _ := rlp.EncodeToBytes([]interface{}{b, nonce}) return common.BytesToAddress(Keccak256(data)[12:]) - //return Sha3(common.NewValue([]interface{}{b, nonce}).Encode())[12:] } func Sha256(data []byte) []byte { -- cgit v1.2.3