crypto

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package crypto contains cryptographic utilities.

Package crypto contains cryptographic utilities.

Index

Constants

View Source
const DefaultPSKLength = 32

DefaultPSKLength is the default length of a PSK.

Variables

View Source
var ErrInvalidSignature = fmt.Errorf("invalid signature")

ErrInvalidSignature is returned when a signature is invalid.

View Source
var ValidPSKChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

ValidPSKChars is the set of valid characters for a PSK.

Functions

func IsValidDefaultPSK

func IsValidDefaultPSK(s string) bool

IsValidDefaultPSK returns true if the given string is a valid PSK.

func IsValidPSK

func IsValidPSK(s string, length int) bool

IsValidPSK returns true if the given string is a valid PSK.

func IsValidPSKBytes

func IsValidPSKBytes(b []byte, length int) bool

IsValidPSKBytes returns true if the given byte slice is a valid PSK.

func ParseHostPublicKey

func ParseHostPublicKey(s string) (p2pcrypto.PubKey, error)

ParseHostPublicKey parses the host public key from the given base64 encoded string.

func Rendezvous

func Rendezvous(keys ...wgtypes.Key) string

Rendezvous generates a rendezvous string for discovering the peers at the given public wireguard keys.

func Sign

func Sign(data []byte, psk PSK) ([]byte, error)

Sign signs the given data using the given PSK.

func Verify

func Verify(data, signature []byte, psk PSK) error

Verify verifies the given signature against the given data using the given PSK.

Types

type Key

type Key interface {
	// PrivateKey returns the WireGuard private key derived from the
	// given key.
	PrivateKey() wgtypes.Key
	// PublicKey returns the public WireGuard key derived from the given key.
	PublicKey() wgtypes.Key
	// HostKey returns a libp2p compatible host key-pair.
	HostKey() p2pcrypto.PrivKey
	// PublicHostString returns the base64 encoded string representation of the full host public key.
	PublicHostString() string
	// String return the base64 encoded string representation of the key.
	String() string
	// Rendezvous generates a rendezvous string for discovering the peers at the given
	// public wireguard keys.
	Rendezvous(keys ...wgtypes.Key) string
}

Key is a private key used for encryption and identity over libp2p and WireGuard tunnels.

func GenerateKey

func GenerateKey() (Key, error)

GenerateKey generates a new private key.

func MustGenerateKey

func MustGenerateKey() Key

MustGenerateKey generates a new private key or panics.

func ParseKey

func ParseKey(s string) (Key, error)

ParseKeyFromString parses the key from the given base64 encoded string.

func ParseKeyFromBytes

func ParseKeyFromBytes(data []byte) (Key, error)

ParseKey parses a private key from the given bytes.

type PSK

type PSK []byte

PSK is a pre-shared key.

func GeneratePSK

func GeneratePSK() (PSK, error)

GeneratePSK generates a PSK.

func GeneratePSKWithLength

func GeneratePSKWithLength(length int) (PSK, error)

GeneratePSKWithLength generates a PSK with a given length.

func MustGeneratePSK

func MustGeneratePSK() PSK

MustGeneratePSK generates a PSK and panics on error.

func (PSK) DeterministicSign

func (p PSK) DeterministicSign(data []byte) ([]byte, error)

DeterministicSign creates a signature of the given data using this PSK.

func (PSK) DeterministicSignatureSize

func (p PSK) DeterministicSignatureSize() int

func (PSK) DeterministicVerify

func (p PSK) DeterministicVerify(data, signature []byte) error

DeterministicVerify verifies the given signature against the given data using this PSK.

func (PSK) IsValid

func (p PSK) IsValid() bool

func (PSK) Sign

func (p PSK) Sign(data []byte) ([]byte, error)

Sign creates a signature of the given data using this PSK.

func (PSK) SignatureSize

func (p PSK) SignatureSize() int

func (PSK) String

func (p PSK) String() string

func (PSK) Verify

func (p PSK) Verify(data, signature []byte) error

Verify verifies the given signature against the given data using this PSK.

Jump to

Keyboard shortcuts

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