1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-02-07 08:45:23 -05:00

prototype of mtproto proxy

This commit is contained in:
Darien Raymond
2018-07-04 17:48:48 +02:00
parent 255090c5c0
commit 0d94d25688
11 changed files with 535 additions and 4 deletions

View File

@@ -10,15 +10,21 @@ import (
// 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)
}
func NewAesStreamMethod(key []byte, iv []byte, f func(cipher.Block, []byte) cipher.Stream) cipher.Stream {
aesBlock, err := aes.NewCipher(key)
common.Must(err)
return cipher.NewCFBDecrypter(aesBlock, iv)
return f(aesBlock, iv)
}
// 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 {
aesBlock, err := aes.NewCipher(key)
common.Must(err)
return cipher.NewCFBEncrypter(aesBlock, iv)
return NewAesStreamMethod(key, iv, cipher.NewCFBEncrypter)
}
func NewAesCTRStream(key []byte, iv []byte) cipher.Stream {
return NewAesStreamMethod(key, iv, cipher.NewCTR)
}