use md5 instead of sha256; #178

This commit is contained in:
clowwindy 2014-09-09 16:17:33 +08:00
parent 1fea9dca8d
commit 1044358a6b
4 changed files with 13 additions and 12 deletions

View File

@ -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

View File

@ -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',

View File

@ -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,

View File

@ -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
}