sm2

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2019 License: MIT Imports: 13 Imported by: 0

README

SM 2

前提条件

  • 数字签名部分需要 sm3

相关链接

参考和引用

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func GenKey

func GenKey(rand io.Reader) (*PrivKey, *PubKey, error)

GenKey 生成密钥对

func IsPointInfinity

func IsPointInfinity(x, y *big.Int) bool

func MarshalEncryptedToASN1DER

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

func UnmarshalEncryptedFromASN1DER

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

Types

type ASN1DERCipher

type ASN1DERCipher struct {
	X, Y *big.Int
	C3   []byte
	C2   []byte
}

ASN1DERCipher 密文

type Curve

type Curve struct {
	*elliptic.CurveParams
	RInverse *big.Int
	A        *big.Int
}

Curve 曲线和曲线参数 3.1

func GetSm2P256

func GetSm2P256() Curve

func Init

func Init(A *big.Int, RInverse *big.Int, givenCurveParams *elliptic.CurveParams) *Curve

Init 初始化曲线

func InitWithRecommendedParams

func InitWithRecommendedParams() *Curve

InitWithRecommendedParams 使用推荐参数初始化曲线

type PrivKey

type PrivKey struct {
	D     *big.Int `json:"d"`
	Curve Curve    `json:"curve"`
}

PrivKey 私钥

func (*PrivKey) Decrypt

func (sk *PrivKey) Decrypt(in []byte) ([]byte, error)

func (*PrivKey) GenPubKey

func (sk *PrivKey) GenPubKey() *PubKey

GenPubKey 生成公钥

func (*PrivKey) Sign

func (sk *PrivKey) Sign(userID []byte, data []byte) ([]byte, error)

Sign 用私钥生成基于 ASN.1 DER-encoded 的签名

func (*PrivKey) SignToASN1DER

func (sk *PrivKey) SignToASN1DER(userID []byte, msg []byte) ([]byte, error)

SignToASN1DER 生成签名并输出成 ASN.1 DER 格式

func (*PrivKey) SignToBigInt

func (sk *PrivKey) SignToBigInt(userID []byte, msg []byte) (r, s *big.Int, err error)

SignToBigInt 生成签名并输出成大数

func (*PrivKey) String

func (sk *PrivKey) String() string

func (*PrivKey) ToBytes

func (sk *PrivKey) ToBytes() []byte

ToBytes 私钥的字节流

type PubKey

type PubKey struct {
	X     *big.Int `json:"x"`
	Y     *big.Int `json:"y"`
	Curve Curve    `json:"curve"`
}

PubKey 公钥

func (*PubKey) Encrypt

func (pk *PubKey) Encrypt(msg []byte) ([]byte, error)

func (*PubKey) String

func (pk *PubKey) String() string

func (*PubKey) ToBytes

func (pk *PubKey) ToBytes() []byte

ToBytes 公钥的字节流

func (*PubKey) ToUncompressedBytes

func (pk *PubKey) ToUncompressedBytes() []byte

ToUncompressedBytes 公钥未压缩字节流

func (*PubKey) Verify

func (pk *PubKey) Verify(userID []byte, data []byte, sig []byte) bool

Verify 用公钥验证基于 ASN.1 DER-encoded 的签名

func (*PubKey) VerifyFromASN1DER

func (pk *PubKey) VerifyFromASN1DER(userID []byte, msg []byte, sigBytes []byte) bool

VerifyFromASN1DER 验证签名

func (*PubKey) VerifyFromBigInt

func (pk *PubKey) VerifyFromBigInt(userID []byte, msg []byte, r, s *big.Int) bool

type Signature

type Signature struct {
	R, S *big.Int
}

Signature 签名

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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