dh

package
v1.0.1039 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeSecret

func ComputeSecret(private *PrivateKey, peersPublic *PublicKey) []byte

生成密钥

func GenerateKey

func GenerateKey(groupID GroupID, rand io.Reader) (*PrivateKey, *PublicKey, error)

生成证书

func GenerateKeyWithGroup added in v1.0.1025

func GenerateKeyWithGroup(param *Group, rand io.Reader) (*PrivateKey, *PublicKey, error)

生成证书

func IsSafePrimeParameters added in v1.0.1026

func IsSafePrimeParameters(param Parameters, n int) bool

判断是否为安全数据

func MarshalPrivateKey

func MarshalPrivateKey(key *PrivateKey) ([]byte, error)

包装私钥

func MarshalPublicKey

func MarshalPublicKey(key *PublicKey) ([]byte, error)

包装公钥

Types

type Group

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

	// The generator
	G *big.Int
}

分组数据

func GetMODGroup added in v1.0.1026

func GetMODGroup(groupID GroupID) (group *Group, err error)

Current minimum recommendation is 2048 bit with id=14.

type GroupID

type GroupID uint

分组 id

const (
	P1001 GroupID = 1 + iota
	P1002
	P1536
	P2048
	P3072
	P4096
	P6144
	P8192
)

type Parameters

type Parameters struct {
	// The prime
	P *big.Int

	// The generator
	G *big.Int
}

公用参数

type PrivateKey

type PrivateKey struct {
	PublicKey

	// 私钥
	X *big.Int
}

私钥

func ParsePrivateKey

func ParsePrivateKey(derBytes []byte) (*PrivateKey, error)

解析私钥

func (*PrivateKey) ComputeSecret added in v1.0.1025

func (this *PrivateKey) ComputeSecret(peersPublic *PublicKey) (secret []byte)

生成密钥

func (*PrivateKey) Public

func (this *PrivateKey) Public() crypto.PublicKey

type PublicKey

type PublicKey struct {
	Parameters

	// 公钥
	Y *big.Int
}

公钥

func GeneratePublicKey added in v1.0.1025

func GeneratePublicKey(private *PrivateKey) (*PublicKey, error)

从私钥获取公钥

func ParsePublicKey

func ParsePublicKey(derBytes []byte) (pub *PublicKey, err error)

解析公钥

func (*PublicKey) Check

func (this *PublicKey) Check() (err error)

检测 public key is < 0 or > g.P.

Jump to

Keyboard shortcuts

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