kg

package
v1.1.1007 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCurve       = errors.New("go-cryptobin/kg: invalid curve")
	ErrInvalidK           = errors.New("go-cryptobin/kg: use another K")
	ErrInvalidPrivateKey  = errors.New("go-cryptobin/kg: invalid private key")
	ErrInvalidPublicKey   = errors.New("go-cryptobin/kg: invalid public key")
	ErrInvalidSignature   = errors.New("go-cryptobin/kg: invalid signature")
	ErrInvalidCurvesMatch = errors.New("go-cryptobin/kg: curves miss match")
	ErrSharedKeyIsZero    = errors.New("go-cryptobin/kg: shared key is zero")
	ErrInvalidASN1        = errors.New("go-cryptobin/kg: invalid ASN.1 encoding")
	ErrInvalidSignerOpts  = errors.New("go-cryptobin/kg: opts must be *SignerOpts")
)

Functions

func AddNamedCurve

func AddNamedCurve(curve elliptic.Curve, oid asn1.ObjectIdentifier)

func MarshalECPrivateKey

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

MarshalECPrivateKey converts an EC private key to SEC 1, ASN.1 DER form.

This kind of key is commonly encoded in PEM blocks of type "EC PRIVATE KEY". For a more flexible key format which is not EC specific, use MarshalPKCS8PrivateKey.

func MarshalPrivateKey

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

Marshal PrivateKey to der

func MarshalPublicKey

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

Marshal PublicKey to der

func NamedCurveFromOid

func NamedCurveFromOid(oid asn1.ObjectIdentifier) elliptic.Curve

func OidFromNamedCurve

func OidFromNamedCurve(curve elliptic.Curve) (asn1.ObjectIdentifier, bool)

func PrivateKeyTo

func PrivateKeyTo(key *PrivateKey) []byte

return PrivateKey data

func PublicKeyTo

func PublicKeyTo(key *PublicKey) []byte

return PublicKey data

func SignASN1

func SignASN1(rand io.Reader, priv *PrivateKey, hashFunc Hasher, msg []byte) ([]byte, error)

sign data and return asn.1 marshal data

func SignToRS

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

* KG signature.

func SignUsingKToRS

func SignUsingKToRS(k *big.Int, priv *PrivateKey, hashFunc Hasher, msg []byte) (r, s *big.Int, err error)

*| IUF - KG signature

func VerifyASN1

func VerifyASN1(pub *PublicKey, hashFunc Hasher, msg, signature []byte) (bool, error)

Verify asn.1 marshal data

func VerifyWithRS

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

*| IUF - KG verification

Types

type Hasher

type Hasher = func() hash.Hash

type PrivateKey

type PrivateKey struct {
	PublicKey

	D *big.Int
}

func GenerateKey

func GenerateKey(rand io.Reader, curve elliptic.Curve) (*PrivateKey, error)

generate a private key

func NewPrivateKey

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

New a private key from key data bytes

func ParseECPrivateKey

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

ParseECPrivateKey parses an EC private key in SEC 1, ASN.1 DER form.

This kind of key is commonly encoded in PEM blocks of type "EC PRIVATE KEY".

func ParsePrivateKey

func ParsePrivateKey(derBytes []byte) (*PrivateKey, error)

Parse PrivateKey der

func (*PrivateKey) ECDH

func (priv *PrivateKey) ECDH(pub *PublicKey) ([]byte, error)

func (*PrivateKey) Equal

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

Equal reports whether priv and x have the same value.

func (*PrivateKey) Public

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

The KG's private key contains the public key

func (*PrivateKey) Sign

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

sign data and return asn.1 or bytes marshal data, default asn.1

type PublicKey

type PublicKey struct {
	elliptic.Curve

	X, Y *big.Int
}

func NewPublicKey

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

New a PublicKey from publicKey data

func ParsePublicKey

func ParsePublicKey(derBytes []byte) (pub *PublicKey, err error)

Parse PublicKey der

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(digest, signature []byte, opts crypto.SignerOpts) bool

Verify asn.1 marshal data ans1(r, s)

type SignerOpts

type SignerOpts struct {
	Hash Hasher
}

SignerOpts contains options for creating and verifying KG signatures.

func (*SignerOpts) GetHash

func (opts *SignerOpts) GetHash() Hasher

GetHash returns func() hash.Hash

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