keys

package
v0.0.0-...-50e3d47 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Curve

func Curve() elliptic.Curve

Curve returns an elliptic.Curve. We use btcsuite's golang implementation of secp256k1.

func DecodeSignature

func DecodeSignature(sig string) (r, s *big.Int, err error)

DecodeSignature parses a string representation of a signature as produced by EncodeSignature.

func DumpPrivateKey

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

DumpPrivateKey exports a private key into a binary dump.

func EncodeSignature

func EncodeSignature(r, s *big.Int) string

EncodeSignature returns a string representation of a signature.

func FromPublicKey

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

FromPublicKey is a wrapper around elliptic.Marshal which calls Curve() to determine which elliptic.Curve to use. It outputs the point in uncompressed form.

func GenerateECDSAKey

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

GenerateECDSAKey creates a new ecdsa.PrivateKey using the elliptic.Curve returned by Curve() function.

func Hash32

func Hash32(data []byte) uint32

Hash32 ...

func ParsePrivateKey

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

ParsePrivateKey creates a private key with the given D value.

func PrivateKeyHex

func PrivateKeyHex(key *ecdsa.PrivateKey) string

PrivateKeyHex returns the hexadecimal representation of a raw private key as returned by DumpPrivateKey

func PublicKeyHex

func PublicKeyHex(pub *ecdsa.PublicKey) string

PublicKeyHex returns the hexadecimal reprentation of the uncompressed form of the public key

func PublicKeyID

func PublicKeyID(pub *ecdsa.PublicKey) uint32

PublicKeyID tries to give a unique uint32 representation of the public key. There is obviously a risk of collision here. The uint32 is used to save space in the wire encoding of hashgraph Events, by replacing the uncompressed form of public-keys (65 bytes for secp256k1 curve) with uint32 (8 bytes).

XXX THIS SEEMS LIKE AN ATTACK VECTOR

func Sign

func Sign(priv *ecdsa.PrivateKey, hash []byte) (r, s *big.Int, err error)

Sign is a wrapper around ecdsa.Sign which uses the built-in pseudo-random generator rand.Reader.

func ToPublicKey

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

ToPublicKey is a wrapper around elliptic.Unmarshal which calls Curve() to determine which elliptic.Curve to use. The argument pub is expected to be the uncompressed form of point on the curve, as returned by FromPublicKey.

func Verify

func Verify(pub *ecdsa.PublicKey, hash []byte, r, s *big.Int) bool

Verify is a wrapper around ecdsa.Verify.

Types

type KeyReaderWriter

type KeyReaderWriter interface {
	ReadKey() (ecdsa.PrivateKey, error)
	WriteKey(ecdsa.PrivateKey, error)
}

KeyReaderWriter reads and writes ecdsa keys from/to any format or support.

type SimpleKeyfile

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

SimpleKeyfile implements KeyReaderWriter with unencrypted and unformated files.

func NewSimpleKeyfile

func NewSimpleKeyfile(keyfile string) *SimpleKeyfile

NewSimpleKeyfile instantiates a new SimpleKeyfile with an underlying file

func (*SimpleKeyfile) ReadKey

func (k *SimpleKeyfile) ReadKey() (*ecdsa.PrivateKey, error)

ReadKey implements KeyReaderWriter. It reads from the underlying file which is expected to contain a raw hex dump of the key's D value (big.Int), as produced by WriteKey.

func (*SimpleKeyfile) WriteKey

func (k *SimpleKeyfile) WriteKey(key *ecdsa.PrivateKey) error

WriteKey implements KeyReaderWriter. It writes a raw hex dump of the key's D value (big.Int) to the underlying file.

Jump to

Keyboard shortcuts

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