crypto

package
v0.2.34 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PacketByteLimit   = 1 << 25
	PacketCommandMask = 1 << 63
)
View Source
const NonceRotationNum = 1 << 20
View Source
const (
	SeqIDOutOfOrderThreshold = uint64(4096)
)

Variables

This section is empty.

Functions

func HandshakeAsServerCha0

func HandshakeAsServerCha0(remaining []byte, conn io.ReadWriter, authPrivateKey ed25519.PrivateKey, authFunc func(ed25519.PublicKey) bool) ([]byte, []byte, uint16, error)

Types

type Device

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

func NewDevice

func NewDevice(sharedKey []byte, fecDataShards, fecParityShards int) (*Device, error)

func (*Device) DecryptInline

func (d *Device) DecryptInline(buffer *bufferio.BufferArray, startOffset int, sigFunc SignalFunc) error

func (*Device) DecryptPacketsFromReader

func (d *Device) DecryptPacketsFromReader(reader IOReader, sigFunc SignalFunc, outputBuffer *bufferio.BufferArray) error

DecryptPacketsFromReader decrypts one packet from `reader`. Most of the time, `input` will be called once per packet, but might be multiple if FEC recovers some missing packets. Returns EOF if `reader` returns EOF. Returns unexpected EOF if reader returns EOF while reading a packet.

func (*Device) EncryptInline

func (d *Device) EncryptInline(inputBuffer *bufferio.BufferArray) error

func (*Device) GetRecvStats

func (device *Device) GetRecvStats(recv *RecvStats)

Returns receiver stats: raw packet missing, recovered by fec.

func (*Device) WriteSignal

func (d *Device) WriteSignal(signal uint32, ba *bufferio.BufferArray)

Write signal ecrypts a signal, this signal will not be recovered by FEC.

type DeviceConf

type DeviceConf struct {
	FecTotal, FecParity int
}

func HandshakeAsClientWithCha0

func HandshakeAsClientWithCha0(conn io.ReadWriter, authPrivateKey ed25519.PrivateKey, authFunc func(ed25519.PublicKey) bool, conf *DeviceConf) ([]byte, []byte, *DeviceConf, error)

func HandshakeAsClientWithCha1

func HandshakeAsClientWithCha1(conn io.ReadWriter, remotePub ed25519.PublicKey, authPrivateKey ed25519.PrivateKey, deviceConf *DeviceConf) ([]byte, []byte, *DeviceConf, error)

func HandshakeAsServer

func HandshakeAsServer(conn io.ReadWriter, authPrivateKey ed25519.PrivateKey, authFunc func(ed25519.PublicKey) bool, public bool) ([]byte, []byte, *DeviceConf, error)

func HandshakeAsServerCha1

func HandshakeAsServerCha1(remaining []byte, conn io.ReadWriter, authPrivateKey ed25519.PrivateKey, authFunc func(ed25519.PublicKey) bool) ([]byte, []byte, *DeviceConf, error)

type EncryptedCha1RequestHeader

type EncryptedCha1RequestHeader struct {
	X25519PubKey  []byte
	Ed25519PubKey []byte
	Nonce         []byte
	Conf          []byte

	Signature []byte
}

The following fields are encrypted by ed25519 pubkey.

type EncryptedCha1ResponseHeader

type EncryptedCha1ResponseHeader struct {
	X25519PubKey   []byte
	Nonce1, Nonce2 []byte

	Signature []byte
}

type IOFunc

type IOFunc func(data [][]byte) (int64, error)

IOFunc specifies a functor for an I/O operation. `Data` is invalid when it is out of invoke call.

type IOReader

type IOReader interface {
	io.Reader
	io.ByteReader
}

type RecvStats added in v0.2.29

type RecvStats struct {
	PacketTotal                      uint64
	PacketMissed, PacketFECRecovered uint64
}

type SignalFunc

type SignalFunc func(uint32)

SignalFunc will be invoked when device receives a signal.

Jump to

Keyboard shortcuts

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