Documentation
¶
Overview ¶
Package sm2 exposes an SM2 implementation backed by github.com/emmansun/gmsm.
Index ¶
- Constants
- Variables
- func New(opts *SignerOpts) (*sm2Crpt, error)
- func NewWithCryptoSignerOpts(opts crpt.SignerOpts) (*sm2Crpt, error)
- type Address
- type PrivateKey
- func (priv PrivateKey) Bytes() []byte
- func (priv PrivateKey) Equal(o crpt.PrivateKey) bool
- func (priv PrivateKey) Public() crpt.PublicKey
- func (priv PrivateKey) SignDigest(digest []byte, rand io.Reader, opts crpt.SignerOpts) (crpt.Signature, error)
- func (priv PrivateKey) SignMessage(message []byte, rand io.Reader, opts crpt.SignerOpts) (crpt.Signature, error)
- type PublicKey
- func (pub PublicKey) Address() Address
- func (pub PublicKey) Bytes() []byte
- func (pub PublicKey) Equal(o crpt.PublicKey) bool
- func (pub PublicKey) VerifyDigest(digest []byte, sig crpt.Signature, opts crpt.SignerOpts) (bool, error)
- func (pub PublicKey) VerifyMessage(message []byte, sig crpt.Signature, opts crpt.SignerOpts) (bool, error)
- type SignerOpts
Constants ¶
View Source
const ( KeyType = crpt.SM2 PublicKeySize = 65 // 0x04 || X || Y (32 bytes each) PrivateKeySize = 32 AddressSize = PublicKeySize )
Variables ¶
View Source
var ( KeyTypeByte = byte(KeyType) ErrWrongPublicKeySize = fmt.Errorf("%w, should be %d bytes", crpt.ErrWrongPublicKeySize, PublicKeySize) ErrWrongPrivateKeySize = fmt.Errorf("%w, should be %d bytes", crpt.ErrWrongPrivateKeySize, PrivateKeySize) ErrInvalidSignature = errors.New("sm2: invalid signature encoding") DefaultSignerOpts = NewSignerOpts(true, nil, crpt.SM3) )
Functions ¶
func New ¶
func New(opts *SignerOpts) (*sm2Crpt, error)
New creates an SM2 Crpt with the provided default signer options.
func NewWithCryptoSignerOpts ¶
func NewWithCryptoSignerOpts(opts crpt.SignerOpts) (*sm2Crpt, error)
NewWithCryptoSignerOpts creates an SM2 Crpt from generic crypto.SignerOpts.
Types ¶
type PrivateKey ¶
type PrivateKey struct {
*crpt.BasePrivateKey
// contains filtered or unexported fields
}
PrivateKey wraps the gmsm private key implementation.
func NewPrivateKey ¶
func NewPrivateKey(b []byte, opts crpt.SignerOpts) (*PrivateKey, error)
NewPrivateKey constructs a PrivateKey from raw scalar bytes.
func (PrivateKey) Bytes ¶
func (priv PrivateKey) Bytes() []byte
func (PrivateKey) Equal ¶
func (priv PrivateKey) Equal(o crpt.PrivateKey) bool
func (PrivateKey) Public ¶
func (priv PrivateKey) Public() crpt.PublicKey
func (PrivateKey) SignDigest ¶
func (priv PrivateKey) SignDigest(digest []byte, rand io.Reader, opts crpt.SignerOpts, ) (crpt.Signature, error)
func (PrivateKey) SignMessage ¶
func (priv PrivateKey) SignMessage(message []byte, rand io.Reader, opts crpt.SignerOpts, ) (crpt.Signature, error)
type PublicKey ¶
type PublicKey struct {
*crpt.BasePublicKey
// contains filtered or unexported fields
}
PublicKey wraps an uncompressed SM2 public key.
func NewPublicKey ¶
func NewPublicKey(b []byte, opts crpt.SignerOpts) (*PublicKey, error)
NewPublicKey constructs a PublicKey from its uncompressed bytes.
func (PublicKey) VerifyDigest ¶
func (PublicKey) VerifyMessage ¶
type SignerOpts ¶
type SignerOpts struct {
*gsm2.SM2SignerOption
// contains filtered or unexported fields
}
SignerOpts controls how SM2 operations are performed.
func NewSignerOpts ¶
func NewSignerOpts(forceGMSign bool, uid []byte, hash crpt.Hash) *SignerOpts
func (*SignerOpts) Clone ¶
func (o *SignerOpts) Clone() crpt.SignerOptsExtended
Clone creates a copy of the SignerOpts.
func (*SignerOpts) HashFunc ¶
func (o *SignerOpts) HashFunc() crpt.Hash
HashFunc implements crypto.SignerOpts.
func (*SignerOpts) SetHash ¶
func (o *SignerOpts) SetHash(hash crpt.Hash)
SetHash sets the hash function for the SignerOpts.
Click to show internal directories.
Click to hide internal directories.