Documentation
¶
Overview ¶
Package secp256k1
@author: xwc1125
Package secp256k1 ¶
@author: xwc1125
Package secp256k1 ¶
@author: xwc1125
Package secp256k1 ¶
@author: xwc1125
Index ¶
- func CompressPubkey(pubkey *ecdsa.PublicKey) []byte
- func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error)
- func GenerateKey() (*ecdsa.PrivateKey, error)
- func MarshalPrivateKey(key *ecdsa.PrivateKey) ([]byte, error)
- func MarshalPrivateKeyX509(key *ecdsa.PrivateKey) ([]byte, error)
- func MarshalPublicKey(pub *ecdsa.PublicKey) ([]byte, error)
- func MarshalPublicKeyX509(pub *ecdsa.PublicKey) ([]byte, error)
- func RecoverPubkey(hash, sig []byte) ([]byte, error)
- func S256() elliptic.Curve
- func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error)
- func Sign(prv *ecdsa.PrivateKey, hash []byte) ([]byte, error)
- func UnmarshalPrivateKey(curve elliptic.Curve, data []byte) (*ecdsa.PrivateKey, error)
- func UnmarshalPrivateKeyX509(curve elliptic.Curve, data []byte) (*ecdsa.PrivateKey, error)
- func UnmarshalPublicKey(curve elliptic.Curve, data []byte) (*ecdsa.PublicKey, error)
- func UnmarshalPublicKeyX509(curve elliptic.Curve, data []byte) (*ecdsa.PublicKey, error)
- func Verify(pub *ecdsa.PublicKey, hash []byte, signature []byte) bool
- func VerifySignature(pubkey, hash, signature []byte) bool
- type Secp251k1
- func (s Secp251k1) FromECDSA(prv *ecdsa.PrivateKey) crypto.PrivateKey
- func (s Secp251k1) FromECDSAPubKey(pub *ecdsa.PublicKey) crypto.PublicKey
- func (s Secp251k1) GenerateKey(curve elliptic.Curve) (*ecdsa.PrivateKey, error)
- func (s Secp251k1) HashFunc(cryptoName string) func() hash.Hash
- func (s Secp251k1) HashMsg(cryptoName string, data []byte) ([]byte, error)
- func (s Secp251k1) HashType(curveName string) crypto.Hash
- func (s Secp251k1) MarshalPrivateKey(key *ecdsa.PrivateKey) ([]byte, error)
- func (s Secp251k1) MarshalPrivateKeyX509(key *ecdsa.PrivateKey) ([]byte, error)
- func (s Secp251k1) MarshalPublicKey(pub *ecdsa.PublicKey) ([]byte, error)
- func (s Secp251k1) MarshalPublicKeyX509(pub *ecdsa.PublicKey) ([]byte, error)
- func (s Secp251k1) Sign(prv *ecdsa.PrivateKey, hash []byte) (sig []byte, err error)
- func (s Secp251k1) ToECDSA(prv crypto.PrivateKey) *ecdsa.PrivateKey
- func (s Secp251k1) ToECDSAPubKey(pub crypto.PublicKey) *ecdsa.PublicKey
- func (s Secp251k1) UnmarshalPrivateKey(curve elliptic.Curve, keyBytes []byte) (*ecdsa.PrivateKey, error)
- func (s Secp251k1) UnmarshalPrivateKeyX509(curve elliptic.Curve, keyBytes []byte) (*ecdsa.PrivateKey, error)
- func (s Secp251k1) UnmarshalPublicKey(curve elliptic.Curve, data []byte) (*ecdsa.PublicKey, error)
- func (s Secp251k1) UnmarshalPublicKeyX509(curve elliptic.Curve, data []byte) (*ecdsa.PublicKey, error)
- func (s Secp251k1) Verify(pub *ecdsa.PublicKey, hash []byte, signature []byte) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompressPubkey ¶
CompressPubkey encodes a public key to the 33-byte compressed format.
func DecompressPubkey ¶
DecompressPubkey parses a public key in the 33-byte compressed format.
func MarshalPrivateKey ¶
func MarshalPrivateKey(key *ecdsa.PrivateKey) ([]byte, error)
func MarshalPrivateKeyX509 ¶
func MarshalPrivateKeyX509(key *ecdsa.PrivateKey) ([]byte, error)
func RecoverPubkey ¶
RecoverPubkey returns the uncompressed 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 UnmarshalPrivateKeyX509 ¶
func UnmarshalPublicKey ¶
func UnmarshalPublicKeyX509 ¶
func VerifySignature ¶
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 (Secp251k1) GenerateKey ¶
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 (Secp251k1) MarshalPublicKeyX509 ¶
func (Secp251k1) ToECDSA ¶
func (s Secp251k1) ToECDSA(prv crypto.PrivateKey) *ecdsa.PrivateKey