dhparam

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

README

Go Report Card

Luzifer / go-dhparam

go-dhparam is a pure Golang implementation of the openssl dhparam generator no requiring any CGO bindings.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAllParametersOK = errors.New("DH parameters appear to be ok")

ErrAllParametersOK is defined to check whether the returned error from Check is indeed no error For simplicity reasons it is defined as an error instead of an additional result parameter

Functions

This section is empty.

Types

type DH

type DH struct {
	P *big.Int
	G int
}

DH contains a prime (P) and a generator (G) number representing the DH parameters

func Decode

func Decode(pemData []byte) (*DH, error)

Decode reads a DH parameters struct from its PEM data

func Generate

func Generate(bits int, generator Generator, cb GeneratorCallback) (*DH, error)

Generate determines a prime number according to the generator having the specified number of bits

In OpenSSL defined generators are 2 and 5. Others are supported but the verification is not supported in an extend as with generators 2 and 5. The bit size should be adjusted to be high enough for the current requirements. Also you should keep in mind the higher the bitsize, the longer the generation might take.

func (DH) Check

func (d DH) Check() ([]error, bool)

Check returns a number of errors and an "ok" bool. If the "ok" bool is set to true, still one error is returned: ErrAllParametersOK. If "ok" is false, the error list will contain at least one error not being equal to ErrAllParametersOK.

func (DH) ToPEM

func (d DH) ToPEM() ([]byte, error)

ToPEM encodes the DH parameters using ASN1 and PEM encoding

type Generator

type Generator int

Generator is the generator number to use when determining the prime number

const (
	// GeneratorTwo uses a generator 2
	GeneratorTwo Generator = 2
	// GeneratorFive uses a generator 5
	GeneratorFive = 5
)

type GeneratorCallback

type GeneratorCallback func(r GeneratorResult)

GeneratorCallback is a type of function to receive GeneratorResults while the prime number is determined

type GeneratorResult

type GeneratorResult uint

GeneratorResult is a type of results sent to the GeneratorCallback function

const (
	// GeneratorFoundPossiblePrime signals a possible (non-verified) prime number was found (OpenSSL: ".")
	GeneratorFoundPossiblePrime GeneratorResult = iota
	// GeneratorFirstConfirmation signals the prime number itself was verified but is not yet considered "safe" (OpenSSL: "+")
	GeneratorFirstConfirmation
	// GeneratorSafePrimeFound signals the prime number now is considered "safe" (OpenSSL: "*")
	GeneratorSafePrimeFound
)

Jump to

Keyboard shortcuts

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