secp256k1

package module
v0.0.0-...-ebd5122 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 1 Imported by: 0

README

secp256k1

secp256k1 in Go

This library uses a pure Go implementation with CGO_ENABLED=0, but also uses libsecp256k1 and platform specific code when CGO_ENABLED=0 is not set, delivering better performance when CGO is enabled but keeping portability and Go cross compilation to all supported targets when CGO is not allowed.

There are some platform specific optimizations for amd64 and arm64 which can be disabled by compiling with the tag forceportable.

Benchmark against other libraries available here.

Acknowledgments

Code from the following libraries is used here:

  • secp256k1: C implementation of secp256k1.
  • dcrec: Pure Go secp256k1 implementation.
  • btcec: Schnorr signature implementation in Go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SchnorrKeyPairFromBytes32

func SchnorrKeyPairFromBytes32(priv *PrivateKey, pub *PublicKey,
	data []byte) error

SchnorrKeyPairFromBytes32 initializes priv and pub with a 32 byte private key.

The public key Y will always be even.

Types

type ECDSASignature

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

func (*ECDSASignature) FromBytes64

func (s *ECDSASignature) FromBytes64(data []byte) error

FromBytes64 initializes from R and S, 32 bytes each.

func (*ECDSASignature) FromDER

func (s *ECDSASignature) FromDER(data []byte, lax bool) error

FromBytes64 initializes from DER. If lax is false, strict canonical DER is enforced.

func (*ECDSASignature) Sign

func (s *ECDSASignature) Sign(priv *PrivateKey, hash []byte) error

func (*ECDSASignature) ToBytes64

func (s *ECDSASignature) ToBytes64(data []byte) []byte

ToBytes64 writes R and S into the buffer and returns it.

func (*ECDSASignature) ToDER72

func (s *ECDSASignature) ToDER72(data []byte) []byte

ToBytes64 writes R and S into the buffer and returns it.

func (*ECDSASignature) Verify

func (s *ECDSASignature) Verify(pub *PublicKey, hash []byte) bool

type PrivateKey

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

func (*PrivateKey) FromBytes32

func (p *PrivateKey) FromBytes32(data []byte) error

func (*PrivateKey) ToBytes32

func (p *PrivateKey) ToBytes32(data []byte) []byte

ToBytes32 serializes the private key into the passed 32 byte buffer and returns it.

type PublicKey

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

func (*PublicKey) FromBytes32

func (p *PublicKey) FromBytes32(data []byte) error

FromBytes32 initializes from even public key.

func (*PublicKey) FromBytes33

func (p *PublicKey) FromBytes33(data []byte) error

FromBytes33 initializes from compressed public key.

func (*PublicKey) FromBytes64

func (p *PublicKey) FromBytes64(data []byte) error

FromBytes64 initializes from a full public key, containing X and Y, 32 bytes each.

func (*PublicKey) FromPrivateKey

func (p *PublicKey) FromPrivateKey(priv *PrivateKey) error

func (*PublicKey) ToBytes32

func (p *PublicKey) ToBytes32(data []byte) []byte

ToBytes32 writes the X coordinate into the passed buffer and returns it.

func (*PublicKey) ToBytes33

func (p *PublicKey) ToBytes33(data []byte) []byte

ToBytes32 writes the compressed public key into the passed buffer and returns it.

func (*PublicKey) ToBytes64

func (p *PublicKey) ToBytes64(data []byte) []byte

ToBytes32 writes the X and Y coordinates into the passed buffer and returns it.

type SchnorrSignature

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

func (*SchnorrSignature) FromBytes64

func (s *SchnorrSignature) FromBytes64(data []byte) error

FromBytes64 initializes s with R and S from the data buffer.

func (*SchnorrSignature) Sign

func (s *SchnorrSignature) Sign(priv *PrivateKey, msg []byte) error

func (*SchnorrSignature) SignExt

func (s *SchnorrSignature) SignExt(priv *PrivateKey, msg []byte,
	auxRand *[32]byte, fastSign bool) error

SignExt signs msg with priv, using auxRand as additional entropy to generate the nonce.

auxRand being nil is the same as passing a pointer to a zeroed 32 byte array.

fastSign tells the procedure to avoid some verifications, which may cause speed up depending of the underlying implementation.

func (*SchnorrSignature) ToBytes64

func (s *SchnorrSignature) ToBytes64(data []byte) []byte

ToBytes64 writes R and S into the data buffer, returning it.

func (*SchnorrSignature) Verify

func (s *SchnorrSignature) Verify(pub *PublicKey, msg []byte) bool

Directories

Path Synopsis
internal
dcrsecp
Package secp256k1 implements optimized secp256k1 elliptic curve operations in pure Go.
Package secp256k1 implements optimized secp256k1 elliptic curve operations in pure Go.
dcrsecp/ecdsa
Package ecdsa provides secp256k1-optimized ECDSA signing and verification.
Package ecdsa provides secp256k1-optimized ECDSA signing and verification.
der

Jump to

Keyboard shortcuts

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