aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorRicardo Catalinas Jiménez <r@untroubled.be>2016-02-22 02:40:27 +0800
committerRicardo Catalinas Jiménez <r@untroubled.be>2016-02-22 06:34:34 +0800
commit436fc8d76a4871d67a61dc86c1a635e20594a0e6 (patch)
tree5fad9f69b068f43ca606e2887f5522188e7f9ddd /crypto
parentc20d6e5e4ed8eff6d26cd849f90ca42dd5a7040c (diff)
downloaddexon-436fc8d76a4871d67a61dc86c1a635e20594a0e6.tar.gz
dexon-436fc8d76a4871d67a61dc86c1a635e20594a0e6.tar.zst
dexon-436fc8d76a4871d67a61dc86c1a635e20594a0e6.zip
all: Rename crypto.Sha3{,Hash}() to crypto.Keccak256{,Hash}()
As we aren't really using the standarized SHA-3
Diffstat (limited to 'crypto')
-rw-r--r--crypto/crypto.go10
-rw-r--r--crypto/crypto_test.go10
-rw-r--r--crypto/key_store_passphrase.go8
3 files changed, 14 insertions, 14 deletions
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) {
diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go
index 1681c7fef..58b29da49 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 94411d2f9..b7ae9e1de 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
}