From db2a4508abe46701dc106b4de0611f030b0daa4b Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Wed, 29 May 2013 09:56:36 +0800 Subject: [PATCH] Store cipherInfo pointer in cipherMethod map. --- shadowsocks/encrypt.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shadowsocks/encrypt.go b/shadowsocks/encrypt.go index 16261074..4294e38a 100644 --- a/shadowsocks/encrypt.go +++ b/shadowsocks/encrypt.go @@ -89,12 +89,6 @@ func newRC4Cipher(key []byte) (enc, dec cipher.Stream, err error) { return rc4Enc, &rc4Dec, nil } -type cipherInfo struct { - keyLen int - ivLen int - newBlock func([]byte) (cipher.Block, error) -} - // Ciphers from go.crypto has NewCipher returning specific type of cipher // instead of cipher.Block, so we need to have the following adapter // functions. @@ -109,7 +103,13 @@ func newCast5Cipher(key []byte) (cipher.Block, error) { return cast5.NewCipher(key) } -var cipherMethod = map[string]cipherInfo{ +type cipherInfo struct { + keyLen int + ivLen int + newBlock func([]byte) (cipher.Block, error) +} + +var cipherMethod = map[string]*cipherInfo{ "aes-128-cfb": {16, 16, aes.NewCipher}, "aes-192-cfb": {24, 16, aes.NewCipher}, "aes-256-cfb": {32, 16, aes.NewCipher}, @@ -149,7 +149,7 @@ func NewCipher(method, password string) (c *Cipher, err error) { key := evpBytesToKey(password, mi.keyLen) - c = &Cipher{key: key, info: &mi} + c = &Cipher{key: key, info: mi} if mi.newBlock == nil { if method == "" {