shadowsocks

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const TestCipher = "chacha20-ietf-poly1305"

TestCipher is a preferred cipher to use in testing.

Variables

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

ErrShortPacket is identical to shadowaead.ErrShortPacket

Functions

func DecryptOnce added in v1.3.1

func DecryptOnce(cipher *Cipher, salt []byte, plainText, cipherText []byte) ([]byte, error)

DecryptOnce will decrypt the cipherText using the cipher and salt, appending the output to plainText.

func MakeTestPayload added in v1.0.3

func MakeTestPayload(size int) []byte

MakeTestPayload returns a slice of `size` arbitrary bytes.

func MakeTestSecrets added in v1.1.1

func MakeTestSecrets(n int) []string

MakeTestSecrets returns a slice of `n` test passwords. Not secure!

func Pack added in v1.3.0

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

Pack encrypts a Shadowsocks-UDP packet and returns a slice containing the encrypted packet. dst must be big enough to hold the encrypted packet. If plaintext and dst overlap but are not aligned for in-place encryption, this function will panic.

func SupportedCipherNames added in v1.3.1

func SupportedCipherNames() []string

SupportedCipherNames lists the names of the AEAD ciphers that are supported.

func Unpack added in v1.3.0

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

Unpack decrypts a Shadowsocks-UDP packet and returns a slice containing the decrypted payload or an error. If dst is present, it is used to store the plaintext, and must have enough capacity. If dst is nil, decryption proceeds in-place. This function is needed because shadowaead.Unpack() embeds its own replay detection, which we do not always want, especially on memory-constrained clients.

Types

type ChunkReader added in v1.1.5

type ChunkReader interface {
	// ReadChunk reads the next chunk and returns its payload.  The caller must
	// complete its use of the returned buffer before the next call.
	// The buffer is nil iff there is an error.  io.EOF indicates a close.
	ReadChunk() ([]byte, error)
}

ChunkReader is similar to io.Reader, except that it controls its own buffer granularity.

type Cipher added in v1.3.1

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

Cipher encapsulates a Shadowsocks AEAD spec and a secret

func NewCipher added in v1.3.1

func NewCipher(cipherName string, secretText string) (*Cipher, error)

NewCipher creates a Cipher given a cipher name and a secret

func (*Cipher) NewAEAD added in v1.3.1

func (c *Cipher) NewAEAD(salt []byte) (cipher.AEAD, error)

NewAEAD creates the AEAD for this cipher

func (*Cipher) SaltSize added in v1.3.1

func (c *Cipher) SaltSize() int

SaltSize is the size of the salt for this Cipher

func (*Cipher) TagSize added in v1.3.1

func (c *Cipher) TagSize() int

TagSize is the size of the AEAD tag for this Cipher

type Reader added in v1.1.0

type Reader interface {
	io.Reader
	io.WriterTo
}

Reader is an io.Reader that also implements io.WriterTo to allow for piping the data without extra allocations and copies.

func NewShadowsocksReader

func NewShadowsocksReader(reader io.Reader, ssCipher *Cipher) Reader

NewShadowsocksReader creates a Reader that decrypts the given Reader using the shadowsocks protocol with the given shadowsocks cipher.

type SaltGenerator added in v1.2.0

type SaltGenerator interface {
	// Returns a new salt
	GetSalt(salt []byte) error
}

SaltGenerator generates unique salts to use in Shadowsocks connections.

var RandomSaltGenerator SaltGenerator = randomSaltGenerator{}

RandomSaltGenerator is a basic SaltGenerator.

type Writer added in v1.1.0

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

Writer is an io.Writer that also implements io.ReaderFrom to allow for piping the data without extra allocations and copies. The LazyWrite and Flush methods allow a header to be added but delayed until the first write, for concatenation. All methods except Flush must be called from a single thread.

func NewShadowsocksWriter

func NewShadowsocksWriter(writer io.Writer, ssCipher *Cipher) *Writer

NewShadowsocksWriter creates a Writer that encrypts the given Writer using the shadowsocks protocol with the given shadowsocks cipher.

func (*Writer) Flush added in v1.1.8

func (sw *Writer) Flush() error

Flush sends the pending data, if any. This method is thread-safe.

func (*Writer) LazyWrite added in v1.1.8

func (sw *Writer) LazyWrite(p []byte) (int, error)

LazyWrite queues p to be written, but doesn't send it until Flush() is called, a non-lazy write is made, or the buffer is filled.

func (*Writer) ReadFrom added in v1.2.0

func (sw *Writer) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements the io.ReaderFrom interface.

func (*Writer) SetSaltGenerator added in v1.2.0

func (sw *Writer) SetSaltGenerator(saltGenerator SaltGenerator)

SetSaltGenerator sets the salt generator to be used. Must be called before the first write.

func (*Writer) Write added in v1.2.0

func (sw *Writer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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