Skip to content

Commit

Permalink
use md5 instead of sha256; #178
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Sep 9, 2014
1 parent 1fea9dc commit 1044358
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ script:
- pep8 .
- python tests/test.py -c tests/table.json
- python tests/test.py -c tests/aes.json
- python tests/test.py -c tests/rc4-sha256.json
- python tests/test.py -c tests/rc4-md5.json
- python tests/test.py -c tests/salsa20.json
- python tests/test.py -c tests/server-multi-ports.json
- python tests/test.py -c tests/server-multi-passwd.json
Expand Down
12 changes: 6 additions & 6 deletions shadowsocks/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import struct
import logging
import encrypt_salsa20
import encrypt_rc4_sha256
import encrypt_rc4_md5


def random_string(length):
Expand Down Expand Up @@ -116,7 +116,7 @@ def EVP_BytesToKey(password, key_len, iv_len):
'idea-cfb': (16, 8),
'rc2-cfb': (16, 8),
'rc4': (16, 0),
'rc4-sha256': (32, 16),
'rc4-md5': (16, 16),
'seed-cfb': (16, 16),
'salsa20-ctr': (32, 8),
}
Expand Down Expand Up @@ -160,8 +160,8 @@ def get_cipher(self, password, method, op, iv=None):
self.cipher_iv = iv[:m[1]]
if method == 'salsa20-ctr':
return encrypt_salsa20.Salsa20Cipher(method, key, iv, op)
elif method == 'rc4-sha256':
return encrypt_rc4_sha256.create_cipher(method, key, iv, op)
elif method == 'rc4-md5':
return encrypt_rc4_md5.create_cipher(method, key, iv, op)
else:
import M2Crypto.EVP
return M2Crypto.EVP.Cipher(method.replace('-', '_'), key, iv,
Expand Down Expand Up @@ -223,8 +223,8 @@ def encrypt_all(password, method, op, data):
data = data[iv_len:]
if method == 'salsa20-ctr':
cipher = encrypt_salsa20.Salsa20Cipher(method, key, iv, op)
elif method == 'rc4-sha256':
cipher = encrypt_rc4_sha256.create_cipher(method, key, iv, op)
elif method == 'rc4-md5':
cipher = encrypt_rc4_md5.create_cipher(method, key, iv, op)
else:
cipher = M2Crypto.EVP.Cipher(method.replace('-', '_'), key, iv,
op, key_as_bytes=0, d='md5',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@

def create_cipher(alg, key, iv, op, key_as_bytes=0, d=None, salt=None,
i=1, padding=1):
sha256 = hashlib.sha256()
sha256.update(key)
sha256.update(iv)
rc4_key = sha256.digest()
md5 = hashlib.md5()
md5.update(key)
md5.update(iv)
rc4_key = md5.digest()
print len(rc4_key)

import M2Crypto.EVP
return M2Crypto.EVP.Cipher('rc4', rc4_key, '', op, key_as_bytes=0,
Expand Down
2 changes: 1 addition & 1 deletion tests/rc4-sha256.json → tests/rc4-md5.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"local_port":1081,
"password":"aes_password",
"timeout":60,
"method":"rc4-sha256",
"method":"rc4-md5",
"local_address":"127.0.0.1",
"fast_open":false
}

0 comments on commit 1044358

Please sign in to comment.