ecdh

package
v0.0.0-...-796008b Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2016 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ecdh provides support for ECDH with the IETF CFRG Curves as specified in RFC 7748.

Index

Constants

View Source
const X25519Size = 32

X25519Size is the X25519 private/public key and shared secret size in bytes.

View Source
const X448Size = 56

X448Size is the X448 private/public key and shared secret size in bytes.

Variables

View Source
var (
	// ErrInvalidCurve is the error returned when the curve is unknown/invalid.
	ErrInvalidCurve = errors.New("ecdh: invalid curve")

	// ErrInvalidPoint is the error returned when when the point is of small
	// order, where the order divides the cofactor of the curve.
	ErrInvalidPoint = errors.New("ecdh: invalid point")

	// ErrInvalidKeySize is the error returned when deserialization fails due
	// to an invalid length buffer.
	ErrInvalidKeySize = errors.New("ecdh: invalid key size")

	// ErrNotSupported is the error returned when a operation is not supported.
	ErrNotSupported = errors.New("ecdh: not supported")
)

Functions

This section is empty.

Types

type Curve

type Curve byte

Curve is a curve identifier.

const (
	// X25519 is curve25519 from RFC 7748.
	X25519 Curve = iota

	// X448 is curve448 from RFC 7748.
	X448
)

type PrivateKey

type PrivateKey interface {
	// PublicKey returns the PublicKey corresponding to the PrivateKey.
	PublicKey() PublicKey

	// ScalarMult returns a shared secret given a peer's public key, suitable
	// for use as an input to a key derivation function.  An error is returned
	// iff the result does not ensre contribuatory behavior from both parties.
	ScalarMult(PublicKey) ([]byte, error)

	// Curve returns the Curve that this private key is for.
	Curve() Curve

	// Size returns the size of the encoded private key in bytes.
	Size() int

	// ToBytes returns a byte slice pointing to the interal byte encoded
	// private key.
	ToBytes() []byte

	// Reset sanitizes private values from the PrivateKey such that they no
	// longer appear in memory.
	Reset()
}

PrivateKey is an ECDH private key.

func New

func New(rand io.Reader, curve Curve, uniform bool) (PrivateKey, error)

New generates a new PrivateKey in the provided curve using the random source rand. If uniform is true, an Elligator2 representative will also be generated if supported.

func PrivateKeyFromBytes

func PrivateKeyFromBytes(curve Curve, b []byte) (PrivateKey, error)

PrivateKeyFromBytes returns the PrivateKey corresponding to the given curve and byte slice.

type PublicKey

type PublicKey interface {
	// Curve returns the Curve that this public key is for.
	Curve() Curve

	// Size returns the size of the encoded public key in bytes.
	Size() int

	// ToBytes returns a byte slice pointing to the internal byte encoded
	// public key.
	ToBytes() []byte

	// ToUniformBytes returns the Elligator2 uniform representative of the
	// public key, if one is available or nil if one is not.
	ToUniformBytes() []byte
}

PublicKey is an ECDH public key.

func PublicKeyFromBytes

func PublicKeyFromBytes(curve Curve, b []byte) (PublicKey, error)

PublicKeyFromBytes returns the PublicKey corresponding to the given curve and byte slice.

func PublicKeyFromUniformBytes

func PublicKeyFromUniformBytes(curve Curve, b []byte) (PublicKey, error)

PublicKeyFromUniformBytes returns the PublicKey corresponding to the given curve and Elligator2 uniform representative.

Jump to

Keyboard shortcuts

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