crypto

package
v0.0.0-...-7505a0c Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2019 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HashLength    = 32
	AddressLength = 20
)

Variables

View Source
var (
	ErrExceedHashLength = errors.New("bytes length exceed maximum hash length of 32")
)

Functions

func CompressPubkey

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

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

func DecompressPubkey

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

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

func Ecrecover

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

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

func GenerateKey

func GenerateKey(rand io.Reader) (prv *secp256k1.PrivateKey, err error)

Generate an elliptic curve public / private keypair. If params is nil, the recommended default parameters for the key will be chosen.

func Keccak256

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

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

func LoadECDSA

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

LoadECDSA loads a secp256k1 private key from the given file.

func SaveECDSA

func SaveECDSA(file string, key *secp256k1.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) (*secp256k1.PublicKey, error)

SigToPub returns the public key that created the given signature.

func Sign

func Sign(hash []byte, prv *secp256k1.PrivateKey) ([]byte, 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 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.

func VerifySignature

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.

Types

type ByteCode

type ByteCode []byte

type CommonAddress

type CommonAddress [AddressLength]byte

func Big2Address

func Big2Address(x *big.Int) CommonAddress

func Bytes2Address

func Bytes2Address(b []byte) CommonAddress

func CreateAddress

func CreateAddress(b CommonAddress, nonce uint64) CommonAddress

CreateAddress creates an ethereum address given the bytes and the nonce

func CreateAddress2

func CreateAddress2(b CommonAddress, salt [32]byte, code []byte) CommonAddress

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

func GetByteCodeAddress

func GetByteCodeAddress(callerAddr CommonAddress, nonce int64) CommonAddress

func Hex2Address

func Hex2Address(s string) CommonAddress

func PubKey2Address

func PubKey2Address(pubKey *secp256k1.PublicKey) CommonAddress

func PubkeyToAddress

func PubkeyToAddress(p *secp256k1.PublicKey) CommonAddress

func (CommonAddress) Big

func (addr CommonAddress) Big() *big.Int

func (CommonAddress) Bytes

func (addr CommonAddress) Bytes() []byte

func (CommonAddress) Hex

func (addr CommonAddress) Hex() string

func (CommonAddress) IsEmpty

func (addr CommonAddress) IsEmpty() bool

func (CommonAddress) MarshalText

func (addr CommonAddress) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a.

func (*CommonAddress) SetBytes

func (addr *CommonAddress) SetBytes(b []byte)

func (*CommonAddress) UnmarshalJSON

func (addr *CommonAddress) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (CommonAddress) UnmarshalText

func (addr CommonAddress) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

type Hash

type Hash [HashLength]byte

func Big2Hash

func Big2Hash(x *big.Int) Hash

func Bytes2Hash

func Bytes2Hash(b []byte) Hash

func GetByteCodeHash

func GetByteCodeHash(byteCode ByteCode) Hash

func Keccak256Hash

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

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

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

Directories

Path Synopsis
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
cloudflare
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.
google
Package bn256 implements a particular bilinear group.
Package bn256 implements a particular bilinear group.
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