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
- func BigintToPub(curveName string, x, y *big.Int) *ecdsa.PublicKey
- func CurveName(curve elliptic.Curve) string
- func CurveType(curveName string) elliptic.Curve
- func Ecrecover(hash []byte, sig *SignResult) ([]byte, error)
- func FromECDSA(prvKey *ecdsa.PrivateKey) []byte
- func GenerateKeyWithECDSA(curveName string) (*ecdsa.PrivateKey, error)
- func GetECDSA(curveName string) (crypto.ECDSA, error)
- func HashFunc(curveName string) func() hash.Hash
- func HashMsg(curveName string, msg []byte) []byte
- func HashType(curveName string) crypto.Hash
- func HexToECDSA(curveName, hexKey string) (*ecdsa.PrivateKey, error)
- func LoadECDSA(curveName string, file string) (*ecdsa.PrivateKey, error)
- func MarshalPrvkeyWithECDSA(prv *ecdsa.PrivateKey) ([]byte, error)
- func MarshalPrvkeyWithECDSAX509(prv *ecdsa.PrivateKey) ([]byte, error)
- func MarshalPubkeyWithECDSA(pub *ecdsa.PublicKey) ([]byte, error)
- func MarshalPubkeyWithECDSAX509(pub *ecdsa.PublicKey) ([]byte, error)
- func NonceRFC6979(curve elliptic.Curve, privkey *big.Int, hash []byte, extra []byte, ...) *big.Int
- func PubkeyToAddress(p *ecdsa.PublicKey) types.Address
- func SaveECDSA(file string, key *ecdsa.PrivateKey) error
- func SigToPub(hash []byte, sig *SignResult) (*ecdsa.PublicKey, error)
- func SignRFC6979(key *ecdsa.PrivateKey, hash []byte) ([]byte, error)
- func ToECDSA(curveName string, d []byte) (*ecdsa.PrivateKey, error)
- func ToECDSAUnsafe(curveName string, d []byte) *ecdsa.PrivateKey
- func ToHexWithECDSA(prvKey *ecdsa.PrivateKey) string
- func UnMarshalPrvkeyWithECDSA(curveName string, key []byte) (*ecdsa.PrivateKey, error)
- func UnmarshalPubkeyWithECDSA(curveName string, pub []byte) (*ecdsa.PublicKey, error)
- func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool
- func VerifyRFC6979(pubkey *ecdsa.PublicKey, msg, signature []byte) bool
- func VerifyWithECDSA(signResult *SignResult, dataBytes []byte) bool
- type SignResult
- type SignatureECDSA
Constants ¶
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 ¶
BigintToPub 将big.Int转换为PublicKey
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 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 ¶
MarshalPubkeyWithECDSA marshal ecdsa publicKey to bytes
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 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 ¶
UnmarshalPubkeyWithECDSA converts bytes to a public key.
func ValidateSignatureValues ¶
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 ¶
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 ¶
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.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package gmsm
|
Package gmsm |
Package prime256v1
|
Package prime256v1 |
Package secp256k1
|
Package secp256k1 |