p2p

package
v0.0.0-...-7f98e96 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: Apache-2.0 Imports: 8 Imported by: 9

Documentation

Overview

Package p2p implements functions for generating symmetric keys for peer to peer communication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKeys

func GenerateKeys() (*PublicKey, *SecretKey, error)

GenerateKeys randomly.

func Key

Key returns symmetric key for communication between the peers.

func Keys

func Keys(sk1 *SecretKey, pks []*PublicKey, pid uint16) ([]encrypt.SymmetricKey, error)

Keys return symmetric keys for communication between the peers.

func VerifySharedSecret

func VerifySharedSecret(pk1, pk2 *PublicKey, elem SharedSecret) bool

VerifySharedSecret checks whether the shared element comes from the given keys.

Types

type PublicKey

type PublicKey struct {
	// contains filtered or unexported fields
}

PublicKey is a public key used to generate p2p keys.

func DecodePublicKey

func DecodePublicKey(enc string) (*PublicKey, error)

DecodePublicKey decodes a verification key encoded as a base64 string.

func NewPublicKey

func NewPublicKey(secret *big.Int) *PublicKey

NewPublicKey returns a public key for the specified secret.

func (*PublicKey) Encode

func (pk *PublicKey) Encode() string

Encode encodes given PublicKey into a base64 string.

func (*PublicKey) Marshal

func (pk *PublicKey) Marshal() []byte

Marshal the public key.

func (*PublicKey) Unmarshal

func (pk *PublicKey) Unmarshal(data []byte) (*PublicKey, error)

Unmarshal the public key.

func (*PublicKey) Verify

func (pk *PublicKey) Verify() bool

Verify verifies if the public key is correct.

type SecretKey

type SecretKey struct {
	// contains filtered or unexported fields
}

SecretKey is a secret key used to generate p2p keys.

func DecodeSecretKey

func DecodeSecretKey(enc string) (*SecretKey, error)

DecodeSecretKey decodes a secret key encoded as a base64 string.

func NewSecretKey

func NewSecretKey(secret *big.Int) *SecretKey

NewSecretKey returns a secret key with the specified secret.

func (*SecretKey) Encode

func (sk *SecretKey) Encode() string

Encode encodes given SecretKey into a base64 string.

func (*SecretKey) Marshal

func (sk *SecretKey) Marshal() []byte

Marshal the secret key.

func (*SecretKey) PublicKey

func (sk *SecretKey) PublicKey() *PublicKey

PublicKey returns the public key associated with this secret key.

func (*SecretKey) Unmarshal

func (sk *SecretKey) Unmarshal(data []byte) (*SecretKey, error)

Unmarshal the secret key.

type SharedSecret

type SharedSecret struct {
	// contains filtered or unexported fields
}

SharedSecret is a secret shared between two peers. It should be revealed, when proving that the other party has sent non compliant messages.

func NewSharedSecret

func NewSharedSecret(sk1 *SecretKey, pk2 *PublicKey) SharedSecret

NewSharedSecret returns a secret to share with the other party.

func (*SharedSecret) Marshal

func (ss *SharedSecret) Marshal() []byte

Marshal the shared secret to bytes.

func (*SharedSecret) Unmarshal

func (ss *SharedSecret) Unmarshal(data []byte) (*SharedSecret, error)

Unmarshal the shared secret from bytes.

Jump to

Keyboard shortcuts

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