ecdh

package
v0.0.0-...-917d9ad Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Curve25519

type Curve25519 struct {
	A uint8 // 247
	B uint8 // 127
	C uint8 // 64
	ECDH
}

func (*Curve25519) GenerateKey

func (e *Curve25519) GenerateKey(rand io.Reader) (crypto.PrivateKey, crypto.PublicKey, error)

GenerateKey 基于curve25519椭圆曲线算法生成秘钥对

func (*Curve25519) GenerateSharedSecret

func (e *Curve25519) GenerateSharedSecret(privKey crypto.PrivateKey, pubKey crypto.PublicKey) ([]byte, error)

GenerateSharedSecret 实现秘钥协商接口

func (*Curve25519) Marshal

func (e *Curve25519) Marshal(p crypto.PublicKey) []byte

Marshal 实现公钥的序列化

func (*Curve25519) Unmarshal

func (e *Curve25519) Unmarshal(data []byte) (crypto.PublicKey, bool)

Unmarshal实现公钥的反序列化

type ECDH

type ECDH interface {
	GenerateKey(io.Reader) (crypto.PrivateKey, crypto.PublicKey, error)
	Marshal(crypto.PublicKey) []byte
	Unmarshal([]byte) (crypto.PublicKey, bool)
	GenerateSharedSecret(crypto.PrivateKey, crypto.PublicKey) ([]byte, error)
}

ECDH 密钥交换算法接口

type Elliptic

type Elliptic struct {
	ECDH
	Curve elliptic.Curve
}

func (*Elliptic) GenerateKey

func (e *Elliptic) GenerateKey(rand io.Reader) (crypto.PrivateKey, crypto.PublicKey, error)

GenerateKey 基于标准库的NIST椭圆曲线算法生成秘钥对

func (*Elliptic) GenerateSharedSecret

func (e *Elliptic) GenerateSharedSecret(privKey crypto.PrivateKey, pubKey crypto.PublicKey) ([]byte, error)

GenerateSharedSecret 通过自己的私钥和对方的公钥协商一个共享密码

func (*Elliptic) Marshal

func (e *Elliptic) Marshal(p crypto.PublicKey) []byte

Marshal用于公钥的序列化

func (*Elliptic) Unmarshal

func (e *Elliptic) Unmarshal(data []byte) (crypto.PublicKey, bool)

Unmarshal用于公钥的反序列化

type EllipticPrivateKey

type EllipticPrivateKey struct {
	D []byte
}

type EllipticPublicKey

type EllipticPublicKey struct {
	elliptic.Curve
	X, Y *big.Int
}

Jump to

Keyboard shortcuts

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