sm2

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package sm2 implements china crypto standards.

Package sm2 implements china crypto standards.

Index

Constants

This section is empty.

Variables

View Source
var DecryptionErr = errors.New("sm2: decryption error")
View Source
var EncryptionErr = errors.New("sm2: encryption error")
View Source
var SM2PARAM_A, _ = new(big.Int).SetString("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC", 16)

Functions

func AffineToP256Point

func AffineToP256Point(x, y *big.Int) (out p256Point)

func Decrypt

func Decrypt(c []byte, key *PrivateKey) ([]byte, error)

func Encrypt

func Encrypt(rand io.Reader, key *PublicKey, msg []byte) (der []byte, err error)

func Hexprint

func Hexprint(in []byte)

func P256Sm2

func P256Sm2() elliptic.Curve

func Sign

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

func SignWithDigest

func SignWithDigest(rand io.Reader, priv *PrivateKey, digest []byte) (r, s *big.Int, err error)

func Test1

func Test1()

func TestP256_Point

func TestP256_Point()

func Test_amd64

func Test_amd64()

func Test_p256Func

func Test_p256Func()

func Test_p256InternalFunc

func Test_p256InternalFunc()

func Uint64ToAffine

func Uint64ToAffine(in []uint64) (x, y *big.Int)

func Verify

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

func VerifyById

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

func VerifyWithDigest

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

Types

type EncData

type EncData struct {
	X    *big.Int
	Y    *big.Int
	Hash []byte
	C2   []byte
}

sm2 enc structure in asn1

type PrivateKey

type PrivateKey struct {
	PublicKey
	D *big.Int
}

func GenerateKey

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

func (*PrivateKey) Decrypt

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

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(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)

func (*PrivateKey) SignWithDigest

func (priv *PrivateKey) SignWithDigest(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)

type PublicKey

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

func (*PublicKey) Verify

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

func (*PublicKey) VerifyWithDigest

func (pub *PublicKey) VerifyWithDigest(digest []byte, sign []byte) bool

Jump to

Keyboard shortcuts

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