From 1044358a6bf6b3f275d8ebce08bfaf325042b5b4 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Tue, 9 Sep 2014 16:17:33 +0800 Subject: [PATCH] use md5 instead of sha256; #178 --- .travis.yml | 2 +- shadowsocks/encrypt.py | 12 ++++++------ .../{encrypt_rc4_sha256.py => encrypt_rc4_md5.py} | 9 +++++---- tests/{rc4-sha256.json => rc4-md5.json} | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) rename shadowsocks/{encrypt_rc4_sha256.py => encrypt_rc4_md5.py} (92%) rename tests/{rc4-sha256.json => rc4-md5.json} (83%) diff --git a/.travis.yml b/.travis.yml index 24b234b..1d716f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/shadowsocks/encrypt.py b/shadowsocks/encrypt.py index 3537d00..d144e64 100644 --- a/shadowsocks/encrypt.py +++ b/shadowsocks/encrypt.py @@ -27,7 +27,7 @@ import string import struct import logging import encrypt_salsa20 -import encrypt_rc4_sha256 +import encrypt_rc4_md5 def random_string(length): @@ -116,7 +116,7 @@ method_supported = { '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), } @@ -160,8 +160,8 @@ class Encryptor(object): 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, @@ -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', diff --git a/shadowsocks/encrypt_rc4_sha256.py b/shadowsocks/encrypt_rc4_md5.py similarity index 92% rename from shadowsocks/encrypt_rc4_sha256.py rename to shadowsocks/encrypt_rc4_md5.py index 968f3e2..f71bad3 100644 --- a/shadowsocks/encrypt_rc4_sha256.py +++ b/shadowsocks/encrypt_rc4_md5.py @@ -25,10 +25,11 @@ import hashlib 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, diff --git a/tests/rc4-sha256.json b/tests/rc4-md5.json similarity index 83% rename from tests/rc4-sha256.json rename to tests/rc4-md5.json index 7119c09..26ba0df 100644 --- a/tests/rc4-sha256.json +++ b/tests/rc4-md5.json @@ -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 }