mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-12-17 12:44:36 +03:00
Some checks failed
Test / check-assets (push) Has been cancelled
Build and Release for Windows 7 / check-assets (push) Has been cancelled
Build and Release / check-assets (push) Has been cancelled
Build and Release / build (ppc64le, linux) (push) Has been cancelled
Build and Release / build (riscv64, linux) (push) Has been cancelled
Build and Release / build (s390x, linux) (push) Has been cancelled
Test / test (macos-latest) (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
Build and Release for Windows 7 / build (win7-32, 386, windows) (push) Has been cancelled
Build and Release for Windows 7 / build (win7-64, amd64, windows) (push) Has been cancelled
Build and Release / build (386, freebsd, ) (push) Has been cancelled
Build and Release / build (386, linux, ) (push) Has been cancelled
Build and Release / build (386, openbsd, ) (push) Has been cancelled
Build and Release / build (386, windows, ) (push) Has been cancelled
Build and Release / build (amd64, android, android-amd64) (push) Has been cancelled
Build and Release / build (amd64, darwin, ) (push) Has been cancelled
Build and Release / build (amd64, freebsd, ) (push) Has been cancelled
Build and Release / build (amd64, linux, ) (push) Has been cancelled
Build and Release / build (amd64, openbsd, ) (push) Has been cancelled
Build and Release / build (amd64, windows, ) (push) Has been cancelled
Build and Release / build (arm, 5, linux) (push) Has been cancelled
Build and Release / build (arm, 6, linux) (push) Has been cancelled
Build and Release / build (arm, 7, freebsd) (push) Has been cancelled
Build and Release / build (arm, 7, linux) (push) Has been cancelled
Build and Release / build (arm, 7, openbsd) (push) Has been cancelled
Build and Release / build (arm, 7, windows) (push) Has been cancelled
Build and Release / build (arm64, android) (push) Has been cancelled
Build and Release / build (arm64, darwin) (push) Has been cancelled
Build and Release / build (arm64, freebsd) (push) Has been cancelled
Build and Release / build (arm64, linux) (push) Has been cancelled
Build and Release / build (arm64, openbsd) (push) Has been cancelled
Build and Release / build (arm64, windows) (push) Has been cancelled
Build and Release / build (loong64, linux) (push) Has been cancelled
Build and Release / build (mips, linux) (push) Has been cancelled
Build and Release / build (mips64, linux) (push) Has been cancelled
Build and Release / build (mips64le, linux) (push) Has been cancelled
Build and Release / build (mipsle, linux) (push) Has been cancelled
Build and Release / build (ppc64, linux) (push) Has been cancelled
Test / test (windows-latest) (push) Has been cancelled
Scheduled assets update / geodat (push) Has been cancelled
* Refine must2 and apply NewAesGcm() to all usage * Remove unused package * Fix test
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package crypto
|
|
|
|
import (
|
|
"crypto/aes"
|
|
"crypto/cipher"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
)
|
|
|
|
// NewAesDecryptionStream creates a new AES encryption stream based on given key and IV.
|
|
// Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
|
|
func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream {
|
|
return NewAesStreamMethod(key, iv, cipher.NewCFBDecrypter)
|
|
}
|
|
|
|
// NewAesEncryptionStream creates a new AES description stream based on given key and IV.
|
|
// Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
|
|
func NewAesEncryptionStream(key []byte, iv []byte) cipher.Stream {
|
|
return NewAesStreamMethod(key, iv, cipher.NewCFBEncrypter)
|
|
}
|
|
|
|
func NewAesStreamMethod(key []byte, iv []byte, f func(cipher.Block, []byte) cipher.Stream) cipher.Stream {
|
|
aesBlock, err := aes.NewCipher(key)
|
|
common.Must(err)
|
|
return f(aesBlock, iv)
|
|
}
|
|
|
|
// NewAesCTRStream creates a stream cipher based on AES-CTR.
|
|
func NewAesCTRStream(key []byte, iv []byte) cipher.Stream {
|
|
return NewAesStreamMethod(key, iv, cipher.NewCTR)
|
|
}
|
|
|
|
// NewAesGcm creates a AEAD cipher based on AES-GCM.
|
|
func NewAesGcm(key []byte) cipher.AEAD {
|
|
block := common.Must2(aes.NewCipher(key))
|
|
aead := common.Must2(cipher.NewGCM(block))
|
|
return aead
|
|
}
|