gmsm

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrivateKeySize = 32
	PublicKeySize  = 64
)
View Source
const (
	HeaderCommonSize = 24
	HashSize         = 32
	GCMNonceSize     = 12
	GCMTagSize       = 16
	TimestampSize    = 8
	HeaderSize       = HeaderCommonSize + PublicKeySize + PublicKeySize + GCMTagSize + TimestampSize + GCMTagSize + HashSize
)
View Source
const (
	NHP_FLAG_EXTENDEDLENGTH = 1 << iota
	NHP_FLAG_COMPRESS
)

header flags (bit 0 - bit 11)

View Source
const (
	NHP_FLAG_SCHEME_GMSM = 0 << 12
)

cipher scheme combination (bit 11 - bit 15)

Variables

This section is empty.

Functions

func Base64DecodeSM2ECDHPrivateKey

func Base64DecodeSM2ECDHPrivateKey(privStr string) (*ecdh.PrivateKey, error)

func Base64DecodeSM2ECDHPublicKey

func Base64DecodeSM2ECDHPublicKey(pubStr string) (*ecdh.PublicKey, error)

func Base64DecodeSM2ECDSAPrivateKey

func Base64DecodeSM2ECDSAPrivateKey(pubKeyStr string, privKeyStr string) (*sm2.PrivateKey, error)

func Base64DecodeSM2ECDSAPublicKey

func Base64DecodeSM2ECDSAPublicKey(pubKeyStr string) (*ecdsa.PublicKey, error)

func GenerateSM2ECDHKeypair

func GenerateSM2ECDHKeypair() (string, string)

生成用于ECDH的SM2公私钥对

func GenerateSM2ECDSAKeypair

func GenerateSM2ECDSAKeypair() (*sm2.PrivateKey, string, string)

生成用于ECDSA的SM2公私钥对

Types

type HeaderGmsm

type HeaderGmsm struct {
	HeaderCommon [HeaderCommonSize]byte
	Ephermeral   [PublicKeySize]byte
	Static       [PublicKeySize + GCMTagSize]byte
	Timestamp    [TimestampSize + GCMTagSize]byte
	HMAC         [HashSize]byte
}

func (*HeaderGmsm) Bytes

func (h *HeaderGmsm) Bytes() []byte

func (*HeaderGmsm) Counter

func (h *HeaderGmsm) Counter() uint64

func (*HeaderGmsm) EphermeralBytes

func (h *HeaderGmsm) EphermeralBytes() []byte

func (*HeaderGmsm) Flag

func (h *HeaderGmsm) Flag() uint16

func (*HeaderGmsm) HMACBytes

func (h *HeaderGmsm) HMACBytes() []byte

func (*HeaderGmsm) IdentityBytes

func (h *HeaderGmsm) IdentityBytes() []byte

func (*HeaderGmsm) NonceBytes

func (h *HeaderGmsm) NonceBytes() []byte

func (*HeaderGmsm) SetCounter

func (h *HeaderGmsm) SetCounter(counter uint64)

func (*HeaderGmsm) SetFlag

func (h *HeaderGmsm) SetFlag(flag uint16)

func (*HeaderGmsm) SetTypeAndPayloadSize

func (h *HeaderGmsm) SetTypeAndPayloadSize(t int, s int)

func (*HeaderGmsm) SetVersion

func (h *HeaderGmsm) SetVersion(major int, minor int)

func (*HeaderGmsm) Size

func (h *HeaderGmsm) Size() int

func (*HeaderGmsm) StaticBytes

func (h *HeaderGmsm) StaticBytes() []byte

func (*HeaderGmsm) TimestampBytes

func (h *HeaderGmsm) TimestampBytes() []byte

func (*HeaderGmsm) TypeAndPayloadSize

func (h *HeaderGmsm) TypeAndPayloadSize() (t int, s int)

gmsm header implementations

func (*HeaderGmsm) Version

func (h *HeaderGmsm) Version() (int, int)

type SM2ECDH

type SM2ECDH struct {
	PrivKey [PrivateKeySize]byte
	PubKey  [PublicKeySize]byte

	PrivKeyBase64 string
	PubKeyBase64  string
	BriefName     string
	// contains filtered or unexported fields
}

func NewECDH

func NewECDH() *SM2ECDH

func (*SM2ECDH) Identity

func (s *SM2ECDH) Identity() []byte

func (*SM2ECDH) MidPublicKey

func (c *SM2ECDH) MidPublicKey() []byte

func (*SM2ECDH) Name

func (s *SM2ECDH) Name() string

func (*SM2ECDH) PrivateKey

func (s *SM2ECDH) PrivateKey() []byte

func (*SM2ECDH) PrivateKeyBase64

func (s *SM2ECDH) PrivateKeyBase64() string

func (*SM2ECDH) PublicKey

func (s *SM2ECDH) PublicKey() []byte

func (*SM2ECDH) PublicKeyBase64

func (s *SM2ECDH) PublicKeyBase64() string

func (*SM2ECDH) SetPrivateKey

func (s *SM2ECDH) SetPrivateKey(prk []byte) (err error)

func (*SM2ECDH) SharedSecret

func (s *SM2ECDH) SharedSecret(pbk []byte) []byte

Jump to

Keyboard shortcuts

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