crypto

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2016 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// n,r,p = 2^18, 8, 1 uses 256MB memory and approx 1s CPU time on a modern CPU.
	StandardScryptN = 1 << 18
	StandardScryptP = 1

	// n,r,p = 2^12, 8, 6 uses 4MB memory and approx 100ms CPU time on a modern CPU.
	LightScryptN = 1 << 12
	LightScryptP = 6
)

Variables

This section is empty.

Functions

func CreateAddress

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

Creates an ethereum address given the bytes and the nonce

func Decrypt

func Decrypt(prv *ecdsa.PrivateKey, ct []byte) ([]byte, error)

func Ecrecover

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

func Encrypt

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

func FromECDSA

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

func FromECDSAPub

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

func GenerateKey

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

func HexToECDSA

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

HexToECDSA parses a secp256k1 private key.

func ImportBlockTestKey

func ImportBlockTestKey(privKeyBytes []byte) error

Used only by block tests.

func LoadECDSA

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

LoadECDSA loads a secp256k1 private key from the given file. The key data is expected to be hex-encoded.

func PubkeyToAddress

func PubkeyToAddress(p ecdsa.PublicKey) common.Address

func Ripemd160

func Ripemd160(data []byte) []byte

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 Sha256

func Sha256(data []byte) []byte

func Sha3

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

func Sha3Hash

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

func SigToPub

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

func Sign

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

func ToECDSA

func ToECDSA(prv []byte) *ecdsa.PrivateKey

New methods using proper ecdsa keys from the stdlib

func ToECDSAPub

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

func ValidateSignatureValues

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

Types

type BitCurve

type BitCurve struct {
	P       *big.Int // the order of the underlying field
	N       *big.Int // the order of the base point
	B       *big.Int // the constant of the BitCurve equation
	Gx, Gy  *big.Int // (x,y) of the base point
	BitSize int      // the size of the underlying field
}

A BitCurve represents a Koblitz Curve with a=0. See http://www.hyperelliptic.org/EFD/g1p/auto-shortw.html

func S160

func S160() *BitCurve

S160 returns a BitCurve which implements secp160k1 (see SEC 2 section 2.4.1)

func S192

func S192() *BitCurve

S192 returns a BitCurve which implements secp192k1 (see SEC 2 section 2.5.1)

func S224

func S224() *BitCurve

S224 returns a BitCurve which implements secp224k1 (see SEC 2 section 2.6.1)

func S256

func S256() *BitCurve

S256 returns a BitCurve which implements secp256k1 (see SEC 2 section 2.7.1)

func (*BitCurve) Add

func (BitCurve *BitCurve) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int)

Add returns the sum of (x1,y1) and (x2,y2)

func (*BitCurve) Double

func (BitCurve *BitCurve) Double(x1, y1 *big.Int) (*big.Int, *big.Int)

Double returns 2*(x,y)

func (*BitCurve) GenerateKey

func (BitCurve *BitCurve) GenerateKey(rand io.Reader) (priv []byte, x, y *big.Int, err error)

TODO: double check if it is okay GenerateKey returns a public/private key pair. The private key is generated using the given reader, which must return random data.

func (*BitCurve) IsOnCurve

func (BitCurve *BitCurve) IsOnCurve(x, y *big.Int) bool

IsOnBitCurve returns true if the given (x,y) lies on the BitCurve.

func (*BitCurve) Marshal

func (BitCurve *BitCurve) Marshal(x, y *big.Int) []byte

Marshal converts a point into the form specified in section 4.3.6 of ANSI X9.62.

func (*BitCurve) Params

func (BitCurve *BitCurve) Params() *elliptic.CurveParams

func (*BitCurve) ScalarBaseMult

func (BitCurve *BitCurve) ScalarBaseMult(k []byte) (*big.Int, *big.Int)

ScalarBaseMult returns k*G, where G is the base point of the group and k is an integer in big-endian form.

func (*BitCurve) ScalarMult

func (BitCurve *BitCurve) ScalarMult(Bx, By *big.Int, k []byte) (*big.Int, *big.Int)

TODO: double check if it is okay ScalarMult returns k*(Bx,By) where k is a number in big-endian form.

func (*BitCurve) Unmarshal

func (BitCurve *BitCurve) Unmarshal(data []byte) (x, y *big.Int)

Unmarshal converts a point, serialised by Marshal, into an x, y pair. On error, x = nil.

type Key

type Key struct {
	Id uuid.UUID // Version 4 "random" for unique id not derived from key data
	// to simplify lookups we also store the address
	Address common.Address
	// we only store privkey as pubkey/address can be derived from it
	// privkey in this struct is always in plaintext
	PrivateKey *ecdsa.PrivateKey
}

func GenerateNewKeyDefault

func GenerateNewKeyDefault(ks KeyStore, rand io.Reader, auth string) (key *Key, err error)

func ImportPreSaleKey

func ImportPreSaleKey(keyStore KeyStore, keyJSON []byte, password string) (*Key, error)

creates a Key and stores that in the given KeyStore by decrypting a presale key JSON

func NewKey

func NewKey(rand io.Reader) *Key

func NewKeyForDirectICAP added in v1.3.1

func NewKeyForDirectICAP(rand io.Reader) *Key

generate key whose address fits into < 155 bits so it can fit into the Direct ICAP spec. for simplicity and easier compatibility with other libs, we retry until the first byte is 0.

func NewKeyFromECDSA

func NewKeyFromECDSA(privateKeyECDSA *ecdsa.PrivateKey) *Key

func (*Key) MarshalJSON

func (k *Key) MarshalJSON() (j []byte, err error)

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(j []byte) (err error)

type KeyStore

type KeyStore interface {
	// create new key using io.Reader entropy source and optionally using auth string
	GenerateNewKey(io.Reader, string) (*Key, error)
	GetKey(common.Address, string) (*Key, error) // get key from addr and auth string
	GetKeyAddresses() ([]common.Address, error)  // get all addresses
	StoreKey(*Key, string) error                 // store key optionally using auth string
	DeleteKey(common.Address, string) error      // delete key by addr and auth string
	Cleanup(keyAddr common.Address) (err error)
}

func NewKeyStorePassphrase

func NewKeyStorePassphrase(path string, scryptN int, scryptP int) KeyStore

func NewKeyStorePlain

func NewKeyStorePlain(path string) KeyStore

Directories

Path Synopsis
Package sha3 implements the SHA3 hash algorithm (formerly called Keccak) chosen by NIST in 2012.
Package sha3 implements the SHA3 hash algorithm (formerly called Keccak) chosen by NIST in 2012.

Jump to

Keyboard shortcuts

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