From 1e9c30de48f5dc07b7f520b678981b7a0175da29 Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Thu, 6 Dec 2012 22:07:41 +0800 Subject: [PATCH] Add Encrypt2 function with given src and result buffer. --- src/shadowsocks/encrypt.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/shadowsocks/encrypt.go b/src/shadowsocks/encrypt.go index cd89b08..f56a971 100644 --- a/src/shadowsocks/encrypt.go +++ b/src/shadowsocks/encrypt.go @@ -1,10 +1,10 @@ package shadowsocks import ( + "bytes" "crypto/md5" - "io" "encoding/binary" - "bytes" + "io" ) func GetTable(key string) (encryptTable []byte, decryptTable []byte) { @@ -26,8 +26,8 @@ func GetTable(key string) (encryptTable []byte, decryptTable []byte) { } for i = 1; i < 1024; i++ { table = Sort(table, func(x, y uint64) int64 { - return int64(a%uint64(x + i) - a%uint64(y + i)) - }) + return int64(a%uint64(x+i) - a%uint64(y+i)) + }) } for i = 0; i < 256; i++ { encryptTable[i] = byte(table[i]) @@ -39,10 +39,14 @@ func GetTable(key string) (encryptTable []byte, decryptTable []byte) { return } -func Encrypt(table []byte, buf []byte) []byte { - var result = make([]byte, len(buf)) +func Encrypt2(table []byte, buf, result []byte) { for i := 0; i < len(buf); i++ { result[i] = table[buf[i]] } +} + +func Encrypt(table []byte, buf []byte) []byte { + var result = make([]byte, len(buf), len(buf)) + Encrypt2(table, buf, result) return result }