crypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SECP256K1RSigLen is the number of bytes in a secp2561k recoverable
	// signature
	SECP256K1RSigLen = 65

	// SECP256K1RSKLen is the number of bytes in a secp2561k recoverable private
	// key
	SECP256K1RSKLen = 32

	// SECP256K1RPKLen is the number of bytes in a secp2561k recoverable public
	// key
	SECP256K1RPKLen = 33
)

Variables

View Source
var EnableCrypto = true

EnableCrypto ... TODO: Remove this from this package, this should be in a config file

Functions

func IsSortedAndUniqueSECP2561RSigs

func IsSortedAndUniqueSECP2561RSigs(sigs [][SECP256K1RSigLen]byte) bool

IsSortedAndUniqueSECP2561RSigs returns true if [sigs] is sorted

func SortSECP2561RSigs

func SortSECP2561RSigs(lst [][SECP256K1RSigLen]byte)

SortSECP2561RSigs sorts a slice of SECP2561R signatures

Types

type Factory

type Factory interface {
	NewPrivateKey() (PrivateKey, error)

	ToPublicKey([]byte) (PublicKey, error)
	ToPrivateKey([]byte) (PrivateKey, error)
}

Factory ...

type FactoryED25519

type FactoryED25519 struct{}

FactoryED25519 ...

func (*FactoryED25519) NewPrivateKey

func (*FactoryED25519) NewPrivateKey() (PrivateKey, error)

NewPrivateKey implements the Factory interface

func (*FactoryED25519) ToPrivateKey

func (*FactoryED25519) ToPrivateKey(b []byte) (PrivateKey, error)

ToPrivateKey implements the Factory interface

func (*FactoryED25519) ToPublicKey

func (*FactoryED25519) ToPublicKey(b []byte) (PublicKey, error)

ToPublicKey implements the Factory interface

type FactoryRSA

type FactoryRSA struct{}

FactoryRSA ...

func (*FactoryRSA) NewPrivateKey

func (*FactoryRSA) NewPrivateKey() (PrivateKey, error)

NewPrivateKey implements the Factory interface

func (*FactoryRSA) ToPrivateKey

func (*FactoryRSA) ToPrivateKey(b []byte) (PrivateKey, error)

ToPrivateKey implements the Factory interface

func (*FactoryRSA) ToPublicKey

func (*FactoryRSA) ToPublicKey(b []byte) (PublicKey, error)

ToPublicKey implements the Factory interface

type FactoryRSAPSS

type FactoryRSAPSS struct{}

FactoryRSAPSS ...

func (*FactoryRSAPSS) NewPrivateKey

func (*FactoryRSAPSS) NewPrivateKey() (PrivateKey, error)

NewPrivateKey implements the Factory interface

func (*FactoryRSAPSS) ToPrivateKey

func (*FactoryRSAPSS) ToPrivateKey(b []byte) (PrivateKey, error)

ToPrivateKey implements the Factory interface

func (*FactoryRSAPSS) ToPublicKey

func (*FactoryRSAPSS) ToPublicKey(b []byte) (PublicKey, error)

ToPublicKey implements the Factory interface

type FactorySECP256K1R

type FactorySECP256K1R struct{ Cache cache.LRU }

FactorySECP256K1R ...

func (*FactorySECP256K1R) NewPrivateKey

func (*FactorySECP256K1R) NewPrivateKey() (PrivateKey, error)

NewPrivateKey implements the Factory interface

func (*FactorySECP256K1R) RecoverHashPublicKey

func (f *FactorySECP256K1R) RecoverHashPublicKey(hash, sig []byte) (PublicKey, error)

RecoverHashPublicKey returns the public key from a 65 byte signature

func (*FactorySECP256K1R) RecoverPublicKey

func (f *FactorySECP256K1R) RecoverPublicKey(msg, sig []byte) (PublicKey, error)

RecoverPublicKey returns the public key from a 65 byte signature

func (*FactorySECP256K1R) ToPrivateKey

func (*FactorySECP256K1R) ToPrivateKey(b []byte) (PrivateKey, error)

ToPrivateKey implements the Factory interface

func (*FactorySECP256K1R) ToPublicKey

func (*FactorySECP256K1R) ToPublicKey(b []byte) (PublicKey, error)

ToPublicKey implements the Factory interface

type PrivateKey

type PrivateKey interface {
	PublicKey() PublicKey

	Sign(message []byte) ([]byte, error)
	SignHash(hash []byte) ([]byte, error)

	Bytes() []byte
}

PrivateKey ...

type PrivateKeyED25519

type PrivateKeyED25519 struct {
	// contains filtered or unexported fields
}

PrivateKeyED25519 ...

func (PrivateKeyED25519) Bytes

func (k PrivateKeyED25519) Bytes() []byte

Bytes implements the PrivateKey interface

func (*PrivateKeyED25519) PublicKey

func (k *PrivateKeyED25519) PublicKey() PublicKey

PublicKey implements the PrivateKey interface

func (*PrivateKeyED25519) Sign

func (k *PrivateKeyED25519) Sign(msg []byte) ([]byte, error)

Sign implements the PrivateKey interface

func (PrivateKeyED25519) SignHash

func (k PrivateKeyED25519) SignHash(hash []byte) ([]byte, error)

SignHash implements the PrivateKey interface

type PrivateKeyRSA

type PrivateKeyRSA struct {
	// contains filtered or unexported fields
}

PrivateKeyRSA ...

func (*PrivateKeyRSA) Bytes

func (k *PrivateKeyRSA) Bytes() []byte

Bytes implements the PrivateKey interface

func (*PrivateKeyRSA) PublicKey

func (k *PrivateKeyRSA) PublicKey() PublicKey

PublicKey implements the PrivateKey interface

func (*PrivateKeyRSA) Sign

func (k *PrivateKeyRSA) Sign(msg []byte) ([]byte, error)

Sign implements the PrivateKey interface

func (*PrivateKeyRSA) SignHash

func (k *PrivateKeyRSA) SignHash(hash []byte) ([]byte, error)

SignHash implements the PrivateKey interface

type PrivateKeyRSAPSS

type PrivateKeyRSAPSS struct {
	// contains filtered or unexported fields
}

PrivateKeyRSAPSS ...

func (*PrivateKeyRSAPSS) Bytes

func (k *PrivateKeyRSAPSS) Bytes() []byte

Bytes implements the PrivateKey interface

func (*PrivateKeyRSAPSS) PublicKey

func (k *PrivateKeyRSAPSS) PublicKey() PublicKey

PublicKey implements the PrivateKey interface

func (*PrivateKeyRSAPSS) Sign

func (k *PrivateKeyRSAPSS) Sign(msg []byte) ([]byte, error)

Sign implements the PrivateKey interface

func (*PrivateKeyRSAPSS) SignHash

func (k *PrivateKeyRSAPSS) SignHash(hash []byte) ([]byte, error)

SignHash implements the PrivateKey interface

type PrivateKeySECP256K1R

type PrivateKeySECP256K1R struct {
	// contains filtered or unexported fields
}

PrivateKeySECP256K1R ...

func (*PrivateKeySECP256K1R) Bytes

func (k *PrivateKeySECP256K1R) Bytes() []byte

Bytes implements the PrivateKey interface

func (*PrivateKeySECP256K1R) PublicKey

func (k *PrivateKeySECP256K1R) PublicKey() PublicKey

PublicKey implements the PrivateKey interface

func (*PrivateKeySECP256K1R) Sign

func (k *PrivateKeySECP256K1R) Sign(msg []byte) ([]byte, error)

Sign implements the PrivateKey interface

func (*PrivateKeySECP256K1R) SignHash

func (k *PrivateKeySECP256K1R) SignHash(hash []byte) ([]byte, error)

SignHash implements the PrivateKey interface

type PublicKey

type PublicKey interface {
	Verify(message, signature []byte) bool
	VerifyHash(hash, signature []byte) bool

	Address() ids.ShortID
	Bytes() []byte
}

PublicKey ...

type PublicKeyED25519

type PublicKeyED25519 struct {
	// contains filtered or unexported fields
}

PublicKeyED25519 ...

func (*PublicKeyED25519) Address

func (k *PublicKeyED25519) Address() ids.ShortID

Address implements the PublicKey interface

func (*PublicKeyED25519) Bytes

func (k *PublicKeyED25519) Bytes() []byte

Bytes implements the PublicKey interface

func (*PublicKeyED25519) Verify

func (k *PublicKeyED25519) Verify(msg, sig []byte) bool

Verify implements the PublicKey interface

func (*PublicKeyED25519) VerifyHash

func (k *PublicKeyED25519) VerifyHash(hash, sig []byte) bool

VerifyHash implements the PublicKey interface

type PublicKeyRSA

type PublicKeyRSA struct {
	// contains filtered or unexported fields
}

PublicKeyRSA ...

func (*PublicKeyRSA) Address

func (k *PublicKeyRSA) Address() ids.ShortID

Address implements the PublicKey interface

func (*PublicKeyRSA) Bytes

func (k *PublicKeyRSA) Bytes() []byte

Bytes implements the PublicKey interface

func (*PublicKeyRSA) Verify

func (k *PublicKeyRSA) Verify(msg, sig []byte) bool

Verify implements the PublicKey interface

func (*PublicKeyRSA) VerifyHash

func (k *PublicKeyRSA) VerifyHash(hash, sig []byte) bool

VerifyHash implements the PublicKey interface

type PublicKeyRSAPSS

type PublicKeyRSAPSS struct {
	// contains filtered or unexported fields
}

PublicKeyRSAPSS ...

func (*PublicKeyRSAPSS) Address

func (k *PublicKeyRSAPSS) Address() ids.ShortID

Address implements the PublicKey interface

func (*PublicKeyRSAPSS) Bytes

func (k *PublicKeyRSAPSS) Bytes() []byte

Bytes implements the PublicKey interface

func (*PublicKeyRSAPSS) Verify

func (k *PublicKeyRSAPSS) Verify(msg, sig []byte) bool

Verify implements the PublicKey interface

func (*PublicKeyRSAPSS) VerifyHash

func (k *PublicKeyRSAPSS) VerifyHash(hash, sig []byte) bool

VerifyHash implements the PublicKey interface

type PublicKeySECP256K1R

type PublicKeySECP256K1R struct {
	// contains filtered or unexported fields
}

PublicKeySECP256K1R ...

func (*PublicKeySECP256K1R) Address

func (k *PublicKeySECP256K1R) Address() ids.ShortID

Address implements the PublicKey interface

func (*PublicKeySECP256K1R) Bytes

func (k *PublicKeySECP256K1R) Bytes() []byte

Bytes implements the PublicKey interface

func (*PublicKeySECP256K1R) Verify

func (k *PublicKeySECP256K1R) Verify(msg, sig []byte) bool

Verify implements the PublicKey interface

func (*PublicKeySECP256K1R) VerifyHash

func (k *PublicKeySECP256K1R) VerifyHash(hash, sig []byte) bool

VerifyHash implements the PublicKey interface

type RecoverableFactory

type RecoverableFactory interface {
	Factory

	RecoverPublicKey(message, signature []byte) (PublicKey, error)
	RecoverHashPublicKey(hash, signature []byte) (PublicKey, error)
}

RecoverableFactory ...

Jump to

Keyboard shortcuts

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