sm2

package
v0.0.0-...-d024a02 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

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 T1 = make(map[string]int64, 16777216)
View Source
var T2x = make([]*big.Int, 256)
View Source
var T2y = make([]*big.Int, 256)

Functions

func Decrypt

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

func Encrypt

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

func KeyDerivation

func KeyDerivation(Z []byte, klen int) []byte

func LgwDec

func LgwDec(x1, y1 *big.Int, c2, c3 []byte, key *PrivateKey) ([]byte, error)

func LgwEnc

func LgwEnc(rand io.Reader, key *PublicKey, msg []byte) (x, y *big.Int, c2, c3 []byte, err error)

func LgwHDec

func LgwHDec(key *PrivateKey, c1x, c1y, c2x, c2y *big.Int) (int, error)

func LgwHEnc

func LgwHEnc(rand io.Reader, key *PublicKey, m *big.Int) (x1, y1, c2x, c2y *big.Int)

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 Sm2KeyGen

func Sm2KeyGen(rand io.Reader) (sk, pk []byte, err error)

func Sm2Sign

func Sm2Sign(sk, pk, msg []byte) ([]byte, error)

func Sm2Verify

func Sm2Verify(sign, pk, msg []byte) bool

func Verify

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

func VerifyWithDigest

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

Types

type PrivateKey

type PrivateKey struct {
	PublicKey
	D    *big.Int
	DInv *big.Int //(1+d)^-1
}

func GenerateKey

func GenerateKey(rand io.Reader) (*PrivateKey, 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) ([]byte, error)

type PublicKey

type PublicKey struct {
	sm2curve.Curve
	X, Y        *big.Int
	PreComputed *[37][64 * 8]uint64 //precomputation
}

func (*PublicKey) Verify

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

type Sm2PrivateKey

type Sm2PrivateKey struct {
	D *big.Int //sk
}

type Sm2PublicKey

type Sm2PublicKey struct {
	X *big.Int //pk.X
	Y *big.Int //pk.Y
}

Jump to

Keyboard shortcuts

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