smcrypto

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKey added in v1.1.0

func GenerateKey() (*ecdsa.PrivateKey, error)

GenerateKey generates a new private key.

func HexKeyToAddress

func HexKeyToAddress(hexKey string) common.Address

HexKeyToAddress calculate address from sm2p256v1 private key

func HexToPEM added in v0.10.0

func HexToPEM(hexkey string) (string, error)

HexToPEM parses a secp256k1 private key.

func HexToSM2 added in v0.10.0

func HexToSM2(hexkey string) (*ecdsa.PrivateKey, error)

HexToSM2 parses a secp256k1 private key.

func PubkeyToAddress

func PubkeyToAddress(p ecdsa.PublicKey) common.Address

PubkeyToAddress calculate address from sm2p256v1 private key

func SM2KeyToAddress added in v0.10.0

func SM2KeyToAddress(privateKey []byte) common.Address

SM2KeyToAddress calculate address from sm2p256v1 private key

func SM2PreProcess

func SM2PreProcess(src []byte, id string, priv *ecdsa.PrivateKey) ([]byte, error)

SM2PreProcess compute z value of id and return z||m

func SM2PubBytes added in v0.10.0

func SM2PubBytes(pub *ecdsa.PublicKey) []byte

SM2PubBytes return esdsa public key as slice

func SM2Sign

func SM2Sign(src []byte, priv *ecdsa.PrivateKey) (r, s *big.Int, err error)

SM2Sign return sm2 signature

func SM2ToPEM added in v0.10.0

func SM2ToPEM(key *ecdsa.PrivateKey) (string, error)

SM2ToPEM parses a secp256k1 private key.

func Sign

func Sign(hash, privateKey []byte) (sig []byte, err error)

Sign calculates an sm2 signature.

This function is susceptible to chosen plaintext attacks that can leak information about the private key that is used for signing. Callers must be aware that the given hash cannot be chosen by an adversery. Common solution is to hash any input before calculating the signature.

The produced signature is in the [R || S || V] format where V is public key.

func ToSM2 added in v0.10.0

func ToSM2(d []byte) (*ecdsa.PrivateKey, error)

ToSM2 creates a private key with the given D value.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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