mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-13 14:44:15 +00:00
general purpose encryption streams
This commit is contained in:
1 parent
9371b3d080
commit
86944af2ff
4 files changed
+90
-24
No files matched your search
@@ -3,6 +3,7 @@ package vmess
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
mrand "math/rand"
|
||||
"testing"
|
||||
@@ -26,21 +27,22 @@ func TestNormalReading(t *testing.T) {
|
||||
keySize := 16
|
||||
key := make([]byte, keySize)
|
||||
randomBytes(key, t)
|
||||
iv := make([]byte, keySize)
|
||||
randomBytes(iv, t)
|
||||
|
||||
cipher, err := aes.NewCipher(key)
|
||||
aesBlock, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
aesMode := cipher.NewCBCEncrypter(aesBlock, iv)
|
||||
|
||||
ciphertext := make([]byte, testSize)
|
||||
for encryptSize := 0; encryptSize < testSize; encryptSize += blockSize {
|
||||
cipher.Encrypt(ciphertext[encryptSize:], plaintext[encryptSize:])
|
||||
}
|
||||
aesMode.CryptBlocks(ciphertext, plaintext)
|
||||
|
||||
ciphertextcopy := make([]byte, testSize)
|
||||
copy(ciphertextcopy, ciphertext)
|
||||
|
||||
reader, err := NewDecryptionReader(bytes.NewReader(ciphertextcopy), key)
|
||||
reader, err := NewDecryptionReader(bytes.NewReader(ciphertextcopy), key, iv)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user