asym

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: Apache-2.0 Imports: 16 Imported by: 5

Documentation

Index

Constants

View Source
const (
	AlgorithmNone     = 0x00
	AlgoP256K1        = 0x0200
	AlgoP256R1        = 0x0300
	AlgoP384R1        = 0x0400
	AlgoP521R1        = 0x0500
	AlgoP256K1Recover = 0x0600
	AlgoRSA2048       = 0x1000
	AlgoRSA3072       = 0x1100
	AlgoRSA4096       = 0x1200
)

Algorithm identity

Variables

This section is empty.

Functions

func Copy

func Copy(in *big.Int) *big.Int

Copy copy big

func Get32BYtes

func Get32BYtes() []byte

Get32BYtes get 32 bytes

func GetBig

func GetBig() *big.Int

GetBig git big

func Put32Bytes

func Put32Bytes(in []byte)

Put32Bytes put 32 bytes

func PutBig

func PutBig(in *big.Int)

PutBig put big

Types

type ECDSA

type ECDSA struct {
	Opt int
}

ECDSA ECDSA instance is a tool to sign and verify. You can sign and verify via ECDSAPrivateKey and ECDSAPublicKey, ECDSA instance is just a package of ECDSAPrivateKey's Sign and ECDSAPublicKey's Verify. If you need revoke Sign or Verify at a sepcific Key many times, we recommend using ECDSAPrivateKey and ECDSAPublicKey, which avoid decode and alloc repeatedly. All in all, ECDSA is convenient; ECDSAPrivateKey and ECDSAPublicKey are faster.

func NewECDSA

func NewECDSA(opt int) *ECDSA

NewECDSA get a ECDSA instance, input parameter is algorithm type

func (*ECDSA) Sign

func (sv *ECDSA) Sign(k []byte, digest []byte, reader io.Reader) (signature []byte, err error)

Sign get signature to digest, k is the private key

func (*ECDSA) Verify

func (sv *ECDSA) Verify(k []byte, signature, digest []byte) (valid bool, err error)

Verify verify signature ,k is the public key

type ECDSAPrivateKey

type ECDSAPrivateKey struct {
	ECDSAPublicKey
	D *big.Int
}

ECDSAPrivateKey ECDSA private key. never new(ECDSAPrivateKey), use NewECDSAPrivateKey()

func GenerateKey

func GenerateKey(opt int) (*ECDSAPrivateKey, error)

GenerateKey generate a pair of key,input is algorithm type

func (*ECDSAPrivateKey) Bytes

func (key *ECDSAPrivateKey) Bytes() ([]byte, error)

Bytes return key bytes. Inverse method of FromBytes(k []byte, opt AlgorithmOption)

func (*ECDSAPrivateKey) CalculatePublicKey

func (key *ECDSAPrivateKey) CalculatePublicKey() *ECDSAPrivateKey

CalculatePublicKey Calculate the public key contained in the private key when get a ECDSAPrivateKey by FromBytes(...), the public key contained is empty, you should invoke SetPublicKey(...) or CalculatePublicKey(). If you have the Public Key,SetPublicKey(...) is better and faster, since CalculatePublicKey() while calculate public key once again.

func (*ECDSAPrivateKey) FromBytes

func (key *ECDSAPrivateKey) FromBytes(k []byte, opt int) error

FromBytes parse a private Key from bytes, Inverse method of Bytes()

func (*ECDSAPrivateKey) Public

func (key *ECDSAPrivateKey) Public() std.PublicKey

Public GetBig ECDSAPublicKey from a ECDSAPrivateKey, if ECDSAPublicKey is empty, this method will invoke CalculatePublicKey().

func (*ECDSAPrivateKey) SetPublicKey

func (key *ECDSAPrivateKey) SetPublicKey(k *ECDSAPublicKey) *ECDSAPrivateKey

SetPublicKey Set the public key contained in the private key when get a ECDSAPrivateKey by FromBytes(...), the public key contained is empty, you should invoke SetPublicKey(...) or CalculatePublicKey(). If you have the Public Key,SetPublicKey(...) is better and faster, since CalculatePublicKey() while calculate public key once again.

func (*ECDSAPrivateKey) Sign

func (key *ECDSAPrivateKey) Sign(k, digest []byte, reader io.Reader) (signature []byte, err error)

Sign get signature of specific digest by ECDSAPrivateKey self,so the first parameter will be ignored signature is 65 bytes: r + s + v if s is odd, v == 01 if s is even, v == 00 look Ethereum yellow paper

type ECDSAPublicKey

type ECDSAPublicKey struct {
	elliptic.Curve
	X, Y *big.Int
	// contains filtered or unexported fields
}

ECDSAPublicKey ECDSA public key. never new(ECDSAPublicKey), use NewECDSAPublicKey()

func (*ECDSAPublicKey) AlgorithmType

func (key *ECDSAPublicKey) AlgorithmType() int

AlgorithmType return the algorithm type

func (*ECDSAPublicKey) Bytes

func (key *ECDSAPublicKey) Bytes() ([]byte, error)

Bytes return key bytes

func (*ECDSAPublicKey) FromBytes

func (key *ECDSAPublicKey) FromBytes(k []byte, opt int) error

FromBytes Parse a public key from 65 bytes and specific algorithm.The reverse method of Bytes()

func (*ECDSAPublicKey) Verify

func (key *ECDSAPublicKey) Verify(_ []byte, signature, digest []byte) (valid bool, err error)

Verify verify the signature by ECDSAPublicKey self, so the first parameter will be ignored.

type ECDSASignature

type ECDSASignature struct {
	R, S *big.Int
}

ECDSASignature ECDSASignature struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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