crypto: add Sha3Hash

This commit is contained in:
Felix Lange 2015-03-16 17:27:24 +01:00
parent e620bde405
commit 64490897f3

View File

@ -16,10 +16,10 @@ import (
"errors" "errors"
"code.google.com/p/go-uuid/uuid" "code.google.com/p/go-uuid/uuid"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/ethereum/go-ethereum/crypto/secp256k1" "github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/common"
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/ripemd160" "golang.org/x/crypto/ripemd160"
) )
@ -37,6 +37,15 @@ func Sha3(data ...[]byte) []byte {
return d.Sum(nil) return d.Sum(nil)
} }
func Sha3Hash(data ...[]byte) (h common.Hash) {
d := sha3.NewKeccak256()
for _, b := range data {
d.Write(b)
}
d.Sum(h[:])
return h
}
// Creates an ethereum address given the bytes and the nonce // Creates an ethereum address given the bytes and the nonce
func CreateAddress(b []byte, nonce uint64) []byte { func CreateAddress(b []byte, nonce uint64) []byte {
return Sha3(common.NewValue([]interface{}{b, nonce}).Encode())[12:] return Sha3(common.NewValue([]interface{}{b, nonce}).Encode())[12:]