sm2

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func BHGenerateKey

func BHGenerateKey() (pubKey string, priKey string, err error)

BHGenerateKey used to product publicKey and privateKey

func BHGeneratePointCompressKey

func BHGeneratePointCompressKey() (pubKey string, priKey string, err error)

BHGeneratePointCompressKey used to product publicKey and privateKey. The publicKey is ponit compressed

func BHSign

func BHSign(priKey string, userID []byte, src []byte) ([]byte, error)

BHSign used to sign src,priKey is hex string.return r/s bytes If userID be assigned nil,which default value is 1234567812345678

func BHSignX

func BHSignX(priKey string, userID []byte, src []byte) ([]byte, error)

BHSignX used to sign src,priKey is hex string.return asn.1 format bytes If userID be assigned nil,which default value is 1234567812345678

func BHVerify

func BHVerify(pubKey string, userID []byte, src []byte, sign []byte) (pass bool, err error)

BHVerify function is similar with VerifyWithPointCompress,the pubKey is unCompress,the sign is r/s bytes

func BHVerifyWithPointCompress

func BHVerifyWithPointCompress(pubKey string, userID []byte, src []byte, sign []byte) (pass bool, err error)

BHVerifyWithPointCompress used to verify src and sign,the pubKey is point compress,the sign is r/s bytes If userID be assigned nil,which default value is 1234567812345678

func BHVerifyWithPointCompressX

func BHVerifyWithPointCompressX(pubKey string, userID []byte, src []byte, sign []byte) (pass bool, err error)

BHVerifyWithPointCompressX used to verify src and sign,the pubKey is point compress,the sign is asn.1 format bytes If userID be assigned nil,which default value is 1234567812345678

func BHVerifyX

func BHVerifyX(pubKey string, userID []byte, src []byte, sign []byte) (pass bool, err error)

BHVerifyX function is similar with VerifyWithPointCompress,the pubKey is unCompress,the sign is asn.1 format bytes

func Decrypt

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

func Encrypt

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

func GenerateKey

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

func MarshalCipher

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

func MarshalSign

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

func P256Sm2

func P256Sm2() elliptic.Curve

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

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

func (*PublicKey) GetRawBytes

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

func (*PublicKey) GetUnCompressBytes

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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