sm2

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compress added in v1.2.2

func Compress(a *PublicKey) []byte

func Decrypt added in v1.2.2

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

func Encrypt added in v1.2.2

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

* sm2密文结构如下: * x * y * hash * CipherText

func MarshalSm2EcryptedPrivateKey

func MarshalSm2EcryptedPrivateKey(PrivKey *PrivateKey, pwd []byte) ([]byte, error)

func MarshalSm2PrivateKey

func MarshalSm2PrivateKey(key *PrivateKey, pwd []byte) ([]byte, error)

func MarshalSm2PublicKey

func MarshalSm2PublicKey(key *PublicKey) ([]byte, error)

func MarshalSm2UnecryptedPrivateKey

func MarshalSm2UnecryptedPrivateKey(key *PrivateKey) ([]byte, error)

func P256Sm2

func P256Sm2() elliptic.Curve

func Sign

func Sign(priv *PrivateKey, hash []byte) (r, s *big.Int, err error)

func SignDataToSignDigit added in v1.2.2

func SignDataToSignDigit(sign []byte) (*big.Int, *big.Int, error)

func SignDigitToSignData added in v1.2.2

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

func Sm2Sign added in v1.2.2

func Sm2Sign(priv *PrivateKey, msg, uid []byte) (r, s *big.Int, err error)

func Sm2Verify added in v1.2.2

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

func Verify

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

func WritePrivateKeytoMem

func WritePrivateKeytoMem(key *PrivateKey, pwd []byte) ([]byte, error)

func WritePrivateKeytoPem

func WritePrivateKeytoPem(FileName string, key *PrivateKey, pwd []byte) (bool, error)

func WritePublicKeytoMem

func WritePublicKeytoMem(key *PublicKey, _ []byte) ([]byte, error)

func WritePublicKeytoPem

func WritePublicKeytoPem(FileName string, key *PublicKey, _ []byte) (bool, error)

func ZA added in v1.2.2

func ZA(pub *PublicKey, uid []byte) ([]byte, error)

ZA = H256(ENTLA || IDA || a || b || xG || yG || xA || yA)

Types

type EncryptedPrivateKeyInfo

type EncryptedPrivateKeyInfo struct {
	EncryptionAlgorithm Pbes2Algorithms
	EncryptedData       []byte
}

reference to https://www.rfc-editor.org/rfc/rfc5958.txt

type Pbes2Algorithms

type Pbes2Algorithms struct {
	IdPBES2     asn1.ObjectIdentifier
	Pbes2Params Pbes2Params
}

reference to https://www.ietf.org/rfc/rfc2898.txt

type Pbes2Encs

type Pbes2Encs struct {
	EncryAlgo asn1.ObjectIdentifier
	IV        []byte
}

type Pbes2KDfs

type Pbes2KDfs struct {
	IdPBKDF2    asn1.ObjectIdentifier
	Pkdf2Params Pkdf2Params
}

reference to https://www.ietf.org/rfc/rfc2898.txt

type Pbes2Params

type Pbes2Params struct {
	KeyDerivationFunc Pbes2KDfs // PBES2-KDFs
	EncryptionScheme  Pbes2Encs // PBES2-Encs
}

reference to https://www.ietf.org/rfc/rfc2898.txt

type Pkdf2Params

type Pkdf2Params struct {
	Salt           []byte
	IterationCount int
	Prf            pkix.AlgorithmIdentifier
}

reference to https://www.ietf.org/rfc/rfc2898.txt

type PrivateKey

type PrivateKey struct {
	PublicKey
	D *big.Int
}

func GenerateKey

func GenerateKey() (*PrivateKey, error)

func ParsePKCS8EcryptedPrivateKey

func ParsePKCS8EcryptedPrivateKey(der, pwd []byte) (*PrivateKey, error)

func ParsePKCS8PrivateKey

func ParsePKCS8PrivateKey(der, pwd []byte) (*PrivateKey, error)

func ParsePKCS8UnecryptedPrivateKey

func ParsePKCS8UnecryptedPrivateKey(der []byte) (*PrivateKey, error)

func ParseSm2PrivateKey

func ParseSm2PrivateKey(der []byte) (*PrivateKey, error)

func ReadPrivateKeyFromMem

func ReadPrivateKeyFromMem(data []byte, pwd []byte) (*PrivateKey, error)

func ReadPrivateKeyFromPem

func ReadPrivateKeyFromPem(FileName string, pwd []byte) (*PrivateKey, error)

func (*PrivateKey) Decrypt added in v1.2.2

func (priv *PrivateKey) Decrypt(data []byte) ([]byte, 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)

sign format = 30 + len(z) + 02 + len(r) + r + 02 + len(s) + s, z being what follows its size, ie 02+len(r)+r+02+len(s)+s

type PrivateKeyInfo

type PrivateKeyInfo struct {
	Version             int // v1 or v2
	PrivateKeyAlgorithm []asn1.ObjectIdentifier
	PrivateKey          []byte
}

reference to https://www.rfc-editor.org/rfc/rfc5958.txt

type PublicKey

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

func Decompress added in v1.2.2

func Decompress(a []byte) *PublicKey

func ParseSm2PublicKey

func ParseSm2PublicKey(der []byte) (*PublicKey, error)

func ReadPublicKeyFromMem

func ReadPublicKeyFromMem(data []byte, _ []byte) (*PublicKey, error)

func ReadPublicKeyFromPem

func ReadPublicKeyFromPem(FileName string, pwd []byte) (*PublicKey, error)

func (*PublicKey) Encrypt added in v1.2.2

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

func (*PublicKey) Verify

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

Jump to

Keyboard shortcuts

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