From d085133c6d9d75e9cbd016a9a597097fa2bb4345 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 29 Jun 2014 15:57:12 +0100 Subject: move ethutil helper crypto functions to ethcrypto/crypto --- ethcrypto/crypto.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ethcrypto/crypto.go (limited to 'ethcrypto/crypto.go') diff --git a/ethcrypto/crypto.go b/ethcrypto/crypto.go new file mode 100644 index 000000000..9c4013d6c --- /dev/null +++ b/ethcrypto/crypto.go @@ -0,0 +1,27 @@ +package ethcrypto + +import ( + "code.google.com/p/go.crypto/ripemd160" + "crypto/sha256" + "github.com/obscuren/sha3" +) + +func Sha256Bin(data []byte) []byte { + hash := sha256.Sum256(data) + + return hash[:] +} + +func Ripemd160(data []byte) []byte { + ripemd := ripemd160.New() + ripemd.Write(data) + + return ripemd.Sum(nil) +} + +func Sha3Bin(data []byte) []byte { + d := sha3.NewKeccak256() + d.Write(data) + + return d.Sum(nil) +} -- cgit From e3b911652dfba1475001137ba8b3687b9fec5331 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 29 Jun 2014 16:08:33 +0100 Subject: move CreateAddress from ethutil/common to ethcrypto --- ethcrypto/crypto.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ethcrypto/crypto.go') diff --git a/ethcrypto/crypto.go b/ethcrypto/crypto.go index 9c4013d6c..b341915eb 100644 --- a/ethcrypto/crypto.go +++ b/ethcrypto/crypto.go @@ -25,3 +25,10 @@ func Sha3Bin(data []byte) []byte { return d.Sum(nil) } + +// Creates an ethereum address given the bytes and the nonce +func CreateAddress(b []byte, nonce *big.Int) []byte { + addrBytes := append(b, nonce.Bytes()...) + + return Sha3Bin(addrBytes)[12:] +} -- cgit From 4be3521727698141512eb6454121302bd3b9cc6d Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 29 Jun 2014 16:17:33 +0100 Subject: import math/big --- ethcrypto/crypto.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethcrypto/crypto.go') diff --git a/ethcrypto/crypto.go b/ethcrypto/crypto.go index b341915eb..8cb0be88c 100644 --- a/ethcrypto/crypto.go +++ b/ethcrypto/crypto.go @@ -4,6 +4,7 @@ import ( "code.google.com/p/go.crypto/ripemd160" "crypto/sha256" "github.com/obscuren/sha3" + "math/big" ) func Sha256Bin(data []byte) []byte { -- cgit From 81bc721c5cd0330547e18bfb710d68d60da4dd46 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 3 Jul 2014 10:03:58 +0200 Subject: Fixed address generation --- ethcrypto/crypto.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'ethcrypto/crypto.go') diff --git a/ethcrypto/crypto.go b/ethcrypto/crypto.go index 8cb0be88c..b4bb881a0 100644 --- a/ethcrypto/crypto.go +++ b/ethcrypto/crypto.go @@ -3,8 +3,8 @@ package ethcrypto import ( "code.google.com/p/go.crypto/ripemd160" "crypto/sha256" + "github.com/ethereum/eth-go/ethutil" "github.com/obscuren/sha3" - "math/big" ) func Sha256Bin(data []byte) []byte { @@ -28,8 +28,6 @@ func Sha3Bin(data []byte) []byte { } // Creates an ethereum address given the bytes and the nonce -func CreateAddress(b []byte, nonce *big.Int) []byte { - addrBytes := append(b, nonce.Bytes()...) - - return Sha3Bin(addrBytes)[12:] +func CreateAddress(b []byte, nonce uint64) []byte { + return Sha3Bin(ethutil.NewValue([]interface{}{b, nonce}).Encode())[12:] } -- cgit From 54715586ab147a62342a9462f3a73cc2f750d148 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 12 Jul 2014 11:10:47 +0200 Subject: Changed sha3 to official one --- ethcrypto/crypto.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethcrypto/crypto.go') diff --git a/ethcrypto/crypto.go b/ethcrypto/crypto.go index b4bb881a0..19f8c9e55 100644 --- a/ethcrypto/crypto.go +++ b/ethcrypto/crypto.go @@ -2,9 +2,9 @@ package ethcrypto import ( "code.google.com/p/go.crypto/ripemd160" + "code.google.com/p/go.crypto/sha3" "crypto/sha256" "github.com/ethereum/eth-go/ethutil" - "github.com/obscuren/sha3" ) func Sha256Bin(data []byte) []byte { -- cgit From 8ef17c2fb138ae254a0cc7ac509a7ab1177ee4ac Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 13 Sep 2014 14:39:01 +0200 Subject: fi crypto --- ethcrypto/crypto.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'ethcrypto/crypto.go') diff --git a/ethcrypto/crypto.go b/ethcrypto/crypto.go index 19f8c9e55..1f500f2db 100644 --- a/ethcrypto/crypto.go +++ b/ethcrypto/crypto.go @@ -1,25 +1,11 @@ package ethcrypto import ( - "code.google.com/p/go.crypto/ripemd160" - "code.google.com/p/go.crypto/sha3" - "crypto/sha256" + //"code.google.com/p/go.crypto/sha3" "github.com/ethereum/eth-go/ethutil" + "github.com/obscuren/sha3" ) -func Sha256Bin(data []byte) []byte { - hash := sha256.Sum256(data) - - return hash[:] -} - -func Ripemd160(data []byte) []byte { - ripemd := ripemd160.New() - ripemd.Write(data) - - return ripemd.Sum(nil) -} - func Sha3Bin(data []byte) []byte { d := sha3.NewKeccak256() d.Write(data) -- cgit From 11ace543072726e76743f157a31956ad1b941956 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 8 Oct 2014 12:00:50 +0200 Subject: ECRECOVER RIPEMD160 SHA256 --- ethcrypto/crypto.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'ethcrypto/crypto.go') diff --git a/ethcrypto/crypto.go b/ethcrypto/crypto.go index 1f500f2db..624c5169f 100644 --- a/ethcrypto/crypto.go +++ b/ethcrypto/crypto.go @@ -2,10 +2,16 @@ package ethcrypto import ( //"code.google.com/p/go.crypto/sha3" + "crypto/sha256" + + "code.google.com/p/go.crypto/ripemd160" "github.com/ethereum/eth-go/ethutil" "github.com/obscuren/sha3" + + "github.com/obscuren/secp256k1-go" ) +// TODO refactor, remove (bin) func Sha3Bin(data []byte) []byte { d := sha3.NewKeccak256() d.Write(data) @@ -17,3 +23,27 @@ func Sha3Bin(data []byte) []byte { func CreateAddress(b []byte, nonce uint64) []byte { return Sha3Bin(ethutil.NewValue([]interface{}{b, nonce}).Encode())[12:] } + +func Sha256(data []byte) []byte { + hash := sha256.Sum256(data) + + return hash[:] +} + +func Ripemd160(data []byte) []byte { + ripemd := ripemd160.New() + ripemd.Write(data) + + return ripemd.Sum(nil) +} + +func Ecrecover(data []byte) []byte { + var in = struct { + hash []byte + sig []byte + }{data[:32], data[32:]} + + r, _ := secp256k1.RecoverPubkey(in.hash, in.sig) + + return r +} -- cgit From 9d86a49a7327199c01977f3372c8adf748252c32 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 8 Oct 2014 12:06:39 +0200 Subject: Renamed Sha3Bin to Sha3 --- ethcrypto/crypto.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'ethcrypto/crypto.go') diff --git a/ethcrypto/crypto.go b/ethcrypto/crypto.go index 624c5169f..ebc8b171b 100644 --- a/ethcrypto/crypto.go +++ b/ethcrypto/crypto.go @@ -1,7 +1,6 @@ package ethcrypto import ( - //"code.google.com/p/go.crypto/sha3" "crypto/sha256" "code.google.com/p/go.crypto/ripemd160" @@ -12,7 +11,7 @@ import ( ) // TODO refactor, remove (bin) -func Sha3Bin(data []byte) []byte { +func Sha3(data []byte) []byte { d := sha3.NewKeccak256() d.Write(data) @@ -21,7 +20,7 @@ func Sha3Bin(data []byte) []byte { // Creates an ethereum address given the bytes and the nonce func CreateAddress(b []byte, nonce uint64) []byte { - return Sha3Bin(ethutil.NewValue([]interface{}{b, nonce}).Encode())[12:] + return Sha3(ethutil.NewValue([]interface{}{b, nonce}).Encode())[12:] } func Sha256(data []byte) []byte { -- cgit