dh

package
v0.0.0-...-34d48bb Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2016 License: LGPL-3.0 Imports: 5 Imported by: 5

Documentation

Overview

Package dh implements the Diffie-Hellman key exchange over multiplicative groups of integers modulo a prime. This also defines some commen groups described in RFC 3526.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSafePrimeGroup

func IsSafePrimeGroup(g *Group, n int) bool

IsSafePrime returns true, if the prime of the group is a so called safe-prime. For a group with a safe-prime prime number the Decisional-Diffie-Hellman-Problem (DDH) is a 'hard' problem. The n argument is the number of iterations for the probabilistic prime test. It's recommend to use DDH-safe groups for DH-exchanges.

Types

type Group

type Group struct {
	P *big.Int // The prime
	G *big.Int // The generator
}

Group represents a mathematical group defined by a large prime and a generator.

func RFC3526_2048

func RFC3526_2048() *Group

RFC3526_2048 creates a new dh.Group consisting of the prime and the generator. The prime (and generator) are described in RFC 3526 (3.). The prime is a 2048 bit value.

func RFC3526_3072

func RFC3526_3072() *Group

RFC3526_3072 creates a new dh.Group consisting of the prime and the generator. The prime (and generator) are described in RFC 3526 (4.). The prime is a 3072 bit value.

func RFC3526_4096

func RFC3526_4096() *Group

RFC3526_4096 creates a new dh.Group consisting of the prime and the generator. The prime (and generator) are described in RFC 3526 (5.). The prime is a 4096 bit value.

func (*Group) Check

func (g *Group) Check(peersPublic PublicKey) (err error)

private returns a non-nil error if the given public key is not a possible element of the group. This means, that the public key is < 0 or > g.P.

func (*Group) ComputeSecret

func (g *Group) ComputeSecret(private PrivateKey, peersPublic PublicKey) (secret *big.Int)

ComputeSecret returns the secret computed from the own private and the peer's public key.

func (*Group) GenerateKey

func (g *Group) GenerateKey(rand io.Reader) (private PrivateKey, public PublicKey, err error)

GenerateKey generates a public/private key pair using entropy from rand. If rand is nil, crypto/rand.Reader will be used.

func (*Group) PublicKey

func (g *Group) PublicKey(private PrivateKey) (public PublicKey)

PublicKey returns the public key corresponding to the given private one.

type PrivateKey

type PrivateKey *big.Int

PrivateKey is the type of DH private keys.

type PublicKey

type PublicKey *big.Int

PublicKey is the type of DH public keys.

Directories

Path Synopsis
Package ecdh implements the Diffie-Hellman key exchange with elliptic curves.
Package ecdh implements the Diffie-Hellman key exchange with elliptic curves.

Jump to

Keyboard shortcuts

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