secp256k1

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package secp256k1

@author: xwc1125

Package secp256k1

@author: xwc1125

Package secp256k1

@author: xwc1125

Package secp256k1

@author: xwc1125

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressPubkey

func CompressPubkey(pubkey *ecdsa.PublicKey) []byte

CompressPubkey encodes a public key to the 33-byte compressed format.

func DecompressPubkey

func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)

DecompressPubkey parses a public key in the 33-byte compressed format.

func GenerateKey

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

GenerateKey 生成s256的私钥

func MarshalPrivateKey

func MarshalPrivateKey(key *ecdsa.PrivateKey) ([]byte, error)

func MarshalPrivateKeyX509

func MarshalPrivateKeyX509(key *ecdsa.PrivateKey) ([]byte, error)

func MarshalPublicKey

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

func MarshalPublicKeyX509

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

func RecoverPubkey

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

RecoverPubkey returns the uncompressed public key that created the given signature.

func S256

func S256() elliptic.Curve

S256 returns an instance of the secp256k1 curve.

func SigToPub

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

SigToPub returns the public key that created the given signature.

func Sign

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

Sign calculates an ECDSA signature.

This function is susceptible to chosen plaintext attacks that can leak information about the private key that is used for signing. Callers must be aware that the given hash cannot be chosen by an adversery. Common solution is to hash any input before calculating the signature.

The produced signature is in the [R || S || V] format where V is 0 or 1.

func UnmarshalPrivateKey

func UnmarshalPrivateKey(curve elliptic.Curve, data []byte) (*ecdsa.PrivateKey, error)

func UnmarshalPrivateKeyX509

func UnmarshalPrivateKeyX509(curve elliptic.Curve, data []byte) (*ecdsa.PrivateKey, error)

func UnmarshalPublicKey

func UnmarshalPublicKey(curve elliptic.Curve, data []byte) (*ecdsa.PublicKey, error)

func UnmarshalPublicKeyX509

func UnmarshalPublicKeyX509(curve elliptic.Curve, data []byte) (*ecdsa.PublicKey, error)

func Verify

func Verify(pub *ecdsa.PublicKey, hash []byte, signature []byte) bool

func VerifySignature

func VerifySignature(pubkey, hash, signature []byte) bool

VerifySignature checks that the given public key created signature over hash. The public key should be in compressed (33 bytes) or uncompressed (65 bytes) format. The signature should have the 64 byte [R || S] format.

Types

type Secp251k1

type Secp251k1 struct {
}

func (Secp251k1) FromECDSA

func (s Secp251k1) FromECDSA(prv *ecdsa.PrivateKey) crypto.PrivateKey

func (Secp251k1) FromECDSAPubKey

func (s Secp251k1) FromECDSAPubKey(pub *ecdsa.PublicKey) crypto.PublicKey

func (Secp251k1) GenerateKey

func (s Secp251k1) GenerateKey(curve elliptic.Curve) (*ecdsa.PrivateKey, error)

func (Secp251k1) HashFunc

func (s Secp251k1) HashFunc(cryptoName string) func() hash.Hash

func (Secp251k1) HashMsg

func (s Secp251k1) HashMsg(cryptoName string, data []byte) ([]byte, error)

func (Secp251k1) HashType

func (s Secp251k1) HashType(curveName string) crypto.Hash

func (Secp251k1) MarshalPrivateKey

func (s Secp251k1) MarshalPrivateKey(key *ecdsa.PrivateKey) ([]byte, error)

func (Secp251k1) MarshalPrivateKeyX509

func (s Secp251k1) MarshalPrivateKeyX509(key *ecdsa.PrivateKey) ([]byte, error)

func (Secp251k1) MarshalPublicKey

func (s Secp251k1) MarshalPublicKey(pub *ecdsa.PublicKey) ([]byte, error)

func (Secp251k1) MarshalPublicKeyX509

func (s Secp251k1) MarshalPublicKeyX509(pub *ecdsa.PublicKey) ([]byte, error)

func (Secp251k1) Sign

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

func (Secp251k1) ToECDSA

func (s Secp251k1) ToECDSA(prv crypto.PrivateKey) *ecdsa.PrivateKey

func (Secp251k1) ToECDSAPubKey

func (s Secp251k1) ToECDSAPubKey(pub crypto.PublicKey) *ecdsa.PublicKey

func (Secp251k1) UnmarshalPrivateKey

func (s Secp251k1) UnmarshalPrivateKey(curve elliptic.Curve, keyBytes []byte) (*ecdsa.PrivateKey, error)

func (Secp251k1) UnmarshalPrivateKeyX509

func (s Secp251k1) UnmarshalPrivateKeyX509(curve elliptic.Curve, keyBytes []byte) (*ecdsa.PrivateKey, error)

func (Secp251k1) UnmarshalPublicKey

func (s Secp251k1) UnmarshalPublicKey(curve elliptic.Curve, data []byte) (*ecdsa.PublicKey, error)

func (Secp251k1) UnmarshalPublicKeyX509

func (s Secp251k1) UnmarshalPublicKeyX509(curve elliptic.Curve, data []byte) (*ecdsa.PublicKey, error)

func (Secp251k1) Verify

func (s Secp251k1) Verify(pub *ecdsa.PublicKey, hash []byte, signature []byte) bool

Jump to

Keyboard shortcuts

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