Documentation ¶
Index ¶
- Constants
- Variables
- func ASN1Ciphertext2Plain(ciphertext []byte, opts *EncryptorOpts) ([]byte, error)
- func AdjustCiphertextSplicingOrder(ciphertext []byte, from, to ciphertextSplicingOrder) ([]byte, error)
- func CalculateZA(pub *ecdsa.PublicKey, uid []byte) ([]byte, error)
- func Decrypt(priv *PrivateKey, ciphertext []byte) ([]byte, error)
- func Encrypt(random io.Reader, pub *ecdsa.PublicKey, msg []byte, opts *EncryptorOpts) ([]byte, error)
- func EncryptASN1(random io.Reader, pub *ecdsa.PublicKey, msg []byte) ([]byte, error)
- func IsPublicKey(publicKey interface{}) bool
- func MarshalEnvelopedPrivateKey(rand io.Reader, pub *ecdsa.PublicKey, tobeEnveloped *PrivateKey) ([]byte, error)
- func MarshalPublicKey(pub *ecdsa.PublicKey) ([]byte, error)
- func P256() elliptic.Curve
- func PlainCiphertext2ASN1(ciphertext []byte, from ciphertextSplicingOrder) ([]byte, error)
- func PublicKeyToECDH(k *ecdsa.PublicKey) (*ecdh.PublicKey, error)
- func Sign(rand io.Reader, priv *ecdsa.PrivateKey, hash []byte) (r, s *big.Int, err error)
- func SignASN1(rand io.Reader, priv *PrivateKey, hash []byte, opts crypto.SignerOpts) ([]byte, error)
- func SignWithSM2(rand io.Reader, priv *ecdsa.PrivateKey, uid, msg []byte) (r, s *big.Int, err error)
- func UnmarshalPublicKey(der []byte) (key *ecdsa.PublicKey, err error)
- func Verify(pub *ecdsa.PublicKey, hash []byte, r, s *big.Int) bool
- func VerifyASN1(pub *ecdsa.PublicKey, hash, sig []byte) bool
- func VerifyASN1WithSM2(pub *ecdsa.PublicKey, uid, msg, sig []byte) bool
- func VerifyWithSM2(pub *ecdsa.PublicKey, uid, msg []byte, r, s *big.Int) bool
- type DecryptorOpts
- type EncryptorOpts
- type KeyExchange
- func (ke *KeyExchange) ConfirmInitiator(s1 []byte) ([]byte, error)
- func (ke *KeyExchange) ConfirmResponder(rB *ecdsa.PublicKey, sB []byte) ([]byte, []byte, error)
- func (ke *KeyExchange) Destroy()
- func (ke *KeyExchange) Equal(x *KeyExchange) bool
- func (ke *KeyExchange) Init(rand io.Reader) (*ecdsa.PublicKey, error)
- func (ke *KeyExchange) Marshal() (p []byte, err error)
- func (ke *KeyExchange) Respond(rand io.Reader, rA *ecdsa.PublicKey) (*ecdsa.PublicKey, []byte, error)
- func (ke *KeyExchange) SetPeerParameters(peerPub *ecdsa.PublicKey, peerUID []byte) error
- type PrivateKey
- func (pri *PrivateKey) Decrypt(rand io.Reader, msg []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error)
- func (pri *PrivateKey) ECDH() (*ecdh.PrivateKey, error)
- func (pri *PrivateKey) Equal(x crypto.PrivateKey) bool
- func (pri *PrivateKey) FromECPrivateKey(key *ecdsa.PrivateKey) (*PrivateKey, error)
- func (pri *PrivateKey) Marshal() ([]byte, error)
- func (pri *PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)
- func (pri *PrivateKey) SignWithSM2(rand io.Reader, uid, msg []byte) ([]byte, error)
- type Signer
- type SignerOption
Constants ¶
const ( MarshalUncompressed pointMarshalMode = iota MarshalCompressed MarshalHybrid )
const ( C1C3C2 ciphertextSplicingOrder = iota C1C2C3 )
Variables ¶
var ASN1DecryptorOpts = &DecryptorOpts{encodingAsn1, C1C3C2}
var ASN1EncryptorOpts = &EncryptorOpts{encodingAsn1, MarshalUncompressed, C1C3C2}
var DefaultSignerOpts = NewSignerOption(true, nil)
var ErrDecryption = errors.New("sm2: decryption error")
Functions ¶
func ASN1Ciphertext2Plain ¶
func ASN1Ciphertext2Plain(ciphertext []byte, opts *EncryptorOpts) ([]byte, error)
func EncryptASN1 ¶
func IsPublicKey ¶
func IsPublicKey(publicKey interface{}) bool
func PlainCiphertext2ASN1 ¶
func SignASN1 ¶
func SignASN1(rand io.Reader, priv *PrivateKey, hash []byte, opts crypto.SignerOpts) ([]byte, error)
func SignWithSM2 ¶
func UnmarshalPublicKey ¶ added in v1.9.0
Types ¶
type DecryptorOpts ¶
type DecryptorOpts struct {
// contains filtered or unexported fields
}
func NewPlainDecryptorOpts ¶
func NewPlainDecryptorOpts(splicingOrder ciphertextSplicingOrder) *DecryptorOpts
type EncryptorOpts ¶
type EncryptorOpts struct {
// contains filtered or unexported fields
}
func NewPlainEncryptorOpts ¶
func NewPlainEncryptorOpts(marhsalMode pointMarshalMode, splicingOrder ciphertextSplicingOrder) *EncryptorOpts
type KeyExchange ¶
type KeyExchange struct {
// contains filtered or unexported fields
}
KeyExchange Usage: 1. initiator create key exchanging 1.1. initiator, err := sm2.NewKeyExchange(initiatorPRI, responderPUB, initiatorUID, responderUID, kenLen, true) 2.1. rA, rAErr := initiator.Init(rand.Reader) 2.3. send rA to responder 2. responder create key exchanging 2.1. responder, err := sm2.NewKeyExchange(responderPRI, initiatorPUB, responderUID, initiatorUID, kenLen, true) 2.2. rB, s2, rBErr := responder.Respond(rand.Reader, rA) 2.3. send rB and s2 to initiator 3. initiator confirm 3.1 ss, s1, err := initiator.ConfirmResponder(rB, s2) 3.2 initiator.Destroy() 3.3 send s1 to responder 4. responder confirm 4.1 ss, err := responder.ConfirmInitiator(s1) 4.2 responder.Destroy()
func NewKeyExchange ¶
func NewKeyExchange(priv *PrivateKey, peerPub *ecdsa.PublicKey, uid, peerUID []byte, keyLen int, genSignature bool) (ke *KeyExchange, err error)
func UnmarshalKeyExchange ¶ added in v1.9.0
func UnmarshalKeyExchange(p []byte) (ke *KeyExchange, err error)
func (*KeyExchange) ConfirmInitiator ¶
func (ke *KeyExchange) ConfirmInitiator(s1 []byte) ([]byte, error)
func (*KeyExchange) ConfirmResponder ¶
func (*KeyExchange) Destroy ¶
func (ke *KeyExchange) Destroy()
func (*KeyExchange) Equal ¶ added in v1.9.0
func (ke *KeyExchange) Equal(x *KeyExchange) bool
func (*KeyExchange) Marshal ¶ added in v1.9.0
func (ke *KeyExchange) Marshal() (p []byte, err error)
func (*KeyExchange) SetPeerParameters ¶
func (ke *KeyExchange) SetPeerParameters(peerPub *ecdsa.PublicKey, peerUID []byte) error
type PrivateKey ¶
type PrivateKey struct {
ecdsa.PrivateKey
}
func GenerateKey ¶
func GenerateKey(rand io.Reader) (*PrivateKey, error)
func ParseEnvelopedPrivateKey ¶
func ParseEnvelopedPrivateKey(priv *PrivateKey, enveloped []byte) (*PrivateKey, error)
func UnmarshalPrivateKey ¶ added in v1.9.0
func UnmarshalPrivateKey(der []byte) (key *PrivateKey, err error)
func (*PrivateKey) Decrypt ¶
func (pri *PrivateKey) Decrypt(rand io.Reader, msg []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error)
func (*PrivateKey) ECDH ¶
func (pri *PrivateKey) ECDH() (*ecdh.PrivateKey, error)
func (*PrivateKey) Equal ¶
func (pri *PrivateKey) Equal(x crypto.PrivateKey) bool
func (*PrivateKey) FromECPrivateKey ¶
func (pri *PrivateKey) FromECPrivateKey(key *ecdsa.PrivateKey) (*PrivateKey, error)
func (*PrivateKey) Marshal ¶ added in v1.9.0
func (pri *PrivateKey) Marshal() ([]byte, error)
func (*PrivateKey) Sign ¶
func (pri *PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)
func (*PrivateKey) SignWithSM2 ¶
SignWithSM2 signs uid, msg with priv, reading randomness from rand. Compliance with GB/T 32918.2-2016. Deprecated: please use Sign method directly.
type SignerOption ¶
type SignerOption struct {
// contains filtered or unexported fields
}
func NewSignerOption ¶
func NewSignerOption(forceGMSign bool, uid []byte) *SignerOption
func (*SignerOption) HashFunc ¶
func (*SignerOption) HashFunc() crypto.Hash