aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-08 18:00:50 +0800
committerobscuren <geffobscura@gmail.com>2014-10-08 18:00:50 +0800
commit11ace543072726e76743f157a31956ad1b941956 (patch)
tree17c044e32d41480c939567fee8637e674f3336d5
parent6de726f16cff6a79939cd9182424c7e9ef678044 (diff)
downloadgo-tangerine-11ace543072726e76743f157a31956ad1b941956.tar
go-tangerine-11ace543072726e76743f157a31956ad1b941956.tar.gz
go-tangerine-11ace543072726e76743f157a31956ad1b941956.tar.bz2
go-tangerine-11ace543072726e76743f157a31956ad1b941956.tar.lz
go-tangerine-11ace543072726e76743f157a31956ad1b941956.tar.xz
go-tangerine-11ace543072726e76743f157a31956ad1b941956.tar.zst
go-tangerine-11ace543072726e76743f157a31956ad1b941956.zip
ECRECOVER RIPEMD160 SHA256
-rw-r--r--ethcrypto/crypto.go30
1 files changed, 30 insertions, 0 deletions
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
+}