fix python 3.*

This commit is contained in:
clowwindy 2014-10-31 22:08:51 +08:00
parent efd45ddfc6
commit 0719e80fbd
2 changed files with 9 additions and 7 deletions

View file

@ -68,7 +68,9 @@ def load_openssl():
def load_cipher(cipher_name):
func_name = 'EVP_' + cipher_name.replace('-', '_')
func_name = b'EVP_' + cipher_name.replace(b'-', b'_')
if bytes != str:
func_name = str(func_name, 'utf-8')
cipher = getattr(libcrypto, func_name, None)
if cipher:
cipher.restype = c_void_p
@ -163,14 +165,14 @@ 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', b'k' * 32, b'i' * 16, 1)
decipher = CtypesCrypto('aes-128-cfb', b'k' * 32, b'i' * 16, 0)
cipher = CtypesCrypto(b'aes-128-cfb', b'k' * 32, b'i' * 16, 1)
decipher = CtypesCrypto(b'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)
results = []
pos = 0
print('salsa20 test start')
print('openssl test start')
start = time.time()
while pos < len(plain):
l = random.randint(100, 32768)
@ -178,7 +180,7 @@ def test():
results.append(c)
pos += l
pos = 0
c = ''.join(results)
c = b''.join(results)
results = []
while pos < len(plain):
l = random.randint(100, 32768)
@ -186,7 +188,7 @@ def test():
pos += l
end = time.time()
print('speed: %d bytes/s' % (BLOCK_SIZE * rounds / (end - start)))
assert ''.join(results) == plain
assert b''.join(results) == plain
if __name__ == '__main__':

View file

@ -87,7 +87,7 @@ def check_config(config):
def get_config(is_local):
logging.basicConfig(level=logging.INFO,
format='%(levelname)-s: %(message)s', filemode='a+')
format='%(levelname)-s: %(message)s')
if is_local:
shortopts = 'hs:b:p:k:l:m:c:t:vq'
longopts = ['fast-open']