shadowstream

package
v0.0.0-...-e0e40e1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrShortPacket = errors.New("short packet")

ErrShortPacket means the packet is too short to be a valid encrypted packet.

Functions

func Pack

func Pack(dst, plaintext []byte, s Cipher) ([]byte, error)

Pack encrypts plaintext using stream cipher s and a random IV. Returns a slice of dst containing random IV and ciphertext. Ensure len(dst) >= s.IVSize() + len(plaintext).

func Unpack

func Unpack(dst, pkt []byte, s Cipher) ([]byte, error)

Unpack decrypts pkt using stream cipher s. Returns a slice of dst containing decrypted plaintext.

Types

type Cipher

type Cipher interface {
	IVSize() int
	Encrypter(iv []byte) cipher.Stream
	Decrypter(iv []byte) cipher.Stream
}

Cipher generates a pair of stream ciphers for encryption and decryption.

func AESCFB

func AESCFB(key []byte) (Cipher, error)

func AESCTR

func AESCTR(key []byte) (Cipher, error)

func Chacha20IETF

func Chacha20IETF(key []byte) (Cipher, error)

func RC4MD5

func RC4MD5(key []byte) (Cipher, error)

func Xchacha20

func Xchacha20(key []byte) (Cipher, error)

type Conn

type Conn struct {
	net.Conn
	Cipher
	// contains filtered or unexported fields
}

A Conn represents a Shadowsocks connection. It implements the net.Conn interface.

func NewConn

func NewConn(c net.Conn, ciph Cipher) *Conn

NewConn wraps a stream-oriented net.Conn with stream cipher encryption/decryption.

func (*Conn) ObtainReadIV

func (c *Conn) ObtainReadIV() ([]byte, error)

func (*Conn) ObtainWriteIV

func (c *Conn) ObtainWriteIV() ([]byte, error)

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

func (*Conn) ReadFrom

func (c *Conn) ReadFrom(r io.Reader) (int64, error)

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

func (*Conn) WriteTo

func (c *Conn) WriteTo(w io.Writer) (int64, error)

type KeySizeError

type KeySizeError int

func (KeySizeError) Error

func (e KeySizeError) Error() string

type PacketConn

type PacketConn struct {
	net.PacketConn
	Cipher
}

func NewPacketConn

func NewPacketConn(c net.PacketConn, ciph Cipher) *PacketConn

NewPacketConn wraps a net.PacketConn with stream cipher encryption/decryption.

func (*PacketConn) ReadFrom

func (c *PacketConn) ReadFrom(b []byte) (int, net.Addr, error)

func (*PacketConn) WriteTo

func (c *PacketConn) WriteTo(b []byte, addr net.Addr) (int, error)

type Reader

type Reader struct {
	io.Reader
	cipher.Stream
	// contains filtered or unexported fields
}

func NewReader

func NewReader(r io.Reader, s cipher.Stream) *Reader

NewReader wraps an io.Reader with stream cipher decryption.

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

func (*Reader) WriteTo

func (r *Reader) WriteTo(w io.Writer) (n int64, err error)

type Writer

type Writer struct {
	io.Writer
	cipher.Stream
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(w io.Writer, s cipher.Stream) *Writer

NewWriter wraps an io.Writer with stream cipher encryption.

func (*Writer) ReadFrom

func (w *Writer) ReadFrom(r io.Reader) (n int64, err error)

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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