crypto

package module
v0.0.0-...-355c6fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2018 License: MIT Imports: 14 Imported by: 1

README

crypt

公共加密库

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAddress

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

CreateAddress return a new address with the specified address and nonce. Generally, it's used to create the contract address based on account address and nonce.

func Ecrecover

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

func FromECDSA

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

FromECDSA exports a private key into a binary dump.

func FromECDSAPub

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

func GenerateKey

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

func GenerateKeyPair

func GenerateKeyPair() (*common.Address, *ecdsa.PrivateKey, error)

GenerateKeyPair generate public key and private key

func GenerateRandomAddress

func GenerateRandomAddress() (*common.Address, error)

GenerateRandomAddress generates and returns a random address.

func GetAddress

func GetAddress(key *ecdsa.PrivateKey) (*common.Address, error)

func HashBytes

func HashBytes(data ...[]byte) common.Hash

HashBytes returns the hash of the input data.

func HexToECDSA

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

HexToECDSA parses a secp256k1 private key.

func Keccak256

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

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

func Keccak256Hash

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

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

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

func LoadECDSA

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

LoadECDSA loads a secp256k1 private key from the given file.

func MustGenerateRandomAddress

func MustGenerateRandomAddress() *common.Address

MustGenerateRandomAddress generates and returns a random address. Panics on any error.

func MustGetAddress

func MustGetAddress(key *ecdsa.PrivateKey) *common.Address

MustGetAddress in fact the err will not occur, so use MustGetAddress will always work

func MustHash

func MustHash(v interface{}) common.Hash

MustHash returns the hash of the specified value. Panics on error, e.g. unsupported data type for encoding.

func PubkeyToAddress

func PubkeyToAddress(p ecdsa.PublicKey) common.Address

func S256

func S256() elliptic.Curve

S256 returns an instance of the secp256k1 curve.

func SaveECDSA

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

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

func Sign

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

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

ToECDSA creates a private key with the given D value.

func ToECDSAPub

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

func ToECDSAUnsafe

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

ToECDSAUnsafe blidly 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 ValidateSignatureValues

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.

Types

This section is empty.

Directories

Path Synopsis
Package bn256 implements a particular bilinear group at the 128-bit security level.
Package bn256 implements a particular bilinear group at the 128-bit security level.
Package secp256k1 wraps the bitcoin secp256k1 C library.
Package secp256k1 wraps the bitcoin secp256k1 C library.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL