ed25519

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ed25519 implements Tor/BitTorrent-like ed25519 keys.

See the following stack overflow post for details on why golang.org/x/crypto/ed25519 can't be used:

https://stackoverflow.com/questions/44810708/ed25519-public-result-is-different

Index

Constants

View Source
const (
	// PublicKeySize is the size, in bytes, of public keys as used in this package.
	PublicKeySize = 32
	// PrivateKeySize is the size, in bytes, of private keys as used in this package.
	PrivateKeySize = 64
	// SignatureSize is the size, in bytes, of signatures generated and verified by this package.
	SignatureSize = 64
)

Variables

This section is empty.

Functions

func Sign

func Sign(keyPair KeyPair, message []byte) []byte

Sign signs the message with the given key pair.

func Verify

func Verify(p PublicKey, message []byte, sig []byte) bool

Verify verifies a signed message.

Types

type KeyPair

type KeyPair interface {
	crypto.Signer
	PrivateKey() PrivateKey
	PublicKey() PublicKey
	Verify(message []byte, sig []byte) bool
}

KeyPair is an interface for types with both keys. While PrivateKey does implement this, it generates the PublicKey on demand. For better performance, use the result of GenerateKey directly or call PrivateKey.KeyPair().

func FromCryptoPrivateKey

func FromCryptoPrivateKey(key ed25519.PrivateKey) KeyPair

FromCryptoPrivateKey converts a Go private key to the one in this package.

func GenerateKey

func GenerateKey(rnd io.Reader) (KeyPair, error)

GenerateKey generates a public/private key pair using entropy from rand. If rand is nil, crypto/rand.Reader will be used.

type PrivateKey

type PrivateKey []byte

PrivateKey is a 64-byte Ed25519 private key. Unlike golang.org/x/crypto/ed25519, this is just the digest and does not contain the public key within it. Instead call PublicKey() or better, call KeyPair() which stores the precomputed public key.

func (PrivateKey) KeyPair

func (p PrivateKey) KeyPair() KeyPair

KeyPair returns a new key pair with the public key precomputed.

func (PrivateKey) PrivateKey

func (p PrivateKey) PrivateKey() PrivateKey

PrivateKey simply returns itself. Implements KeyPair.PrivateKey.

func (PrivateKey) Public

func (p PrivateKey) Public() crypto.PublicKey

Public simply delegates to PublicKey() to satisfy crypto.Signer. This method does a bit more work than the traditional Go ed25519's private key's Public() method so developers are encouraged to reuse the result or use KeyPair() which stores this value.

func (PrivateKey) PublicKey

func (p PrivateKey) PublicKey() PublicKey

PublicKey generates a public key for this private key. This method does a bit more work than the traditional Go ed25519's private key's Public() method so developers are encouraged to reuse the result or use KeyPair() which stores this value. Implements KeyPair.PublicKey.

func (PrivateKey) Sign

func (p PrivateKey) Sign(rand io.Reader, message []byte, opts crypto.SignerOpts) ([]byte, error)

Sign signs the given message with priv. Ed25519 performs two passes over messages to be signed and therefore cannot handle pre-hashed messages. Thus opts.HashFunc() must return zero to indicate the message hasn't been hashed. This can be achieved by passing crypto.Hash(0) as the value for opts.

func (PrivateKey) Verify

func (p PrivateKey) Verify(message []byte, sig []byte) bool

Verify simply calls PublicKey().Verify(). Callers are encouraged to instead store a precomputed KeyPair (via KeyPair() or GenerateKey()) and call Verify on that.

type PublicKey

type PublicKey []byte

PublicKey is a 32-byte Ed25519 public key.

func FromCryptoPublicKey

func FromCryptoPublicKey(key ed25519.PublicKey) PublicKey

FromCryptoPublicKey converts a Go public key to the one in this package.

func (PublicKey) Verify

func (p PublicKey) Verify(message []byte, sig []byte) bool

Verify simply calls the package-level function Verify().

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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