signature

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: 26 Imported by: 11

Documentation

Overview

Package signature

@author: xwc1125

Package signature

@author: xwc1125

Package signature

@author: xwc1125

Package signature

@author: xwc1125

Package signature

@author: xwc1125

Package signature

@author: xwc1125

Package signature

@author: xwc1125

Index

Constants

View Source
const (
	P256    = "P-256"
	P384    = "P-384"
	P521    = "P-521"
	S256    = "S-256"
	SM2P256 = "SM2-P-256"
)

Variables

This section is empty.

Functions

func BigintToPub

func BigintToPub(curveName string, x, y *big.Int) *ecdsa.PublicKey

BigintToPub 将big.Int转换为PublicKey

func CurveName

func CurveName(curve elliptic.Curve) string

func CurveType

func CurveType(curveName string) elliptic.Curve

func Ecrecover

func Ecrecover(hash []byte, sig *SignResult) ([]byte, error)

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

func FromECDSA

func FromECDSA(prvKey *ecdsa.PrivateKey) []byte

FromECDSA exports a private key into a binary dump.

func GenerateKeyWithECDSA

func GenerateKeyWithECDSA(curveName string) (*ecdsa.PrivateKey, error)

GenerateKeyWithECDSA generate the ecdsa key

func GetECDSA

func GetECDSA(curveName string) (crypto.ECDSA, error)

func HashFunc

func HashFunc(curveName string) func() hash.Hash

HashFunc get hash.Hash

func HashMsg

func HashMsg(curveName string, msg []byte) []byte

HashMsg hash data

func HashType

func HashType(curveName string) crypto.Hash

HashType hash type

func HexToECDSA

func HexToECDSA(curveName, hexKey string) (*ecdsa.PrivateKey, error)

HexToECDSA parses a private key.

func LoadECDSA

func LoadECDSA(curveName string, file string) (*ecdsa.PrivateKey, error)

LoadECDSA loads a private key from the given file.

func MarshalPrvkeyWithECDSA

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

func MarshalPrvkeyWithECDSAX509

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

func MarshalPubkeyWithECDSA

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

MarshalPubkeyWithECDSA marshal ecdsa publicKey to bytes

func MarshalPubkeyWithECDSAX509

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

func NonceRFC6979

func NonceRFC6979(curve elliptic.Curve, privkey *big.Int, hash []byte, extra []byte, version []byte) *big.Int

NonceRFC6979 generates an ECDSA nonce (`k`) deterministically according to RFC 6979. It takes a 32-byte hash as an input and returns 32-byte nonce to be used in ECDSA algorithm.

func PubkeyToAddress

func PubkeyToAddress(p *ecdsa.PublicKey) types.Address

func SaveECDSA

func SaveECDSA(file string, key *ecdsa.PrivateKey) error

SaveECDSA saves a private key to the given file with restrictive permissions. The key data is saved hex-encoded.

func SigToPub

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

SigToPub returns the public key that created the given signature.

func SignRFC6979

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

SignRFC6979 produces a compact signature of the data in hash with the given private key on the given koblitz curve. The isCompressed parameter should be used to detail if the given signature should reference a compressed public key or not. If successful the bytes of the compact signature will be returned in the format: <(byte of 27+public key solution)+4 if compressed >< padded bytes for signature R><padded bytes for signature S> where the R and S parameters are padde up to the bitlengh of the curve.

func ToECDSA

func ToECDSA(curveName string, d []byte) (*ecdsa.PrivateKey, error)

ToECDSA creates a private key with the given D value.

func ToECDSAUnsafe

func ToECDSAUnsafe(curveName string, d []byte) *ecdsa.PrivateKey

ToECDSAUnsafe blindly converts a binary blob to a private key. It should almost never be used unless you are sure the input is valid and want to avoid hitting errors due to bad origin encoding (0 prefixes cut off).

func ToHexWithECDSA

func ToHexWithECDSA(prvKey *ecdsa.PrivateKey) string

ToHexWithECDSA convert ecdsa privateKey to hex

func UnMarshalPrvkeyWithECDSA

func UnMarshalPrvkeyWithECDSA(curveName string, key []byte) (*ecdsa.PrivateKey, error)

func UnmarshalPubkeyWithECDSA

func UnmarshalPubkeyWithECDSA(curveName string, pub []byte) (*ecdsa.PublicKey, error)

UnmarshalPubkeyWithECDSA converts bytes to a public key.

func ValidateSignatureValues

func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool

ValidateSignatureValues verifies whether the signature values are valid with the given chain rules. The v value is assumed to be either 0 or 1.

func VerifyRFC6979

func VerifyRFC6979(pubkey *ecdsa.PublicKey, msg, signature []byte) bool

VerifyRFC6979 验证签名

func VerifyWithECDSA

func VerifyWithECDSA(signResult *SignResult, dataBytes []byte) bool

VerifyWithECDSA verify the signature by signResult and dataBytes

Types

type SignResult

type SignResult struct {
	Name      string        `json:"name" mapstructure:"name"`           // 算法名称
	PubKey    hexutil.Bytes `json:"pub_key" mapstructure:"pub_key"`     // 公钥
	Signature hexutil.Bytes `json:"signature" mapstructure:"signature"` // 签名结果
}

SignResult 签名结果

func SignWithECDSA

func SignWithECDSA(prvKey *ecdsa.PrivateKey, dataBytes []byte) (*SignResult, error)

SignWithECDSA use ecdsa sign the raw data bytes

func (*SignResult) Copy

func (s *SignResult) Copy() *SignResult

func (*SignResult) Deserialize

func (s *SignResult) Deserialize(data []byte) error

Deserialize 反解码

func (*SignResult) Serialize

func (s *SignResult) Serialize() ([]byte, error)

Serialize 获取signResult的bytes

type SignatureECDSA

type SignatureECDSA struct {
	R *big.Int
	S *big.Int
	// contains filtered or unexported fields
}

SignatureECDSA is a type representing an ecdsa signature.

func NewSignature

func NewSignature(curve elliptic.Curve, r, s *big.Int) *SignatureECDSA

NewSignature instantiates a new signature given some R,S values.

func (*SignatureECDSA) GetR

func (sig *SignatureECDSA) GetR() *big.Int

GetR satisfies the chainec PublicKey interface.

func (*SignatureECDSA) GetS

func (sig *SignatureECDSA) GetS() *big.Int

GetS satisfies the chainec PublicKey interface.

func (*SignatureECDSA) Verify

func (sig *SignatureECDSA) Verify(hash []byte, pubKey *ecdsa.PublicKey) bool

Directories

Path Synopsis
Package gmsm
Package gmsm
Package prime256v1
Package prime256v1
Package secp256k1
Package secp256k1

Jump to

Keyboard shortcuts

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