ed25519

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ed25519 provides an Ed25519 implementation backed by crypto/ed25519(https://pkg.go.dev/crypto/ed25519) std package, but using [ed25519consensus](https://pkg.go.dev/github.com/hdevalence/ed25519consensus) package for signature verification, which conforms to [ZIP 215](https://zips.z.cash/zip-0215) specification, making it suitable for consensus-critical contexts, see [README from ed25519consensus](https://github.com/hdevalence/ed25519consensus) for the explanation.

Index

Constants

View Source
const (
	KeyType = crpt.Ed25519
	// 32 bytes
	PublicKeySize = ved25519.PublicKeySize
	// 64 bytes
	PrivateKeySize = ved25519.PrivateKeySize
	// 64 bytes (The size of a compressed, Edwards25519 point, and a field element. Both of which are 32 bytes.)
	SignatureSize = ved25519.SignatureSize
	// 32 bytes private key seeds. (These are the private key representations used by RFC 8032.)
	SeedSize = 32
	// 64 bytes
	AddressSize = PublicKeySize
)

Variables

View Source
var (
	KeyTypeByte = byte(KeyType)

	ErrWrongPublicKeySize   = fmt.Errorf("%w, should be 32 bytes", crpt.ErrWrongPublicKeySize)
	ErrWrongPrivateKeySize  = fmt.Errorf("%w, should be 64 bytes", crpt.ErrWrongPrivateKeySize)
	ErrWrongSignatureSize   = fmt.Errorf("%w, should be 64 bytes", crpt.ErrWrongSignatureSize)
	ErrNotEd25519PublicKey  = errors.New("not a Ed25519 public key")
	ErrNotEd25519PrivateKey = errors.New("not a Ed25519 private key")
)

Functions

func New

func New(hash crypto.Hash) (*ed25519Crpt, error)

New creates an Ed225519 Crpt.

func NewBatchVerifier added in v0.5.0

func NewBatchVerifier() crpt.BatchVerifier

func SetEd25519Options added in v0.5.0

func SetEd25519Options(context string, addedRandomness bool, verify *ved25519.VerifyOptions)

SetEd25519Options sets the Ed25519 options used by this package.

See `github.com/oasisprotocol/curve25519-voi/primitives/ed25519.Options` for parameter details.

Types

type Address

type Address = crpt.Address

Ed25519 33-byte address (the same as TypedPublicKey)

type BatchVerifier added in v0.5.0

type BatchVerifier struct {
	*ved25519.BatchVerifier
}

BatchVerifier implements batch verification for ed25519.

func (*BatchVerifier) Add added in v0.5.0

func (b *BatchVerifier) Add(pub crpt.PublicKey, message []byte, sig crpt.Signature) error

func (*BatchVerifier) Verify added in v0.5.0

func (b *BatchVerifier) Verify(rand io.Reader) (bool, []bool)

type PrivateKey added in v0.5.0

type PrivateKey ved25519.PrivateKey

Ed25519 32-byte private key + 32-byte public key suffix = 64 bytes See: https://pkg.go.dev/crypto/ed25519

func (PrivateKey) Bytes added in v0.5.0

func (priv PrivateKey) Bytes() []byte

Bytes's returned byte slice is not safe to modify because it returns the underlying byte slice directly for the performance reason. Copy it if you need to modify.

func (PrivateKey) Equal added in v0.5.0

func (priv PrivateKey) Equal(o crpt.PrivateKey) bool

func (PrivateKey) KeyType added in v0.5.0

func (priv PrivateKey) KeyType() crpt.KeyType

func (PrivateKey) Public added in v0.5.0

func (priv PrivateKey) Public() crpt.PublicKey

Panics if the private key is not initialized.

func (PrivateKey) Sign added in v0.5.0

func (priv PrivateKey) Sign(message, digest []byte, hashFunc crypto.Hash, rand io.Reader,
) (crpt.Signature, error)

Sign produces a signature on the provided message. This assumes the privkey is wellformed in the golang format. The first 32 bytes should be random, corresponding to the normal ed25519 private key. The latter 32 bytes should be the compressed public key. If these conditions aren't met, Sign will return an error or produce an incorrect signature.

func (PrivateKey) SignDigest added in v0.5.0

func (priv PrivateKey) SignDigest(digest []byte, hashFunc crypto.Hash, rand io.Reader,
) (crpt.Signature, error)

func (PrivateKey) SignMessage added in v0.5.0

func (priv PrivateKey) SignMessage(message []byte, rand io.Reader) (crpt.Signature, error)

func (PrivateKey) TypedBytes added in v0.5.0

func (priv PrivateKey) TypedBytes() crpt.TypedPrivateKey

TypedBytes's returned byte slice is not safe to modify because it returns the underlying byte slice directly for the performance reason. Copy it if you need to modify.

type PublicKey added in v0.5.0

type PublicKey ved25519.PublicKey

Ed25519 32-byte public key

func (PublicKey) Address added in v0.5.0

func (pub PublicKey) Address() Address

Address returns TypedPublicKey instead of deriving address from the public key by hashing and returning the last certain bytes, to avoid adding extra space in transactions for public keys.

Address's returned byte slice is not safe to modify because it returns the underlying byte slice directly for the performance reason. Copy it if you need to modify.

func (PublicKey) Bytes added in v0.5.0

func (pub PublicKey) Bytes() []byte

Bytes's returned byte slice is not safe to modify because it returns the underlying byte slice directly for the performance reason. Copy it if you need to modify.

func (PublicKey) Equal added in v0.5.0

func (pub PublicKey) Equal(o crpt.PublicKey) bool

func (PublicKey) KeyType added in v0.5.0

func (pub PublicKey) KeyType() crpt.KeyType

func (PublicKey) TypedBytes added in v0.5.0

func (pub PublicKey) TypedBytes() crpt.TypedPublicKey

TypedBytes's returned byte slice is not safe to modify because it returns the underlying byte slice directly for the performance reason. Copy it if you need to modify.

func (PublicKey) Verify added in v0.5.0

func (pub PublicKey) Verify(message, digest []byte, hashFunc crypto.Hash, sig crpt.Signature,
) (bool, error)

func (PublicKey) VerifyDigest added in v0.5.0

func (pub PublicKey) VerifyDigest(digest []byte, hashFunc crypto.Hash, sig crpt.Signature,
) (ok bool, err error)

func (PublicKey) VerifyMessage added in v0.5.0

func (pub PublicKey) VerifyMessage(message []byte, sig crpt.Signature) (ok bool, err error)

Jump to

Keyboard shortcuts

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