Documentation ¶
Overview ¶
Package dh contains functions to perform a Diffie-Hellman key exchange over the group Z^*_p for a prime p.
Index ¶
- type Group
- func (g Group) Bytes(x *big.Int) []byte
- func (g Group) GeneratePrivateKey() (*big.Int, error)
- func (g Group) GeneratePublicKey(privKey *big.Int) *big.Int
- func (g Group) IsInGroup(x *big.Int) bool
- func (g Group) IsInSmallSubgroup(x *big.Int) bool
- func (g Group) SharedSecret(privKey *big.Int, otherPubKey *big.Int) []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
Group represents the group Z^*_p.
func (Group) Bytes ¶
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 ¶
GeneratePrivateKey generates a private key to be used in a Diffie-Hellman key exchange in the group g.
func (Group) GeneratePublicKey ¶
GeneratePublicKey creates a public key which corresponds to the private key privKey.
func (Group) IsInSmallSubgroup ¶
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 ¶
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.