sm2

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

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 ResponderConfirm

func ResponderConfirm(responderS2 []byte, initiatorS2 []byte) bool

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 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 ExchangeResult

type ExchangeResult struct {
	Key []byte
	S1  []byte
	S2  []byte
}

func CalculateKeyWithConfirmation

func CalculateKeyWithConfirmation(initiator bool, keyBits int, confirmationTag []byte,
	selfStaticPriv *PrivateKey, selfEphemeralPriv *PrivateKey, selfId []byte,
	otherStaticPub *PublicKey, otherEphemeralPub *PublicKey, otherId []byte) (*ExchangeResult, error)

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 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 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
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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