dh

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2018 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package dh contains functions to perform a Diffie-Hellman key exchange over the group Z^*_p for a prime p.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	// Group generator.
	G *big.Int

	// Group order.
	P *big.Int
}

Group represents the group Z^*_p.

var Rfc3526_2048 Group

Rfc3526_2048 is the 2048-bit MODP Group from RFC 3526.

func (Group) Bytes

func (g Group) Bytes(x *big.Int) []byte

Bytes returns the absolute value of x as a big-endian byte slice. The length of the slice is padded with zeros so that the length of the returned slice is always the same for a given group.

func (Group) GeneratePrivateKey

func (g Group) GeneratePrivateKey() (*big.Int, error)

GeneratePrivateKey generates a private key to be used in a Diffie-Hellman key exchange in the group g.

func (Group) GeneratePublicKey

func (g Group) GeneratePublicKey(privKey *big.Int) *big.Int

GeneratePublicKey creates a public key which corresponds to the private key privKey.

func (Group) IsInGroup

func (g Group) IsInGroup(x *big.Int) bool

IsInGroup returns true if x is in the group Z^*_p and false otherwise.

func (Group) IsInSmallSubgroup

func (g Group) IsInSmallSubgroup(x *big.Int) bool

IsInSmallSubgroup returns true if x belongs to a small subgroup of Z^*_p.

Precondition: p is a safe prime (i.e., p is prime and (p-1)/2 is prime.).

As p is a safe prime there are only three sizes of subgroups: one, two, and, (p-1)/2 elements. The subgroups containing one and two elements are considered to be small.

func (Group) SharedSecret

func (g Group) SharedSecret(privKey *big.Int, otherPubKey *big.Int) []byte

SharedSecret returns a byte slice which is the secret shared between two peers who have performed a Diffie-Hellman key exchange.

If priv1 and priv2 are two private keys generated by GeneratePrivateKey and pub1 and pub2 are public keys created using GeneratePublicKey from priv1 and priv2, respectively, then the byte slices returned by SharedSecret(priv1, pub2) and SharedSecret(priv2, pub1) are identical.

Jump to

Keyboard shortcuts

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