ecdh

package module
v0.0.0-...-da7f435 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 8 Imported by: 1

README

ecdh

Go Reference

ecdh is a simple implementation of Elliptic Curve Diffie-Hellman for Go.

Documentation

Index

Constants

View Source
const (
	// KeyLen is the length of a key generated by this package, be it
	// public or private.
	KeyLen = 32
)

Variables

View Source
var (
	ErrDataLen = errors.New("data length zero or not a multiple of the blocksize")
	ErrOutLen  = errors.New("out length is too small")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Rand is the random source to use. If it is nil,
	// crypto/rand.Reader is used.
	Rand io.Reader

	// Mode is the encryption mode to use for the symmetric encryption
	// step. If it is nil, AES is used.
	Mode Mode
}

Config handles configuration details for a variety of things.

func (Config) Decrypt

func (c Config) Decrypt(out, data []byte, priv PrivateKey, pub PublicKey) error

Decrypt decrypts data using a key generated via ECDH from the provided public and private Ed25519 keys.

If the length of data is zero or not a multiple of the symmetric encryption's blocksize, ErrDataLen is returned.

If the length of data is not at least c.DecryptedLen(len(data)), ErrOutLen is returned.

func (Config) DecryptedLen

func (c Config) DecryptedLen(data int) int

DecryptedLen returns the minimum number of bytes that are required to store data of the given length, including padding, after decryption.

func (Config) Encrypt

func (c Config) Encrypt(out, data []byte, priv PrivateKey, pub PublicKey) error

Encrypt encrypts data using a key generated via ECDH from the provided public and private Ed25519 keys.

If the length of data is not at least c.EncryptedLen(len(data)), ErrOutLen is returned.

func (Config) EncryptedLen

func (c Config) EncryptedLen(data int) int

EncryptedLen returns the minimum number of bytes that are required to store data of the given length after encryption.

func (Config) GenerateKey

func (c Config) GenerateKey() (priv PrivateKey, err error)

GenerateKey generates a new private key from the provided source of random bytes.

func (Config) PaddingLen

func (c Config) PaddingLen(data int) int

PaddingLen returns the number of bytes of padding that will be generated for data of the given length when encrypting.

type Mode

type Mode interface {
	// contains filtered or unexported methods
}

Mode represents the symmetric encryption scheme to be used.

func AES

func AES() Mode

type PrivateKey

type PrivateKey []byte

func (PrivateKey) PublicKey

func (priv PrivateKey) PublicKey() (PublicKey, error)

PublicKey calculates a public key from a given private key.

type PublicKey

type PublicKey []byte

Jump to

Keyboard shortcuts

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