ecdh25519

package module
v0.0.0-...-255683a Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2018 License: MIT Imports: 3 Imported by: 0

README

GoDoc

ecdh25519

A simple to use implementation of ECDH with curve25519 for Go. The core mathematics of this algorithm are already present in golang.org/x/crypto/curve25519, this library just implements the algorithm in such a way that knowledge of the underlying mathematics is not necessary.

Example

The below example does not include proper error handling.

package main

import (
    "github.com/luke-park/ecdh25519"
)

func main() {
    prv1, _ := ecdh25519.GenerateKey()
    prv2, _ := ecdh25519.GenerateKey()

    s1 := prv1.ComputeSecret(prv2.Public())
    s2 := prv2.ComputeSecret(prv1.Public())
    // bytes.Compare(s1, s2) == 0
}

Documentation

The full documentation of this package can be found on GoDoc.

Documentation

Overview

A simple to use implementation of ECDH with curve25519 for Go. The core mathematics of this algorithm are already present in golang.org/x/crypto/curve25519, this library just implements the algorithm in such a way that knowledge of the underlying mathematics is not necessary.

Index

Constants

View Source
const KeySize int = 32

KeySize is the length, in bytes, of both Private and Public keys.

Variables

View Source
var KeySizeError error = errors.New("The data provided was not 32 bytes in length.")

KeySizeError is returned if the provided key is not the correct length. It can only be returned from PrivateFromBytes and PublicFromBytes.

Functions

This section is empty.

Types

type PrivateKey

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

PrivateKey represents the private portion of a curve25519 ECDH key pair.

func GenerateKey

func GenerateKey() (*PrivateKey, error)

GenerateKey generates a new curve25519 private key. The public portion can be retrieved by calling Public().

func PrivateFromBytes

func PrivateFromBytes(raw []byte, precompute bool) (*PrivateKey, error)

PrivateFromBytes creates a PrivateKey from the given input byte slice. If precompute is true, the public key is stored in PrivateKey immediately without having to be computed.

func (*PrivateKey) ComputeSecret

func (prv *PrivateKey) ComputeSecret(pub *PublicKey) []byte

ComputeSecret computes the shared secret value for the calling private key when combined with the given public key.

func (*PrivateKey) Public

func (prv *PrivateKey) Public() *PublicKey

Public returns the public key corresponding to prv.

func (*PrivateKey) ToBytes

func (prv *PrivateKey) ToBytes() []byte

ToBytes marshals the given Private Key to a byte slice. It can be loaded back into a PrivateKey by using PrivateFromBytes.

type PublicKey

type PublicKey [KeySize]byte

PublicKey represents the public portion of a curve25519 ECHD key pair.

func PublicFromBytes

func PublicFromBytes(raw []byte) (*PublicKey, error)

PublicFromBytes creates a PublicKey from the given input byte slice.

func (*PublicKey) ToBytes

func (pub *PublicKey) ToBytes() []byte

ToBytes marhsals the given Public Key to a byte slice. It can be loaded back into a PublicKey by using PublicFromBytes.

Jump to

Keyboard shortcuts

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