diff --git a/shadowsocks/crypto/ctypes_openssl.py b/shadowsocks/crypto/ctypes_openssl.py index 807c54f..7707639 100644 --- a/shadowsocks/crypto/ctypes_openssl.py +++ b/shadowsocks/crypto/ctypes_openssl.py @@ -163,8 +163,8 @@ def test(): # decipher = M2Crypto.EVP.Cipher('aes_128_cfb', 'k' * 32, 'i' * 16, 0, # key_as_bytes=0, d='md5', salt=None, i=1, # padding=1) - cipher = CtypesCrypto('aes-128-cfb', 'k' * 32, 'i' * 16, 1) - decipher = CtypesCrypto('aes-128-cfb', 'k' * 32, 'i' * 16, 0) + cipher = CtypesCrypto('aes-128-cfb', b'k' * 32, b'i' * 16, 1) + decipher = CtypesCrypto('aes-128-cfb', b'k' * 32, b'i' * 16, 0) # cipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1) # decipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1) diff --git a/shadowsocks/crypto/salsa20_ctr.py b/shadowsocks/crypto/salsa20_ctr.py index 0f5bfb8..e6c561c 100644 --- a/shadowsocks/crypto/salsa20_ctr.py +++ b/shadowsocks/crypto/salsa20_ctr.py @@ -72,9 +72,16 @@ def numpy_xor(a, b): def py_xor_str(a, b): c = [] - for i in range(0, len(a)): - c.append(chr(ord(a[i]) ^ ord(b[i]))) - return ''.join(c) + if bytes == str: + for i in range(0, len(a)): + c.append(chr(ord(a[i]) ^ ord(b[i]))) + else: + for i in range(0, len(a)): + c.append(a[i] ^ b[i]) + if bytes == str: + return ''.join(c) + else: + return bytes(c) class Salsa20Cipher(object): @@ -83,7 +90,7 @@ class Salsa20Cipher(object): def __init__(self, alg, key, iv, op, key_as_bytes=0, d=None, salt=None, i=1, padding=1): run_imports() - if alg != 'salsa20-ctr': + if alg != b'salsa20-ctr': raise Exception('unknown algorithm') self._key = key self._nonce = struct.unpack('