Skip to content

Commit

Permalink
Support blowfish, cast5 encryption.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed May 26, 2013
1 parent 005bddc commit 28b2a41
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion script/test.sh
Expand Up @@ -52,7 +52,7 @@ test_shadowsocks() {
if ! test_get $url "<html"; then
kill -SIGTERM $server_pid
kill -SIGTERM $local_pid
return 1
exit 1
fi
sleep 0.3
done
Expand All @@ -73,7 +73,9 @@ test_server_local_pair() {
test_shadowsocks baidu.com aes-128-cfb
test_shadowsocks baidu.com aes-192-cfb
test_shadowsocks baidu.com aes-256-cfb
test_shadowsocks baidu.com bf-cfb
test_shadowsocks baidu.com des-cfb
test_shadowsocks baidu.com cast5-cfb
}

SERVER="shadowsocks-server"
Expand Down
18 changes: 18 additions & 0 deletions shadowsocks/encrypt.go
Expand Up @@ -2,6 +2,8 @@ package shadowsocks

import (
"bytes"
"code.google.com/p/go.crypto/blowfish"
"code.google.com/p/go.crypto/cast5"
"crypto/aes"
"crypto/cipher"
"crypto/des"
Expand Down Expand Up @@ -93,10 +95,26 @@ type cipherInfo struct {
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.
// The specific cipher types makes it possible to use Copy to optimize cipher
// initialization, but do this AFTER evaluation.

func newBlowFishCipher(key []byte) (cipher.Block, error) {
return blowfish.NewCipher(key)
}

func newCast5Cipher(key []byte) (cipher.Block, error) {
return cast5.NewCipher(key)
}

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},
"bf-cfb": {16, 8, newBlowFishCipher},
"cast5-cfb": {16, 8, newCast5Cipher},
"des-cfb": {8, 8, des.NewCipher},
"rc4": {16, 0, nil},
"": {16, 0, nil}, // table encryption
Expand Down

0 comments on commit 28b2a41

Please sign in to comment.