sm2

package
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 31 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MarshalUncompressed pointMarshalMode = iota
	MarshalCompressed
	MarshalHybrid
)
View Source
const (
	C1C3C2 ciphertextSplicingOrder = iota
	C1C2C3
)

Variables

View Source
var ASN1DecryptorOpts = &DecryptorOpts{encodingAsn1, C1C3C2}
View Source
var ASN1EncryptorOpts = &EncryptorOpts{encodingAsn1, MarshalUncompressed, C1C3C2}
View Source
var DefaultSignerOpts = NewSignerOption(true, nil)
View Source
var ErrDecryption = errors.New("sm2: decryption error")

Functions

func ASN1Ciphertext2Plain

func ASN1Ciphertext2Plain(ciphertext []byte, opts *EncryptorOpts) ([]byte, error)

func AdjustCiphertextSplicingOrder

func AdjustCiphertextSplicingOrder(ciphertext []byte, from, to ciphertextSplicingOrder) ([]byte, error)

func CalculateZA

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

func Decrypt

func Decrypt(priv *PrivateKey, ciphertext []byte) ([]byte, error)

func Encrypt

func Encrypt(random io.Reader, pub *ecdsa.PublicKey, msg []byte, opts *EncryptorOpts) ([]byte, error)

func EncryptASN1

func EncryptASN1(random io.Reader, pub *ecdsa.PublicKey, msg []byte) ([]byte, error)

func IsPublicKey

func IsPublicKey(publicKey interface{}) bool

func MarshalEnvelopedPrivateKey

func MarshalEnvelopedPrivateKey(rand io.Reader, pub *ecdsa.PublicKey, tobeEnveloped *PrivateKey) ([]byte, error)

func MarshalPublicKey added in v1.9.0

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

func P256

func P256() elliptic.Curve

func PlainCiphertext2ASN1

func PlainCiphertext2ASN1(ciphertext []byte, from ciphertextSplicingOrder) ([]byte, error)

func PublicKeyToECDH

func PublicKeyToECDH(k *ecdsa.PublicKey) (*ecdh.PublicKey, error)

func Sign

func Sign(rand io.Reader, priv *ecdsa.PrivateKey, hash []byte) (r, s *big.Int, err error)

func SignASN1

func SignASN1(rand io.Reader, priv *PrivateKey, hash []byte, opts crypto.SignerOpts) ([]byte, error)

func SignWithSM2

func SignWithSM2(rand io.Reader, priv *ecdsa.PrivateKey, uid, msg []byte) (r, s *big.Int, err error)

func UnmarshalPublicKey added in v1.9.0

func UnmarshalPublicKey(der []byte) (key *ecdsa.PublicKey, err error)

func Verify

func Verify(pub *ecdsa.PublicKey, hash []byte, r, s *big.Int) bool

func VerifyASN1

func VerifyASN1(pub *ecdsa.PublicKey, hash, sig []byte) bool

func VerifyASN1WithSM2

func VerifyASN1WithSM2(pub *ecdsa.PublicKey, uid, msg, sig []byte) bool

func VerifyWithSM2

func VerifyWithSM2(pub *ecdsa.PublicKey, uid, msg []byte, r, s *big.Int) bool

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 (ke *KeyExchange) ConfirmResponder(rB *ecdsa.PublicKey, sB []byte) ([]byte, []byte, error)

func (*KeyExchange) Destroy

func (ke *KeyExchange) Destroy()

func (*KeyExchange) Equal added in v1.9.0

func (ke *KeyExchange) Equal(x *KeyExchange) bool

func (*KeyExchange) Init

func (ke *KeyExchange) Init(rand io.Reader) (*ecdsa.PublicKey, error)

func (*KeyExchange) Marshal added in v1.9.0

func (ke *KeyExchange) Marshal() (p []byte, err error)

func (*KeyExchange) Respond

func (ke *KeyExchange) Respond(rand io.Reader, rA *ecdsa.PublicKey) (*ecdsa.PublicKey, []byte, 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

func (pri *PrivateKey) SignWithSM2(rand io.Reader, uid, msg []byte) ([]byte, error)

SignWithSM2 signs uid, msg with priv, reading randomness from rand. Compliance with GB/T 32918.2-2016. Deprecated: please use Sign method directly.

type Signer

type Signer interface {
	SignWithSM2(rand io.Reader, uid, msg []byte) ([]byte, error)
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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