X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=crypto%2Fcrypto.go;h=cd330372fb22c2ce7d18181e246c84b19ba696f3;hb=a85670d48d75303a3c015389a7a6a0368eb97355;hp=db2079f6da9d5af68c5311ae42e790c16bb29a42;hpb=e254dde6bae775f839176883943eb55e8c0fdb8d;p=bytom%2Fbytom.git diff --git a/crypto/crypto.go b/crypto/crypto.go index db2079f6..cd330372 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -17,21 +17,11 @@ package crypto import ( - "fmt" - //"io" - //"io/ioutil" - //"math/big" - //"os" - - //"encoding/hex" - //"errors" - "github.com/bytom/common" - "golang.org/x/crypto/sha3" "golang.org/x/crypto/ripemd160" + "golang.org/x/crypto/sha3" ) - func Sha256(data ...[]byte) []byte { d := sha3.New256() for _, b := range data { @@ -52,43 +42,9 @@ func Sha256Hash(data ...[]byte) (h common.Hash) { func Sha3(data ...[]byte) []byte { return Sha256(data...) } func Sha3Hash(data ...[]byte) common.Hash { return Sha256Hash(data...) } - func Ripemd160(data []byte) []byte { ripemd := ripemd160.New() ripemd.Write(data) return ripemd.Sum(nil) } - -func PubkeyToAddress(pubBytes []byte) common.Address{ - address, _ := common.AddressEncode("bm", 1, toInt(Ripemd160(Sha3(pubBytes)))) - fmt.Printf(address) - return common.StringToAddress(address) -} - -func AddressToPubkey(addr common.Address) (int, []byte, error) { - ver, data, err := common.AddressDecode("bm", addr.Str()) - return ver, toBytes(data), err -} - -func zeroBytes(bytes []byte) { - for i := range bytes { - bytes[i] = 0 - } -} - -func toInt(bytes []byte) []int{ - ints := make([]int, len(bytes)) - for i := range bytes { - ints[i] = int(bytes[i]) - } - return ints -} - -func toBytes(ints []int) []byte{ - bytes := make([]byte, len(ints)) - for i := range ints { - bytes[i] = byte(ints[i]) - } - return bytes -}