sm2

package
v1.0.2041 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: Apache-2.0 Imports: 15 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASN1Marshal

func ASN1Marshal(data []byte) ([]byte, error)

sm2 密文转 asn.1 编码格式 sm2 密文结构: x + y + hash + CipherText

func ASN1MarshalC1C2C3

func ASN1MarshalC1C2C3(data []byte) ([]byte, error)

sm2 密文转 asn.1 编码格式 sm2 密文结构: x + y + hash + CipherText

func ASN1Unmarshal

func ASN1Unmarshal(b []byte) ([]byte, error)

sm2 密文 asn.1 编码格式转 C1|C3|C2 拼接格式

func ASN1UnmarshalC1C2C3

func ASN1UnmarshalC1C2C3(b []byte) ([]byte, error)

sm2 密文 asn.1 编码格式转 C1|C2|C3 拼接格式

func BytesCombine

func BytesCombine(pBytes ...[]byte) []byte

func Compress

func Compress(a *PublicKey) []byte

func Decrypt

func Decrypt(priv *PrivateKey, data []byte, mode Mode) ([]byte, error)

func DecryptAsn1

func DecryptAsn1(pub *PrivateKey, data []byte, mode Mode) ([]byte, error)

sm2解密,解析asn.1编码格式的密文内容

func Encrypt

func Encrypt(random io.Reader, pub *PublicKey, data []byte, mode Mode) ([]byte, error)

sm2 密文结构: x + y + hash + CipherText

func EncryptAsn1

func EncryptAsn1(rand io.Reader, pub *PublicKey, data []byte, mode Mode) ([]byte, error)

sm2 加密,返回 asn.1 编码格式的密文内容

func KeyExchangeA

func KeyExchangeA(klen int, ida, idb []byte, priA *PrivateKey, pubB *PublicKey, rpri *PrivateKey, rpubB *PublicKey) (k, s1, s2 []byte, err error)

KeyExchangeA 协商第二部,用户A调用,返回共享密钥k

func KeyExchangeB

func KeyExchangeB(klen int, ida, idb []byte, priB *PrivateKey, pubA *PublicKey, rpri *PrivateKey, rpubA *PublicKey) (k, s1, s2 []byte, err error)

KeyExchangeB 协商第二部,用户B调用, 返回共享密钥k

func MarshalPrivateKey

func MarshalPrivateKey(key *PrivateKey) ([]byte, error)

func MarshalPublicKey

func MarshalPublicKey(key *PublicKey) ([]byte, error)

func MarshalSM2PrivateKey

func MarshalSM2PrivateKey(key *PrivateKey) ([]byte, error)

MarshalSM2PrivateKey converts an SM2 private key to SEC 1, ASN.1 DER form.

This kind of key is commonly encoded in PEM blocks of type "SM2 PRIVATE KEY". For a more flexible key format which is not SM2 specific, use MarshalPKCS8PrivateKey.

func P256Sm2

func P256Sm2() elliptic.Curve

func Sign

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

func SignDataToSignDigit

func SignDataToSignDigit(sign []byte) (*big.Int, *big.Int, error)

func SignDigitToSignData

func SignDigitToSignData(r, s *big.Int) ([]byte, error)

func SignWithSM2

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

func ToPrivateKey

func ToPrivateKey(key *PrivateKey) []byte

输出私钥明文

func ToPublicKey

func ToPublicKey(key *PublicKey) []byte

输出公钥明文

func Verify

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

func VerifyWithSM2

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

func WNafReversed

func WNafReversed(wnaf []int8) []int8

func ZA

func ZA(pub *PublicKey, uid []byte) ([]byte, error)

ZA = H256(ENTLA || IDA || a || b || xG || yG || xA || yA)

Types

type EncrypterOpts

type EncrypterOpts struct {
	Mode Mode
}

type Mode

type Mode uint

模式

const (
	C1C3C2 Mode = 0 + iota
	C1C2C3
)

type PrivateKey

type PrivateKey struct {
	PublicKey
	D *big.Int
}

func GenerateKey

func GenerateKey(random io.Reader) (*PrivateKey, error)

func NewPrivateKey

func NewPrivateKey(d []byte) (*PrivateKey, error)

根据私钥明文初始化私钥

func ParsePrivateKey

func ParsePrivateKey(der []byte) (*PrivateKey, error)

func ParseSM2PrivateKey

func ParseSM2PrivateKey(der []byte) (*PrivateKey, error)

ParseSM2PrivateKey parses an SM2 private key in SEC 1, ASN.1 DER form.

This kind of key is commonly encoded in PEM blocks of type "SM2 PRIVATE KEY".

func (*PrivateKey) Decrypt

func (priv *PrivateKey) Decrypt(_ io.Reader, msg []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error)

crypto.Decrypter

func (*PrivateKey) DecryptAsn1

func (priv *PrivateKey) DecryptAsn1(data []byte, opts crypto.DecrypterOpts) ([]byte, error)

func (*PrivateKey) Equal

func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool

Equal reports whether priv and x have the same value.

func (*PrivateKey) Public

func (priv *PrivateKey) Public() crypto.PublicKey

The SM2's private key contains the public key

func (*PrivateKey) Sign

func (priv *PrivateKey) Sign(random io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)

sign format = 30 + len(z) + 02 + len(r) + r + 02 + len(s) + s, z being what follows its size, ie 02+len(r)+r+02+len(s)+s

func (*PrivateKey) SignBytes

func (priv *PrivateKey) SignBytes(random io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)

type PublicKey

type PublicKey struct {
	elliptic.Curve
	X, Y *big.Int
}

func Decompress

func Decompress(a []byte) *PublicKey

func NewPublicKey

func NewPublicKey(q []byte) (*PublicKey, error)

根据公钥明文初始化公钥

func ParsePublicKey

func ParsePublicKey(der []byte) (*PublicKey, error)

func (*PublicKey) Encrypt

func (pub *PublicKey) Encrypt(random io.Reader, data []byte, opts crypto.DecrypterOpts) ([]byte, error)

func (*PublicKey) EncryptAsn1

func (pub *PublicKey) EncryptAsn1(random io.Reader, data []byte, opts crypto.DecrypterOpts) ([]byte, error)

func (*PublicKey) Equal

func (pub *PublicKey) Equal(x crypto.PublicKey) bool

func (*PublicKey) Verify

func (pub *PublicKey) Verify(msg []byte, sign []byte, opts crypto.SignerOpts) bool

func (*PublicKey) VerifyBytes

func (pub *PublicKey) VerifyBytes(msg []byte, sign []byte, opts crypto.SignerOpts) bool

type SignerOpts

type SignerOpts struct {
	Uid []byte
}

func (SignerOpts) HashFunc

func (opt SignerOpts) HashFunc() crypto.Hash

Jump to

Keyboard shortcuts

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