encryption

package
v1.19.34-clash.3 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: GPL-3.0 Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package encryption copy and modify from xray-core https://github.com/XTLS/Xray-core/commit/f61c14e9c63dc41a8a09135db3aea337974f3f37 https://github.com/XTLS/Xray-core/commit/3e19bf9233bdd9bafc073a71c65b737cc1ffba5e https://github.com/XTLS/Xray-core/commit/7ffb555fc8ec51bd1e3e60f26f1d6957984dba80 https://github.com/XTLS/Xray-core/commit/ec1cc35188c1a5f38a2ff75e88b5d043ffdc59da https://github.com/XTLS/Xray-core/commit/5c611420487a92f931faefc01d4bf03869f477f6 https://github.com/XTLS/Xray-core/commit/23d7aad461d232bc5bed52dd6aaa731ecd88ad35 https://github.com/XTLS/Xray-core/commit/3c20bddfcfd8999be5f9a2ac180dc959950e4c61 https://github.com/XTLS/Xray-core/commit/1720be168fa069332c418503d30341fc6e01df7f https://github.com/XTLS/Xray-core/commit/0fd7691d6b28e05922d7a5a9313d97745a51ea63 https://github.com/XTLS/Xray-core/commit/09cc92c61d9067e0d65c1cae9124664ecfc78f43 https://github.com/XTLS/Xray-core/commit/2807ee432a1fbeb301815647189eacd650b12a8b https://github.com/XTLS/Xray-core/commit/bfe4820f2f086daf639b1957eb23dc13c843cad1 https://github.com/XTLS/Xray-core/commit/d1fb48521271251a8c74bd64fcc2fc8700717a3b https://github.com/XTLS/Xray-core/commit/49580705f6029648399304b816a2737f991582a8 https://github.com/XTLS/Xray-core/commit/84835bec7d0d8555d0dd30953ed26a272de814c4 https://github.com/XTLS/Xray-core/commit/373558ed7abdbac3de41745cf30ec04c9adde604 https://github.com/XTLS/Xray-core/commit/38cc306c955c362f044e074049a5e67b6b9fb389 https://github.com/XTLS/Xray-core/commit/b33555cc0a52d0af3c23d2af8fca42f8a685d9af https://github.com/XTLS/Xray-core/commit/ad7140641c44239c9dcdc3d7215ea639b1f0841c https://github.com/XTLS/Xray-core/commit/0199dea39988a1a1b846d0bf8598631bade40902 https://github.com/XTLS/Xray-core/commit/fce1195b60f48ca18a953dbd5c7d991869de9a5e https://github.com/XTLS/Xray-core/commit/b0b220985c9c1bc832665458d5fd6e0c287b67ae https://github.com/XTLS/Xray-core/commit/82ea7a3cc5ff23280b87e3052f0f83b04f0267fa https://github.com/XTLS/Xray-core/commit/e8b02cd6649f14889841e8ab8ee6b2acca71dbe6 https://github.com/XTLS/Xray-core/commit/6768a22f676c9121cfc9dc4f51181a8a07837c8d https://github.com/XTLS/Xray-core/commit/4c6fd94d97159f5a3e740ba6dd2d9b65e3ed320c https://github.com/XTLS/Xray-core/commit/19f890729656bc923ae3dee8426168c93b8ee9c2 https://github.com/XTLS/Xray-core/commit/cbade89ab11af26ba1e480a3688a6c205fa3c3f8

Index

Constants

View Source
const MLKEM768ClientLength = mlkem.EncapsulationKeySize768
View Source
const MLKEM768SeedLength = mlkem.SeedSize
View Source
const X25519PasswordSize = 32
View Source
const X25519PrivateKeySize = 32

Variables

View Source
var ErrInvalidHeader = errors.New("invalid header")
View Source
var (
	HasAESGCMHardwareSupport = hasGCMAsmAMD64 || hasGCMAsmARM64 || hasGCMAsmS390X || hasGCMAsmPPC64
)
View Source
var MaxNonce = bytes.Repeat([]byte{255}, 12)

Functions

func CreatPadding

func CreatPadding(paddingLens, paddingGaps [][3]int) (length int, lens []int, gaps []time.Duration)

func DecodeHeader

func DecodeHeader(h []byte) (l int, err error)

func DecodeLength

func DecodeLength(b []byte) int

func EncodeHeader

func EncodeHeader(h []byte, l int)

func EncodeLength

func EncodeLength(l int) []byte

func GenMLKEM768

func GenMLKEM768(seedStr string) (seedBase64, clientBase64, hash32Base64 string, err error)

func GenX25519

func GenX25519(privateKeyStr string) (privateKeyBase64, passwordBase64, hash32Base64 string, err error)

func IncreaseNonce

func IncreaseNonce(nonce []byte) []byte

func NewCTR

func NewCTR(key, iv []byte) cipher.Stream

func ParsePadding

func ParsePadding(padding string, paddingLens, paddingGaps *[][3]int) (err error)

Types

type AEAD

type AEAD struct {
	cipher.AEAD
	Nonce [12]byte
}

func NewAEAD

func NewAEAD(ctx, key []byte, useAES bool) *AEAD

func (*AEAD) Open

func (a *AEAD) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error)

func (*AEAD) Seal

func (a *AEAD) Seal(dst, nonce, plaintext, additionalData []byte) []byte

type ClientInstance

type ClientInstance struct {
	NfsPKeys      []any
	NfsPKeysBytes [][]byte
	Hash32s       [][32]byte
	RelaysLength  int
	XorMode       uint32
	Seconds       uint32
	PaddingLens   [][3]int
	PaddingGaps   [][3]int

	RWLock sync.RWMutex
	Expire time.Time
	PfsKey []byte
	Ticket []byte
}

func NewClient

func NewClient(encryption string) (*ClientInstance, error)

NewClient new client from encryption string maybe return a nil *ClientInstance without any error, that means don't need to encrypt

func (*ClientInstance) Handshake

func (i *ClientInstance) Handshake(conn net.Conn) (*CommonConn, error)

func (*ClientInstance) Init

func (i *ClientInstance) Init(nfsPKeysBytes [][]byte, xorMode, seconds uint32, padding string) (err error)

type CommonConn

type CommonConn struct {
	net.Conn
	UseAES      bool
	Client      *ClientInstance
	UnitedKey   []byte
	PreWrite    []byte
	AEAD        *AEAD
	PeerAEAD    *AEAD
	PeerPadding []byte
	// contains filtered or unexported fields
}

func NewCommonConn

func NewCommonConn(conn net.Conn, useAES bool) *CommonConn

func (*CommonConn) Read

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

func (*CommonConn) Write

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

type ServerInstance

type ServerInstance struct {
	NfsSKeys      []any
	NfsPKeysBytes [][]byte
	Hash32s       [][32]byte
	RelaysLength  int
	XorMode       uint32
	SecondsFrom   int64
	SecondsTo     int64
	PaddingLens   [][3]int
	PaddingGaps   [][3]int

	RWLock   sync.RWMutex
	Closed   bool
	Lasts    map[int64][16]byte
	Tickets  [][16]byte
	Sessions map[[16]byte]*ServerSession
}

func NewServer

func NewServer(decryption string) (*ServerInstance, error)

NewServer new server from decryption string maybe return a nil *ServerInstance without any error, that means don't need to decrypt

func (*ServerInstance) Close

func (i *ServerInstance) Close() (err error)

func (*ServerInstance) Handshake

func (i *ServerInstance) Handshake(conn net.Conn, fallback *[]byte) (*CommonConn, error)

func (*ServerInstance) Init

func (i *ServerInstance) Init(nfsSKeysBytes [][]byte, xorMode uint32, secondsFrom, secondsTo int64, padding string) (err error)

type ServerSession

type ServerSession struct {
	PfsKey  []byte
	NfsKeys sync.Map
}

type XorConn

type XorConn struct {
	net.Conn
	CTR       cipher.Stream
	PeerCTR   cipher.Stream
	OutSkip   int
	OutHeader []byte
	InSkip    int
	InHeader  []byte
}

func NewXorConn

func NewXorConn(conn net.Conn, ctr, peerCTR cipher.Stream, outSkip, inSkip int) *XorConn

func (*XorConn) Read

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

func (*XorConn) Write

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

Jump to

Keyboard shortcuts

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