From 0040881b84263f583112282e3e58ace207a5c22c Mon Sep 17 00:00:00 2001 From: v2ray Date: Tue, 26 Jul 2016 21:21:22 +0200 Subject: [PATCH] comments --- common/crypto/aes.go | 4 ++++ common/crypto/chacha20.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/common/crypto/aes.go b/common/crypto/aes.go index cae00cb0..64967a33 100644 --- a/common/crypto/aes.go +++ b/common/crypto/aes.go @@ -5,11 +5,15 @@ import ( "crypto/cipher" ) +// 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 { aesBlock, _ := aes.NewCipher(key) return cipher.NewCFBDecrypter(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, _ := aes.NewCipher(key) return cipher.NewCFBEncrypter(aesBlock, iv) diff --git a/common/crypto/chacha20.go b/common/crypto/chacha20.go index 699a00fa..e9b4b0a6 100644 --- a/common/crypto/chacha20.go +++ b/common/crypto/chacha20.go @@ -6,6 +6,8 @@ import ( "github.com/v2ray/v2ray-core/common/crypto/internal" ) +// NewChaCha20Stream creates a new Chacha20 encryption/descryption stream based on give key and IV. +// Caller must ensure the length of key is 32 bytes, and length of IV is either 8 or 12 bytes. func NewChaCha20Stream(key []byte, iv []byte) cipher.Stream { return internal.NewChaCha20Stream(key, iv, 20) }