fix python 3.*
This commit is contained in:
parent
efd45ddfc6
commit
0719e80fbd
2 changed files with 9 additions and 7 deletions
|
@ -68,7 +68,9 @@ def load_openssl():
|
||||||
|
|
||||||
|
|
||||||
def load_cipher(cipher_name):
|
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)
|
cipher = getattr(libcrypto, func_name, None)
|
||||||
if cipher:
|
if cipher:
|
||||||
cipher.restype = c_void_p
|
cipher.restype = c_void_p
|
||||||
|
@ -163,14 +165,14 @@ def test():
|
||||||
# decipher = M2Crypto.EVP.Cipher('aes_128_cfb', 'k' * 32, 'i' * 16, 0,
|
# decipher = M2Crypto.EVP.Cipher('aes_128_cfb', 'k' * 32, 'i' * 16, 0,
|
||||||
# key_as_bytes=0, d='md5', salt=None, i=1,
|
# key_as_bytes=0, d='md5', salt=None, i=1,
|
||||||
# padding=1)
|
# padding=1)
|
||||||
cipher = CtypesCrypto('aes-128-cfb', b'k' * 32, b'i' * 16, 1)
|
cipher = CtypesCrypto(b'aes-128-cfb', b'k' * 32, b'i' * 16, 1)
|
||||||
decipher = CtypesCrypto('aes-128-cfb', b'k' * 32, b'i' * 16, 0)
|
decipher = CtypesCrypto(b'aes-128-cfb', b'k' * 32, b'i' * 16, 0)
|
||||||
|
|
||||||
# cipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1)
|
# cipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1)
|
||||||
# decipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1)
|
# decipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1)
|
||||||
results = []
|
results = []
|
||||||
pos = 0
|
pos = 0
|
||||||
print('salsa20 test start')
|
print('openssl test start')
|
||||||
start = time.time()
|
start = time.time()
|
||||||
while pos < len(plain):
|
while pos < len(plain):
|
||||||
l = random.randint(100, 32768)
|
l = random.randint(100, 32768)
|
||||||
|
@ -178,7 +180,7 @@ def test():
|
||||||
results.append(c)
|
results.append(c)
|
||||||
pos += l
|
pos += l
|
||||||
pos = 0
|
pos = 0
|
||||||
c = ''.join(results)
|
c = b''.join(results)
|
||||||
results = []
|
results = []
|
||||||
while pos < len(plain):
|
while pos < len(plain):
|
||||||
l = random.randint(100, 32768)
|
l = random.randint(100, 32768)
|
||||||
|
@ -186,7 +188,7 @@ def test():
|
||||||
pos += l
|
pos += l
|
||||||
end = time.time()
|
end = time.time()
|
||||||
print('speed: %d bytes/s' % (BLOCK_SIZE * rounds / (end - start)))
|
print('speed: %d bytes/s' % (BLOCK_SIZE * rounds / (end - start)))
|
||||||
assert ''.join(results) == plain
|
assert b''.join(results) == plain
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -87,7 +87,7 @@ def check_config(config):
|
||||||
|
|
||||||
def get_config(is_local):
|
def get_config(is_local):
|
||||||
logging.basicConfig(level=logging.INFO,
|
logging.basicConfig(level=logging.INFO,
|
||||||
format='%(levelname)-s: %(message)s', filemode='a+')
|
format='%(levelname)-s: %(message)s')
|
||||||
if is_local:
|
if is_local:
|
||||||
shortopts = 'hs:b:p:k:l:m:c:t:vq'
|
shortopts = 'hs:b:p:k:l:m:c:t:vq'
|
||||||
longopts = ['fast-open']
|
longopts = ['fast-open']
|
||||||
|
|
Loading…
Reference in a new issue