go-ethereum: github.com/axiomzen/go-ethereum/crypto Index | Files | Directories

package crypto

import "github.com/axiomzen/go-ethereum/crypto"


Package Files

crypto.go signature_cgo.go

func CompressPubkey Uses

func CompressPubkey(pubkey *ecdsa.PublicKey) []byte

CompressPubkey encodes a public key to the 33-byte compressed format.

func CreateAddress Uses

func CreateAddress(b common.Address, nonce uint64) common.Address

CreateAddress creates an ethereum address given the bytes and the nonce

func CreateAddress2 Uses

func CreateAddress2(b common.Address, salt [32]byte, inithash []byte) common.Address

CreateAddress2 creates an ethereum address given the address bytes, initial contract code hash and a salt.

func DecompressPubkey Uses

func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)

DecompressPubkey parses a public key in the 33-byte compressed format.

func Ecrecover Uses

func Ecrecover(hash, sig []byte) ([]byte, error)

Ecrecover returns the uncompressed public key that created the given signature.

func FromECDSA Uses

func FromECDSA(priv *ecdsa.PrivateKey) []byte

FromECDSA exports a private key into a binary dump.

func FromECDSAPub Uses

func FromECDSAPub(pub *ecdsa.PublicKey) []byte

func GenerateKey Uses

func GenerateKey() (*ecdsa.PrivateKey, error)

func HexToECDSA Uses

func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error)

HexToECDSA parses a secp256k1 private key.

func Keccak256 Uses

func Keccak256(data ...[]byte) []byte

Keccak256 calculates and returns the Keccak256 hash of the input data.

func Keccak256Hash Uses

func Keccak256Hash(data ...[]byte) (h common.Hash)

Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.

func Keccak512 Uses

func Keccak512(data ...[]byte) []byte

Keccak512 calculates and returns the Keccak512 hash of the input data.

func LoadECDSA Uses

func LoadECDSA(file string) (*ecdsa.PrivateKey, error)

LoadECDSA loads a secp256k1 private key from the given file.

func PubkeyToAddress Uses

func PubkeyToAddress(p ecdsa.PublicKey) common.Address

func S256 Uses

func S256() elliptic.Curve

S256 returns an instance of the secp256k1 curve.

func SaveECDSA Uses

func SaveECDSA(file string, key *ecdsa.PrivateKey) error

SaveECDSA saves a secp256k1 private key to the given file with restrictive permissions. The key data is saved hex-encoded.

func SigToPub Uses

func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)

SigToPub returns the public key that created the given signature.

func Sign Uses

func Sign(hash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error)

Sign calculates an ECDSA signature.

This function is susceptible to chosen plaintext attacks that can leak information about the private key that is used for signing. Callers must be aware that the given hash cannot be chosen by an adversery. Common solution is to hash any input before calculating the signature.

The produced signature is in the [R || S || V] format where V is 0 or 1.

func ToECDSA Uses

func ToECDSA(d []byte) (*ecdsa.PrivateKey, error)

ToECDSA creates a private key with the given D value.

func ToECDSAUnsafe Uses

func ToECDSAUnsafe(d []byte) *ecdsa.PrivateKey

ToECDSAUnsafe blindly converts a binary blob to a private key. It should almost never be used unless you are sure the input is valid and want to avoid hitting errors due to bad origin encoding (0 prefixes cut off).

func UnmarshalPubkey Uses

func UnmarshalPubkey(pub []byte) (*ecdsa.PublicKey, error)

UnmarshalPubkey converts bytes to a secp256k1 public key.

func ValidateSignatureValues Uses

func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool

ValidateSignatureValues verifies whether the signature values are valid with the given chain rules. The v value is assumed to be either 0 or 1.

func VerifySignature Uses

func VerifySignature(pubkey, hash, signature []byte) bool

VerifySignature checks that the given public key created signature over hash. The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format. The signature should have the 64 byte [R || S] format.


bn256Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
bn256/googlePackage bn256 implements a particular bilinear group.
secp256k1Package secp256k1 wraps the bitcoin secp256k1 C library.

Package crypto imports 15 packages (graph). Updated 2019-07-06. Refresh now. Tools for package owners.