crypto

package
v0.8.4-1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2015 License: LGPL-2.1-or-later Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MnemonicWords []string = []string{}/* 1626 elements not displayed */

Functions

func CreateAddress

func CreateAddress(b []byte, nonce uint64) []byte

Creates an ethereum address given the bytes and the nonce

func Decrypt

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

func DecryptKey added in v0.8.5

func DecryptKey(ks keyStorePassphrase, keyAddr []byte, auth string) (keyBytes []byte, keyId []byte, err error)

func DefaultDataDir added in v0.8.5

func DefaultDataDir() string

TODO: copied from cmd/ethereum/flags.go

func Ecrecover

func Ecrecover(data []byte) []byte

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 GetKeyAddresses added in v0.8.5

func GetKeyAddresses(keysDirPath string) (addresses [][]byte, err error)

func GetKeyFile added in v0.8.5

func GetKeyFile(keysDirPath string, keyAddr []byte) (fileContent []byte, err error)

func HexToECDSA added in v0.8.5

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

HexToECDSA parses a secp256k1 private key.

func IndexOf

func IndexOf(slice []string, value string) int64

TODO: See if we can refactor this into a shared util lib if we need it multiple times

func LoadECDSA added in v0.8.5

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

LoadECDSA loads a secp256k1 private key from the given file.

func MnemonicDecode

func MnemonicDecode(wordsar []string) string

func MnemonicEncode

func MnemonicEncode(message string) []string

func PKCS7Unpad added in v0.8.5

func PKCS7Unpad(in []byte) []byte

func PubkeyToAddress added in v0.8.5

func PubkeyToAddress(p ecdsa.PublicKey) []byte

func Ripemd160

func Ripemd160(data []byte) []byte

func Sha256

func Sha256(data []byte) []byte

func Sha3

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

func SigToPub

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

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 WriteKeyFile added in v0.8.5

func WriteKeyFile(addr []byte, keysDirPath string, content []byte) (err error)

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 DBKeyStore

type DBKeyStore struct {
	// contains filtered or unexported fields
}

func (*DBKeyStore) Load

func (k *DBKeyStore) Load(session string) (*KeyRing, error)

func (*DBKeyStore) Save

func (k *DBKeyStore) Save(session string, keyRing *KeyRing) error

type FileKeyStore

type FileKeyStore struct {
	// contains filtered or unexported fields
}

func (*FileKeyStore) Load

func (k *FileKeyStore) Load(session string) (*KeyRing, error)

func (*FileKeyStore) Save

func (k *FileKeyStore) Save(session string, keyRing *KeyRing) error

type Key added in v0.8.5

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 []byte
	// 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 added in v0.8.5

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

func ImportPreSaleKey added in v0.8.5

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

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

func NewKey added in v0.8.5

func NewKey(rand io.Reader) *Key

func (*Key) MarshalJSON added in v0.8.5

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

func (*Key) UnmarshalJSON added in v0.8.5

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

type KeyManager

type KeyManager struct {
	// contains filtered or unexported fields
}

func NewDBKeyManager

func NewDBKeyManager(db ethutil.Database) *KeyManager

func NewFileKeyManager

func NewFileKeyManager(basedir string) *KeyManager

func (*KeyManager) Address

func (k *KeyManager) Address() []byte

func (*KeyManager) Export

func (k *KeyManager) Export(dir string) error

func (*KeyManager) Init

func (k *KeyManager) Init(session string, cursor int, force bool) error

func (*KeyManager) InitFromSecretsFile

func (k *KeyManager) InitFromSecretsFile(session string, cursor int, secretsfile string) error

func (*KeyManager) InitFromString

func (k *KeyManager) InitFromString(session string, cursor int, secrets string) error

func (*KeyManager) KeyPair

func (k *KeyManager) KeyPair() *KeyPair

func (*KeyManager) KeyRing

func (k *KeyManager) KeyRing() *KeyPair

func (*KeyManager) PrivateKey

func (k *KeyManager) PrivateKey() []byte

func (*KeyManager) PublicKey

func (k *KeyManager) PublicKey() []byte

func (*KeyManager) SetCursor

func (k *KeyManager) SetCursor(cursor int) error

type KeyPair

type KeyPair struct {
	PrivateKey []byte
	PublicKey  []byte
	// contains filtered or unexported fields
}

func GenerateNewKeyPair

func GenerateNewKeyPair() *KeyPair

func NewKeyPairFromSec

func NewKeyPairFromSec(seckey []byte) (*KeyPair, error)

func (*KeyPair) Address

func (k *KeyPair) Address() []byte

func (*KeyPair) AsStrings

func (k *KeyPair) AsStrings() (string, string, string, string)

func (*KeyPair) Mnemonic

func (k *KeyPair) Mnemonic() string

func (*KeyPair) RlpEncode

func (k *KeyPair) RlpEncode() []byte

func (*KeyPair) RlpValue

func (k *KeyPair) RlpValue() *ethutil.Value

type KeyRing

type KeyRing struct {
	// contains filtered or unexported fields
}

func NewGeneratedKeyRing

func NewGeneratedKeyRing(len int) *KeyRing

func NewKeyRing

func NewKeyRing() *KeyRing

func NewKeyRingFromBytes

func NewKeyRingFromBytes(data []byte) (*KeyRing, error)

func NewKeyRingFromFile

func NewKeyRingFromFile(secfile string) (*KeyRing, error)

func NewKeyRingFromSecrets

func NewKeyRingFromSecrets(secs [][]byte) (*KeyRing, error)

func NewKeyRingFromString

func NewKeyRingFromString(content string) (*KeyRing, error)

func (*KeyRing) AddKeyPair

func (k *KeyRing) AddKeyPair(keyPair *KeyPair)

func (*KeyRing) Each

func (k *KeyRing) Each(f func(*KeyPair))

func (*KeyRing) Empty

func (k *KeyRing) Empty() bool

func (*KeyRing) GetKeyPair

func (k *KeyRing) GetKeyPair(i int) *KeyPair

func (*KeyRing) Len

func (k *KeyRing) Len() int

func (*KeyRing) RlpEncode

func (k *KeyRing) RlpEncode() []byte

func (*KeyRing) RlpValue

func (k *KeyRing) RlpValue() *ethutil.Value

type KeyStore

type KeyStore interface {
	Load(string) (*KeyRing, error)
	Save(string, *KeyRing) error
}

type KeyStore2 added in v0.8.5

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

TODO: rename to KeyStore when replacing existing KeyStore

func NewKeyStorePassphrase added in v0.8.5

func NewKeyStorePassphrase(path string) KeyStore2

func NewKeyStorePlain added in v0.8.5

func NewKeyStorePlain(path string) KeyStore2

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