sm2

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2020 License: GPL-3.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	BitSize    = 256
	KeyBytes   = (BitSize + 7) / 8
	UnCompress = 0x04
)

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(priv *PrivateKey, in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)

func Encrypt

func Encrypt(pub *PublicKey, in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)

func GenerateKey

func GenerateKey(rand io.Reader) (*PrivateKey, *PublicKey, error)

func MarshalCipher

func MarshalCipher(in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)

func MarshalSign

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

func Sign

func Sign(priv *PrivateKey, userId []byte, in []byte) ([]byte, error)

签名结果为DER编码的字节数组

func SignToRS

func SignToRS(priv *PrivateKey, userId []byte, in []byte) (r, s *big.Int, err error)

func ToECDSAPublickey

func ToECDSAPublickey(key *PublicKey) *ecdsa.PublicKey

func UnmarshalCipher

func UnmarshalCipher(in []byte, cipherTextType Sm2CipherTextType) (out []byte, err error)

func UnmarshalSign

func UnmarshalSign(sign []byte) (r, s *big.Int, err error)

func Verify

func Verify(pub *PublicKey, userId []byte, src []byte, sign []byte) bool

输入签名须为DER编码的字节数组

func VerifyByRS

func VerifyByRS(pub *PublicKey, userId []byte, src []byte, r, s *big.Int) bool

Types

type P256V1Curve

type P256V1Curve struct {
	*elliptic.CurveParams
	A *big.Int
}

func GetSm2P256V1

func GetSm2P256V1() P256V1Curve

type PrivateKey

type PrivateKey struct {
	D     *big.Int
	Curve P256V1Curve
}

func EcsdAToSm2Pri

func EcsdAToSm2Pri(key *ecdsa.PrivateKey) *PrivateKey

ecdsa privatekey covert to gm privatekey.

func RawBytesToPrivateKey

func RawBytesToPrivateKey(bytes []byte) (*PrivateKey, error)

func (*PrivateKey) GetRawBytes

func (pri *PrivateKey) GetRawBytes() []byte

type PublicKey

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

func CalculatePubKey

func CalculatePubKey(priv *PrivateKey) *PublicKey

func EcsdAToSm2Pubk

func EcsdAToSm2Pubk(key *ecdsa.PublicKey) *PublicKey

ecdsa publickey covert to gm publickey.

func RawBytesToPublicKey

func RawBytesToPublicKey(bytes []byte) (*PublicKey, error)

func (*PublicKey) GetRawBytes

func (pub *PublicKey) GetRawBytes() []byte

func (*PublicKey) GetUnCompressBytes

func (pub *PublicKey) GetUnCompressBytes() []byte

type Sm2CipherTextType

type Sm2CipherTextType int32
const (
	// 旧标准的密文顺序
	C1C2C3 Sm2CipherTextType = 1
	// [GM/T 0009-2012]标准规定的顺序
	C1C3C2 Sm2CipherTextType = 2
)

Jump to

Keyboard shortcuts

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