sign

package
v0.0.0-...-2f646e5 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2019 License: MIT Imports: 14 Imported by: 4

Documentation

Overview

package sign provides a standardized interface for cryptographic signatures and a default implementation with ECDSA with the secp256k1 curve.

Index

Constants

View Source
const (
	// FingerprintLen is the length of the Fingerprint in bytes. Same as the hash length (20)
	FingerprintLen = hash.ByteLen
)

Variables

This section is empty.

Functions

func IsBadSignature

func IsBadSignature(err error) bool

IsBadSignature returns true if err is about a bad signature (e.g. ErrBadSignature)

Types

type ECDSAPrivateKey

type ECDSAPrivateKey ec.PrivateKey

func PrivFromECDSA

func PrivFromECDSA(pr *ec.PrivateKey) *ECDSAPrivateKey

func (*ECDSAPrivateKey) Compare

func (epriv *ECDSAPrivateKey) Compare(f Fingerprint) (ok bool, err error)

func (*ECDSAPrivateKey) Derive

func (epriv *ECDSAPrivateKey) Derive(expansion []byte) (PrivateKey, error)

func (*ECDSAPrivateKey) DeriveSymmetric

func (epriv *ECDSAPrivateKey) DeriveSymmetric(keyIdx uint32, context string, out []byte) (n int, err error)

DeriveSymmetric derives a symmetric key from this private key and writes it to out. keyIdx is the index of the key to generate, and context is a short description of the context the key will be used in, such as "write sign key". It returns the number of bytes copied and an error if fewer bytes were read. The error is EOF only if no bytes were read. If an EOF happens after reading some but not all the bytes, ReadFull returns ErrUnexpectedEOF. On return, n == len(buf) if and only if err == nil.

func (*ECDSAPrivateKey) ECDSA

func (epriv *ECDSAPrivateKey) ECDSA() *ec.PrivateKey

ECDSA returns a standard ecdsa.PrivateKey based on this ECDSAPrivateKey

func (*ECDSAPrivateKey) Fingerprint

func (epriv *ECDSAPrivateKey) Fingerprint() Fingerprint

func (*ECDSAPrivateKey) MarshalBinary

func (epriv *ECDSAPrivateKey) MarshalBinary() (data []byte, err error)

func (*ECDSAPrivateKey) Public

func (epriv *ECDSAPrivateKey) Public() PublicKey

func (*ECDSAPrivateKey) Sign

func (epriv *ECDSAPrivateKey) Sign(h hash.Hashable) Signature

Sign calculates an ECDSA signature for a given Hashable.

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 hash cannot be chosen by an adversary

func (*ECDSAPrivateKey) UnmarshalBinary

func (epriv *ECDSAPrivateKey) UnmarshalBinary(data []byte) error

func (*ECDSAPrivateKey) Verify

func (epriv *ECDSAPrivateKey) Verify(sig Signature, h hash.Hashable) error

type ECDSAPublicKey

type ECDSAPublicKey ec.PublicKey

ECDSAPublicKey is an ECDSA public key

func PubFromECDSA

func PubFromECDSA(pk *ec.PublicKey) *ECDSAPublicKey

func (*ECDSAPublicKey) Compare

func (epubk *ECDSAPublicKey) Compare(f Fingerprint) (ok bool, err error)

Compare this public key to a fingerprint

func (*ECDSAPublicKey) ECDSA

func (epubk *ECDSAPublicKey) ECDSA() *ec.PublicKey

ECDSA returns a standard ecdsa.PublicKey based on this ECDSAPublicKey

func (*ECDSAPublicKey) Fingerprint

func (epubk *ECDSAPublicKey) Fingerprint() (fp Fingerprint)

func (*ECDSAPublicKey) MarshalBinary

func (epubk *ECDSAPublicKey) MarshalBinary() (data []byte, err error)

MarshalBinary encodes a public key to the 33-byte compressed format.

func (*ECDSAPublicKey) UnmarshalBinary

func (epubk *ECDSAPublicKey) UnmarshalBinary(data []byte) error

UnmarshalBinary parses a public key in the 33-byte compressed format.

func (*ECDSAPublicKey) Verify

func (epubk *ECDSAPublicKey) Verify(sig Signature, h hash.Hashable) (err error)

type ECDSASignature

type ECDSASignature []byte

ECDSASignature is an ECDSA signature

func (ECDSASignature) Values

func (ecSig ECDSASignature) Values() (r, s, v *big.Int)

Values returns the r, s and v values of the ECDSA signature

type ErrBadSignature

type ErrBadSignature struct{}

func (ErrBadSignature) BadSignature

func (_ ErrBadSignature) BadSignature() bool

BadSignature always returns true for ErrBadSignature.

func (ErrBadSignature) Error

func (e ErrBadSignature) Error() string

type ErrWrongFingerprintLen

type ErrWrongFingerprintLen int

func (ErrWrongFingerprintLen) Error

func (e ErrWrongFingerprintLen) Error() string

type Fingerprint

type Fingerprint hash.Hash

A Fingerprint uniquely identifies a public signature key

func BytesToFingerprint

func BytesToFingerprint(b []byte) (fp Fingerprint, err error)

BytesToFingerprint turns b into a Fingerprint. If len(b) != FingerprintLen, BytesToFingerprint will return an error

func NilFingerprint

func NilFingerprint() Fingerprint

NilFingerprint returns an empty Fingerprint

func ParseFingerprint

func ParseFingerprint(s string) (Fingerprint, error)

ParseFingerprint parses s as a fingerprint.

func (Fingerprint) Bytes

func (fp Fingerprint) Bytes() []byte

func (Fingerprint) IsZero

func (fp Fingerprint) IsZero() bool

func (Fingerprint) MarshalNoms

func (fp Fingerprint) MarshalNoms(vrw nomstypes.ValueReadWriter) (val nomstypes.Value, err error)

func (Fingerprint) MarshalNomsType

func (_ Fingerprint) MarshalNomsType() (t *nomstypes.Type, err error)

func (*Fingerprint) SetBytes

func (fp *Fingerprint) SetBytes(b []byte) error

SetBytes sets the value of fp from b. If len(b) != FingerprintLen, SetBytes will return an error.

func (Fingerprint) String

func (fp Fingerprint) String() string

func (*Fingerprint) UnmarshalNoms

func (fp *Fingerprint) UnmarshalNoms(v nomstypes.Value) error

func (Fingerprint) Zero

func (fp Fingerprint) Zero()

type PrivIsECDSA

type PrivIsECDSA interface {
	ECDSA() *ec.PrivateKey
}

PrivIsECDSA is implemented by ECDSA PrivateKeys

type PrivateKey

type PrivateKey interface {
	PublicKey
	Public() PublicKey
	Sign(h hash.Hashable) Signature
	Derive([]byte) (PrivateKey, error)
	DeriveSymmetric(keyIdx uint32, context string, out []byte) (n int, err error)
}

func Generate

func Generate() (PrivateKey, error)

Generate generates a new private signature key.

type PubIsECDSA

type PubIsECDSA interface {
	ECDSA() *ec.PublicKey
}

PubIsECDSA is implemented by ECDSA PublicKeys

type PublicKey

type PublicKey interface {
	Fingerprint() Fingerprint
	Verify(sig Signature, message hash.Hashable) (err error)
	Compare(f Fingerprint) (ok bool, err error)
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
}

PublicKey is implemented by public signature keys

func RecoverPubkey

func RecoverPubkey(sig Signature, hash []byte) (PublicKey, error)

type Signature

type Signature interface {
}

A Signature represents a cryptographic signature. Each PublicKey / PrivateKey implementation must define their own. See ECDSASignature for the default ECDSA implementation.

Directories

Path Synopsis
package extended implements hierarchical deterministic key generation, i.e.
package extended implements hierarchical deterministic key generation, i.e.

Jump to

Keyboard shortcuts

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