ecrdsa

package
v1.0.4030 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParametersNotSetUp = errors.New("go-cryptobin/ecrdsa: parameters not set up before generating key")
	ErrInvalidASN1        = errors.New("go-cryptobin/ecrdsa: invalid ASN.1")
	ErrInvalidSignerOpts  = errors.New("go-cryptobin/ecrdsa: opts must be *SignerOpts")
)

Functions

func PrivateKeyTo

func PrivateKeyTo(key *PrivateKey) []byte

输出私钥明文 output PrivateKey data

func PublicKeyTo

func PublicKeyTo(key *PublicKey) []byte

输出公钥明文 output PublicKey data

func Sign

func Sign(rand io.Reader, priv *PrivateKey, h Hasher, data []byte, useISO14888_3 bool) (sig []byte, err error)

Sign data returns the ASN.1 encoded signature.

func SignBytes

func SignBytes(rand io.Reader, priv *PrivateKey, h Hasher, data []byte, useISO14888_3 bool) (sig []byte, err error)

Sign data returns the Bytes encoded signature.

func SignToRS

func SignToRS(rand io.Reader, priv *PrivateKey, hashFunc Hasher, msg []byte, useISO14888_3 bool) (r, s *big.Int, err error)

*| IUF - EC-RDSA signature *| *| UF 1. Compute h = H(m) *| F 2. Get a random value k in ]0,q[ *| F 3. Compute W = (W_x,W_y) = kG *| F 4. Compute r = W_x mod q *| F 5. If r is 0, restart the process at step 2. *| F 6. Compute e = OS2I(h) mod q. If e is 0, set e to 1. *| NOTE: here, ISO/IEC 14888-3 and RFCs differ in the way e treated. *| e = OS2I(h) for ISO/IEC 14888-3, or e = OS2I(reversed(h)) when endianness of h *| is reversed for RFCs. *| F 7. Compute s = (rx + ke) mod q *| F 8. If s is 0, restart the process at step 2. *| F 11. Return (r,s) *

func Verify

func Verify(pub *PublicKey, h Hasher, data, sig []byte, useISO14888_3 bool) bool

Verify verifies the ASN.1 encoded signature, sig, M, of hash using the public key, pub. Its return value records whether the signature is valid.

func VerifyBytes

func VerifyBytes(pub *PublicKey, h Hasher, data, sig []byte, useISO14888_3 bool) bool

Verify verifies the Bytes encoded signature

func VerifyWithRS

func VerifyWithRS(pub *PublicKey, hashFunc Hasher, data []byte, r, s *big.Int, useISO14888_3 bool) bool

*| IUF - EC-RDSA verification *| *| UF 1. Check that r and s are both in ]0,q[ *| F 2. Compute h = H(m) *| F 3. Compute e = OS2I(h)^-1 mod q *| NOTE: here, ISO/IEC 14888-3 and RFCs differ in the way e treated. *| e = OS2I(h) for ISO/IEC 14888-3, or e = OS2I(reversed(h)) when endianness of h *| is reversed for RFCs. *| F 4. Compute u = es mod q *| F 5. Compute v = -er mod q *| F 6. Compute W' = uG + vY = (W'_x, W'_y) *| F 7. Compute r' = W'_x mod q *| F 8. Check r and r' are the same *

Types

type Hasher

type Hasher = func() hash.Hash

type PrivateKey

type PrivateKey struct {
	PublicKey

	D *big.Int
}

ec-gdsa PrivateKey

func GenerateKey

func GenerateKey(random io.Reader, c elliptic.Curve) (*PrivateKey, error)

Generate the PrivateKey

func NewPrivateKey

func NewPrivateKey(curve elliptic.Curve, k []byte) (*PrivateKey, error)

New a PrivateKey from privatekey data

func (*PrivateKey) Equal

func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool

Equal reports whether pub and x have the same value.

func (*PrivateKey) Public

func (priv *PrivateKey) Public() crypto.PublicKey

Public returns the public key corresponding to priv.

func (*PrivateKey) Sign

func (priv *PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)

crypto.Signer

type PublicKey

type PublicKey struct {
	elliptic.Curve

	X, Y *big.Int
}

ec-gdsa PublicKey

func NewPublicKey

func NewPublicKey(curve elliptic.Curve, k []byte) (*PublicKey, error)

根据公钥明文初始化公钥 New a PublicKey from publicKey data

func (*PublicKey) Equal

func (pub *PublicKey) Equal(x crypto.PublicKey) bool

Equal reports whether pub and x have the same value.

func (*PublicKey) Verify

func (pub *PublicKey) Verify(msg, sign []byte, opts crypto.SignerOpts) (bool, error)

Verify asn.1 marshal data

type SignerOpts

type SignerOpts struct {
	Hash          Hasher
	UseISO14888_3 bool
}

SignerOpts contains options for creating and verifying EC-GDSA signatures.

func (*SignerOpts) GetHash

func (opts *SignerOpts) GetHash() Hasher

GetHash returns func() hash.Hash

func (*SignerOpts) GetUseISO14888_3

func (opts *SignerOpts) GetUseISO14888_3() bool

GetUseISO14888_3 returns bool

func (*SignerOpts) HashFunc

func (opts *SignerOpts) HashFunc() crypto.Hash

HashFunc returns opts.Hash

Jump to

Keyboard shortcuts

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