From 90dc03c7626a410169ac03340ecdb9770ea766f9 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Sat, 1 Nov 2014 13:52:16 +0800 Subject: [PATCH] prefer ctypes over m2crypto in rc4-md5 --- shadowsocks/crypto/rc4_md5.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/shadowsocks/crypto/rc4_md5.py b/shadowsocks/crypto/rc4_md5.py index ee421b6..7b212d3 100644 --- a/shadowsocks/crypto/rc4_md5.py +++ b/shadowsocks/crypto/rc4_md5.py @@ -28,28 +28,22 @@ import hashlib __all__ = ['ciphers'] -m2_not_found = False - def create_cipher(alg, key, iv, op, key_as_bytes=0, d=None, salt=None, i=1, padding=1): - global m2_not_found - md5 = hashlib.md5() md5.update(key) md5.update(iv) rc4_key = md5.digest() - if not m2_not_found: - try: - import M2Crypto.EVP - return M2Crypto.EVP.Cipher(b'rc4', rc4_key, b'', op, - key_as_bytes=0, d='md5', salt=None, i=1, - padding=1) - except: - m2_not_found = True - from shadowsocks.crypto import ctypes_openssl - return ctypes_openssl.CtypesCrypto(b'rc4', rc4_key, b'', op) + try: + from shadowsocks.crypto import ctypes_openssl + return ctypes_openssl.CtypesCrypto(b'rc4', rc4_key, b'', op) + except: + import M2Crypto.EVP + return M2Crypto.EVP.Cipher(b'rc4', rc4_key, b'', op, + key_as_bytes=0, d='md5', salt=None, i=1, + padding=1) ciphers = {