sm2

package
v2.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CTX_POOLSIZE_PER_PK = 10
	CTXPOOL_CACHESIZE   = 10000
)
View Source
const BIG_NUM_SIZE = 64
View Source
const SM2_CIPHER_EXTRA_SIZE = 120
View Source
const SM2_CIPHER_MODE_C1C2C3 = tencentsm.SM2CipherMode_C1C2C3
View Source
const SM2_CIPHER_MODE_C1C2C3_ASN1 = tencentsm.SM2CipherMode_C1C2C3_ASN1
View Source
const SM2_CIPHER_MODE_C1C3C2 = tencentsm.SM2CipherMode_C1C3C2
View Source
const SM2_CIPHER_MODE_C1C3C2_ASN1 = tencentsm.SM2CipherMode_C1C3C2_ASN1
View Source
const SM2_PRIVATE_KEY_SIZE = 64
View Source
const SM2_PRIVATE_KEY_STR_LEN = 66
View Source
const SM2_PUBLIC_KEY_SIZE = 130
View Source
const SM2_PUBLIC_KEY_STR_LEN = 132
View Source
const SM2_SIGNATURE_MAX_SIZE = 80
View Source
const SM2_SIGNATURE_MODE_RS = tencentsm.SM2SignMode_RS
View Source
const SM2_SIGNATURE_MODE_RS_ASN1 = tencentsm.SM2SignMode_RS_ASN1
View Source
const SM3_DIGEST_SIZE = tencentsm.SM3_DIGEST_LENGTH

Variables

This section is empty.

Functions

func GetSignatureFromCFCA

func GetSignatureFromCFCA(signature []byte) []byte

nolint CFCA证书若签名为31位,会补0,go本身是不补,长度写31 兼容 去掉补0,长度改为31

func MarshalPrivateKey

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

func MarshalPublicKey

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

public key conversion

func PrivateKeyToPEM

func PrivateKeyToPEM(key *PrivateKey) (string, error)

func PublicKeyToPEM

func PublicKeyToPEM(key *PublicKey) (string, error)

Types

type CtxPool

type CtxPool struct {
	// contains filtered or unexported fields
}

func NewCtxPoolWithPubKey

func NewCtxPoolWithPubKey(pubkey []byte) *CtxPool

func (*CtxPool) Close

func (c *CtxPool) Close()

func (*CtxPool) GetCtx

func (c *CtxPool) GetCtx() *tencentsm.SM2_ctx_t

func (*CtxPool) ReleaseCtx

func (c *CtxPool) ReleaseCtx(ctx *tencentsm.SM2_ctx_t)

type PrivateKey

type PrivateKey struct {
	D    *big.Int
	Text []byte
	// contains filtered or unexported fields
}

func GenerateKeyPair

func GenerateKeyPair() (*PrivateKey, error)

func PrivateKeyFromPEM

func PrivateKeyFromPEM(skPEM string) (*PrivateKey, error)

func UnmarshalPrivateKey

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

func UnmarshalPrivateKeyWithCurve

func UnmarshalPrivateKeyWithCurve(namedCurveOID *asn1.ObjectIdentifier, der []byte) (*PrivateKey, error)

func (*PrivateKey) Bytes

func (sk *PrivateKey) Bytes() ([]byte, error)

func (PrivateKey) Decrypt

func (sk PrivateKey) Decrypt(cipher []byte) ([]byte, error)

func (*PrivateKey) DecryptWithMode

func (sk *PrivateKey) DecryptWithMode(cipher []byte, mode tencentsm.SM2CipherMode) ([]byte, error)

func (PrivateKey) DecryptWithOpts

func (sk PrivateKey) DecryptWithOpts(ciphertext []byte, opts *bccrypto.EncOpts) ([]byte, error)

func (PrivateKey) EncryptKey

func (sk PrivateKey) EncryptKey() bccrypto.EncryptKey

func (*PrivateKey) PublicKey

func (sk *PrivateKey) PublicKey() bccrypto.PublicKey

func (*PrivateKey) Sign

func (sk *PrivateKey) Sign(msg []byte) ([]byte, error)

func (*PrivateKey) SignWithOpts

func (sk *PrivateKey) SignWithOpts(msg []byte, opts *bccrypto.SignOpts) ([]byte, error)

func (*PrivateKey) String

func (sk *PrivateKey) String() (string, error)

func (*PrivateKey) ToStandardKey

func (sk *PrivateKey) ToStandardKey() crypto.PrivateKey

func (*PrivateKey) Type

func (sk *PrivateKey) Type() bccrypto.KeyType

type PublicKey

type PublicKey struct {
	elliptic.Curve
	X, Y *big.Int
	Text []byte
	// contains filtered or unexported fields
}

func ParseSM2PublicKey

func ParseSM2PublicKey(asn1Data []byte) (*PublicKey, error)

func PublicKeyFromPEM

func PublicKeyFromPEM(pkPEM string) (*PublicKey, error)

func UnmarshalPublicKey

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

func (*PublicKey) Bytes

func (pk *PublicKey) Bytes() ([]byte, error)

func (PublicKey) Encrypt

func (pk PublicKey) Encrypt(msg []byte) ([]byte, error)

func (PublicKey) EncryptWithMode

func (pk PublicKey) EncryptWithMode(msg []byte, mode tencentsm.SM2CipherMode) ([]byte, error)

func (PublicKey) EncryptWithOpts

func (pk PublicKey) EncryptWithOpts(data []byte, opts *bccrypto.EncOpts) ([]byte, error)

func (*PublicKey) String

func (pk *PublicKey) String() (string, error)

func (*PublicKey) ToStandardKey

func (pk *PublicKey) ToStandardKey() crypto.PublicKey

ToStandardKey nolint

func (*PublicKey) Type

func (pk *PublicKey) Type() bccrypto.KeyType

func (*PublicKey) Verify

func (pk *PublicKey) Verify(data []byte, sig []byte) (bool, error)

func (*PublicKey) VerifyWithOpts

func (pk *PublicKey) VerifyWithOpts(msg []byte, sig []byte, opts *bccrypto.SignOpts) (bool, error)

Jump to

Keyboard shortcuts

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