eckey

package
v0.0.0-...-aee6f80 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2016 License: MIT, MIT Imports: 5 Imported by: 9

README

eckey

Serialized secp256k1 Elliptic Curve key pairs

Documentation

Index

Constants

View Source
const (
	// PublicCompressedSize defines the number of bytes used to represent a
	// compressed public key.  This consists of a one byte header and the X
	// coordinate of the uncompressed public key.  Each X coordinate maps to
	// exactly two Y coordinates, the header byte is then used to select the even
	// or odd component.
	CompressedPublicSize = 1 + CoordinateSize

	// HeaderCompressedEven defines the header byte of a compressed public key
	// indicating that the even Y coordinate should be chosen upon decompression.
	HeaderCompressedEven byte = 0x02

	// HeaderCompressedOdd defines the header byte of a compressed public key
	// indicating that the odd Y coordinate should be chosen upon decompression.
	HeaderCompressedOdd byte = 0x03
)
View Source
const (
	// CoordinateSize defines the number of bytes required to store the X or Y
	// coordinate of an secp256k1 point.
	CoordinateSize = 32

	// PublicSize defines the number of bytes used to represent a public key,
	// which consists of an (X, Y) coordinate pair.
	PublicSize = 2 * CoordinateSize
)
View Source
const (
	// EntropySize defines the number of bytes used to generate a secret key.
	EntropySize = 32

	// SecretSize defines the number of bytes used to represent a secret key,
	// which is interpreted as a positive scalar coefficient.
	SecretSize = 32
)

Variables

View Source
var (
	// ErrInvalidPublicLength indicates an attempt to create a public key using an
	// invalid number of bytes.
	ErrInvalidPublicLength = fmt.Errorf("Public key must be %d bytes", PublicSize)

	// ErrInvalidCompressedPublicLength indicates an attempt to create a
	// compressed public key using an invalid number of bytes.
	ErrInvalidCompressedPublicLength = fmt.Errorf("Compressed public key must be %d bytes", CompressedPublicSize)

	// ErrInvalidSecretLength indicates an attempt to create a secret key using an
	// invalid number of bytes.
	ErrInvalidSecretLength = fmt.Errorf("Secret key must be %d bytes", SecretSize)

	// ErrInvalidHeader indicates that the header byte of a compressed public key
	// was neither 0x02 or 0x03.
	ErrInvalidHeader = errors.New("Invalid compressed header byte")

	// ErrPublicKeyNotOnCurve indicates that the public key's (X, Y) coordinates do
	// not lie on the secp256k1 curve.
	ErrPublicKeyNotOnCurve = errors.New("Public key is not on secp256k1 curve")

	// ErrPointAtInfinity indicates either that the secret key is 0 or the (X, Y)
	// coordinates of a public key are nil.
	ErrPointAtInfinity = errors.New("Key pair belongs to the point at infinity")
)

Local reference to the btcec secp256k1 curve

Functions

func GenerateKeyPair

func GenerateKeyPair() (*SecretKey, *PublicKey, error)

GenerateKeyPair creates a random public/private key pair.

func GenerateKeyPairDeterministic

func GenerateKeyPairDeterministic(entropy *Entropy) (*SecretKey, *PublicKey)

GenerateKeyPairDeterministic computes the public/private keypair for the given entropy.

Types

type CompressedPublicKey

type CompressedPublicKey [CompressedPublicSize]byte

CompressedPublicKey is used for storing public keys persistently.

func NewCompressedPublicKey

func NewCompressedPublicKey(b []byte) (*CompressedPublicKey, error)

func (*CompressedPublicKey) Uncompress

func (cpk *CompressedPublicKey) Uncompress() (*PublicKey, error)

Uncompress computes the public key for a given compressed public key.

type Entropy

type Entropy [EntropySize]byte

Entropy is used for seeding deterministic key generation.

type PublicKey

type PublicKey [PublicSize]byte

PublicKey is used to verify signatures.

func Add

func Add(pk1, pk2 *PublicKey) *PublicKey

func NewPublicKey

func NewPublicKey(b []byte) (*PublicKey, error)

func NewPublicKeyCoords

func NewPublicKeyCoords(x, y *big.Int) (*PublicKey, error)

PublicKeyFromCoordinates serializes an (X, Y) coordinate pair into a public key. Returns nil if X or Y are nil.

func (*PublicKey) Compress

func (pk *PublicKey) Compress() *CompressedPublicKey

Compress creates a space efficient representation of a public key to be used for persistent storage.

func (*PublicKey) Coords

func (pk *PublicKey) Coords() (*big.Int, *big.Int)

type SecretKey

type SecretKey [SecretSize]byte

SecretKey is used to sign messages.

func NewSecretKey

func NewSecretKey(b []byte) (*SecretKey, error)

func NewSecretKeyInt

func NewSecretKeyInt(s *big.Int) (*SecretKey, error)

func (*SecretKey) PublicKey

func (sk *SecretKey) PublicKey() *PublicKey

PublicKey computes the public key for a given secret key.

func (*SecretKey) PublicKeyCoords

func (sk *SecretKey) PublicKeyCoords() (*big.Int, *big.Int)

PublicKeyCoords computes the X and Y coordinates of the public key corresponding to the given secret key.

func (*SecretKey) Zero

func (sk *SecretKey) Zero()

Zero clears the array backing a secret key.

Jump to

Keyboard shortcuts

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