dhparam

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 8 Imported by: 10

README

Luzifer / go-dhparam

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

Documentation

Overview

Package dhparam is a pure Golang implementation of the openssl dhparam generator no requiring any CGO bindings

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

View Source
var ErrInvalidPem = errors.New("invalid bytes for PEM data; does not seem to be PEM-encoded")

ErrInvalidPem is returned if pemData for the Decode function does not seem to be PEM-encoded data.

View Source
var ErrNoPem = errors.New("empty or nil bytes for PEM data")

ErrNoPem is returned if pemData for the Decode function is nil or empty.

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 GenerateWithContext added in v1.1.0

func GenerateWithContext(ctx context.Context, bits int, generator Generator, cb GeneratorCallback) (*DH, error)

GenerateWithContext is just like the Generate function, but it accepts a ctx parameter with a context, that can be used to interrupt the generation if needed

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