Documentation ¶
Overview ¶
package sign provides a standardized interface for cryptographic signatures and a default implementation with ECDSA with the secp256k1 curve.
Index ¶
- Constants
- func IsBadSignature(err error) bool
- type ECDSAPrivateKey
- func (epriv *ECDSAPrivateKey) Compare(f Fingerprint) (ok bool, err error)
- func (epriv *ECDSAPrivateKey) Derive(expansion []byte) (PrivateKey, error)
- func (epriv *ECDSAPrivateKey) DeriveSymmetric(keyIdx uint32, context string, out []byte) (n int, err error)
- func (epriv *ECDSAPrivateKey) ECDSA() *ec.PrivateKey
- func (epriv *ECDSAPrivateKey) Fingerprint() Fingerprint
- func (epriv *ECDSAPrivateKey) MarshalBinary() (data []byte, err error)
- func (epriv *ECDSAPrivateKey) Public() PublicKey
- func (epriv *ECDSAPrivateKey) Sign(h hash.Hashable) Signature
- func (epriv *ECDSAPrivateKey) UnmarshalBinary(data []byte) error
- func (epriv *ECDSAPrivateKey) Verify(sig Signature, h hash.Hashable) error
- type ECDSAPublicKey
- func (epubk *ECDSAPublicKey) Compare(f Fingerprint) (ok bool, err error)
- func (epubk *ECDSAPublicKey) ECDSA() *ec.PublicKey
- func (epubk *ECDSAPublicKey) Fingerprint() (fp Fingerprint)
- func (epubk *ECDSAPublicKey) MarshalBinary() (data []byte, err error)
- func (epubk *ECDSAPublicKey) UnmarshalBinary(data []byte) error
- func (epubk *ECDSAPublicKey) Verify(sig Signature, h hash.Hashable) (err error)
- type ECDSASignature
- type ErrBadSignature
- type ErrWrongFingerprintLen
- type Fingerprint
- func (fp Fingerprint) Bytes() []byte
- func (fp Fingerprint) IsZero() bool
- func (fp Fingerprint) MarshalNoms(vrw nomstypes.ValueReadWriter) (val nomstypes.Value, err error)
- func (_ Fingerprint) MarshalNomsType() (t *nomstypes.Type, err error)
- func (fp *Fingerprint) SetBytes(b []byte) error
- func (fp Fingerprint) String() string
- func (fp *Fingerprint) UnmarshalNoms(v nomstypes.Value) error
- func (fp Fingerprint) Zero()
- type PrivIsECDSA
- type PrivateKey
- type PubIsECDSA
- type PublicKey
- type Signature
Constants ¶
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 ¶
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
type ECDSAPublicKey ¶
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.
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 ¶
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 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 PubIsECDSA ¶
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