curve

package
v0.0.0-...-5e8e628 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: AGPL-3.0 Imports: 5 Imported by: 5

Documentation

Overview

Package curve implements elliptic curve cryptography functions used for the protocol.

Index

Constants

View Source
const (
	PublicKeySize = curve25519.PublicKeySize
	SignatureSize = curve25519.SignatureSize
)
View Source
const PrivateKeySize = curve25519.PrivateKeySize

Variables

This section is empty.

Functions

This section is empty.

Types

type DJBPrivateKey

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

DJBPrivateKey represents an elliptic curve private key.

func (*DJBPrivateKey) Agreement

func (d *DJBPrivateKey) Agreement(key PublicKey) ([]byte, error)

func (*DJBPrivateKey) Bytes

func (d *DJBPrivateKey) Bytes() []byte

func (*DJBPrivateKey) PublicKey

func (d *DJBPrivateKey) PublicKey() PublicKey

func (*DJBPrivateKey) Sign

func (d *DJBPrivateKey) Sign(random io.Reader, messages ...[]byte) ([]byte, error)

type DJBPublicKey

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

DJBPublicKey represents an elliptic curve public key.

func (*DJBPublicKey) Bytes

func (d *DJBPublicKey) Bytes() []byte

func (*DJBPublicKey) Equal

func (d *DJBPublicKey) Equal(key PublicKey) bool

func (*DJBPublicKey) KeyBytes

func (d *DJBPublicKey) KeyBytes() []byte

func (*DJBPublicKey) VerifySignature

func (d *DJBPublicKey) VerifySignature(signature []byte, messages ...[]byte) (bool, error)

type KeyPair

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

KeyPair represents a related pair of public and private keys.

func GenerateKeyPair

func GenerateKeyPair(random io.Reader) (*KeyPair, error)

GenerateKeyPair returns a public/private key pair using the given reader.

It is recommended to use a cryptographic random reader. If random is nil, then crypto/rand.Reader is used.

func NewKeyPair

func NewKeyPair(privateKey, publicKey []byte) (*KeyPair, error)

NewKeyPair returns a public/private key pair from the given pair.

The given pair is expected to represent a valid curve.PrivateKey and curve.PublicKey, respectively.

func (*KeyPair) Agreement

func (k *KeyPair) Agreement(key PublicKey) ([]byte, error)

Agreement calculates and returns the shared secret between the key pair's private key and the given public key.

func (*KeyPair) PrivateKey

func (k *KeyPair) PrivateKey() PrivateKey

PrivateKey returns the pair's private key.

func (*KeyPair) PublicKey

func (k *KeyPair) PublicKey() PublicKey

PublicKey returns the pair's public key.

func (*KeyPair) Sign

func (k *KeyPair) Sign(random io.Reader, messages ...[]byte) ([]byte, error)

Sign calculates the digital signature of the messages using the key pair's private key.

It is recommended to use a cryptographic random reader. If random is nil, then crypto/rand.Reader is used.

type KeyType

type KeyType byte

KeyType represents a type of public or private key.

const (
	DJB KeyType = 0x05
)

type PrivateKey

type PrivateKey interface {
	// Bytes returns an encoding of the private key.
	Bytes() []byte
	// PublicKey returns the private key's related public key.
	PublicKey() PublicKey
	// Agreement calculates and returns the shared secret between the private key
	// and the given public key.
	Agreement(key PublicKey) ([]byte, error)
	// Sign calculates the digital signature of the messages.
	Sign(random io.Reader, messages ...[]byte) ([]byte, error)
}

PrivateKey represents an elliptic curve private key.

func GeneratePrivateKey

func GeneratePrivateKey(random io.Reader) (PrivateKey, error)

GeneratePrivateKey generates a private key using the given random reader.

It is recommended to use a cryptographic random reader. If random is nil, then crypto/rand.Reader is used.

func NewPrivateKey

func NewPrivateKey(key []byte) (PrivateKey, error)

NewPrivateKey returns a PrivateKey based on the given key.

type PublicKey

type PublicKey interface {

	// Bytes returns an encoding of the public key.
	Bytes() []byte
	// KeyBytes returns an encoding of the public key without the type prefix.
	KeyBytes() []byte
	// Equal reports whether the given public key is the same as this public key.
	//
	// This check is performed in constant time as long as the keys have the same type.
	Equal(key PublicKey) bool
	// VerifySignature verifies the signature is a valid signature
	// of the messages by the public key.
	VerifySignature(signature []byte, messages ...[]byte) (bool, error)
	// contains filtered or unexported methods
}

PublicKey represents an elliptic curve public key.

func NewPublicKey

func NewPublicKey(key []byte) (PublicKey, error)

NewPublicKey returns a PublicKey based on the given key.

The first byte of the given key is expected to identify the type of the key.

Directories

Path Synopsis
Package curve25519 implements the XEd25519 signature scheme.
Package curve25519 implements the XEd25519 signature scheme.

Jump to

Keyboard shortcuts

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