ecdh

package module
v0.0.0-...-81d4d60 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

README

change log

2018-06-21

ECDH

Build Status

This is a go implementation of elliptical curve diffie-hellman key exchange method. It supports the NIST curves (and any curves using the elliptic.Curve go interface) as well as djb's curve25519.

The library handles generating of keys, generating a shared secret, and the (un)marshalling of the elliptical curve keys into slices of bytes.

Warning and Disclaimer

I am not a cryptographer, this was written as part of a personal project to learn about cryptographic systems and protocols. No claims as to the security of this library are made, I would not advise using it for anything that requires any level of security. Pull requests or issues about security flaws are however still welcome.

Compatibility

Works with go 1.2 onwards.

TODO

  • Improve documentation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ECDH

type ECDH interface {
	GenerateKey(io.Reader) (*EllipticPrivateKey, *EllipticPublicKey, error)
	Marshal(priKey *EllipticPublicKey) ([]byte, error)
	Unmarshal([]byte) (*EllipticPublicKey, error)
	// X509MarshalPublicKey(p crypto.PublicKey) ([]byte, error)
	// X509UnmarshalPublicKey(data []byte) (crypto.PublicKey, error)
	GenerateSharedSecret(*EllipticPrivateKey, *EllipticPublicKey) ([]byte, error)
}

The main interface for ECDH key exchange.

type EllipticECDH

type EllipticECDH struct {
	ECDH
	// contains filtered or unexported fields
}

func NewEllipticECDH

func NewEllipticECDH(curve elliptic.Curve) *EllipticECDH

NewEllipticECDH creates a new instance of ECDH with the given elliptic.Curve curve to use as the elliptical curve for elliptical curve diffie-hellman.

func (*EllipticECDH) GenerateKey

func (e *EllipticECDH) GenerateKey(rand io.Reader) (*EllipticPrivateKey, *EllipticPublicKey, error)

func (*EllipticECDH) GenerateSharedSecret

func (e *EllipticECDH) GenerateSharedSecret(priv *EllipticPrivateKey, pub *EllipticPublicKey) ([]byte, error)

GenerateSharedSecret takes in a public key and a private key and generates a shared secret.

RFC5903 Section 9 states we should only return x.

func (*EllipticECDH) Marshal

func (e *EllipticECDH) Marshal(pub *EllipticPublicKey) ([]byte, error)

func (*EllipticECDH) Unmarshal

func (e *EllipticECDH) Unmarshal(data []byte) (*EllipticPublicKey, error)

func (*EllipticECDH) X509MarshalPrivateKey

func (e *EllipticECDH) X509MarshalPrivateKey(priKey *EllipticPrivateKey) ([]byte, error)

func (*EllipticECDH) X509MarshalPublicKey

func (e *EllipticECDH) X509MarshalPublicKey(pub *EllipticPublicKey) ([]byte, error)

func (*EllipticECDH) X509UnmarshalPrivateKey

func (e *EllipticECDH) X509UnmarshalPrivateKey(pemBytes []byte) (*EllipticPrivateKey, error)

func (*EllipticECDH) X509UnmarshalPublicKey

func (e *EllipticECDH) X509UnmarshalPublicKey(data []byte) (*EllipticPublicKey, error)

type EllipticPrivateKey

type EllipticPrivateKey struct {
	EllipticPublicKey
	D *big.Int
}

type EllipticPublicKey

type EllipticPublicKey struct {
	elliptic.Curve
	X, Y *big.Int
}

Jump to

Keyboard shortcuts

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