Python 3 fixes config.py alfcrypto.py
This commit is contained in:
parent
019abecd05
commit
6dd022e6a0
|
@ -268,10 +268,10 @@ class KeyIVGen(object):
|
||||||
# [c_char_p, c_ulong, c_char_p, c_ulong, c_ulong, c_ulong, c_char_p])
|
# [c_char_p, c_ulong, c_char_p, c_ulong, c_ulong, c_ulong, c_char_p])
|
||||||
def pbkdf2(self, passwd, salt, iter, keylen):
|
def pbkdf2(self, passwd, salt, iter, keylen):
|
||||||
|
|
||||||
def xorstr( a, b ):
|
def xorbytes( a, b ):
|
||||||
if len(a) != len(b):
|
if len(a) != len(b):
|
||||||
raise Exception("xorstr(): lengths differ")
|
raise Exception("xorbytes(): lengths differ")
|
||||||
return ''.join((chr(ord(x)^ord(y)) for x, y in zip(a, b)))
|
return bytes([x ^ y for x, y in zip(a, b)])
|
||||||
|
|
||||||
def prf( h, data ):
|
def prf( h, data ):
|
||||||
hm = h.copy()
|
hm = h.copy()
|
||||||
|
@ -283,17 +283,17 @@ class KeyIVGen(object):
|
||||||
T = U
|
T = U
|
||||||
for i in range(2, itercount+1):
|
for i in range(2, itercount+1):
|
||||||
U = prf( h, U )
|
U = prf( h, U )
|
||||||
T = xorstr( T, U )
|
T = xorbytes( T, U )
|
||||||
return T
|
return T
|
||||||
|
|
||||||
sha = hashlib.sha1
|
sha = hashlib.sha1
|
||||||
digest_size = sha().digest_size
|
digest_size = sha().digest_size
|
||||||
# l - number of output blocks to produce
|
# l - number of output blocks to produce
|
||||||
l = int(keylen / digest_size)
|
l = keylen // digest_size
|
||||||
if keylen % digest_size != 0:
|
if keylen % digest_size != 0:
|
||||||
l += 1
|
l += 1
|
||||||
h = hmac.new( passwd, None, sha )
|
h = hmac.new( passwd, None, sha )
|
||||||
T = ""
|
T = b""
|
||||||
for i in range(1, l+1):
|
for i in range(1, l+1):
|
||||||
T += pbkdf2_F( h, salt, iter, i )
|
T += pbkdf2_F( h, salt, iter, i )
|
||||||
return T[0: keylen]
|
return T[0: keylen]
|
||||||
|
|
|
@ -431,7 +431,7 @@ class ManageKeysDialog(QDialog):
|
||||||
defaultname = "{0}.{1}".format(keyname, self.keyfile_ext)
|
defaultname = "{0}.{1}".format(keyname, self.keyfile_ext)
|
||||||
filename = choose_save_file(self, unique_dlg_name, caption, filters, all_files=False, initial_filename=defaultname)
|
filename = choose_save_file(self, unique_dlg_name, caption, filters, all_files=False, initial_filename=defaultname)
|
||||||
if filename:
|
if filename:
|
||||||
with file(filename, 'wb') as fname:
|
with open(filename, 'w') as fname:
|
||||||
if self.binary_file:
|
if self.binary_file:
|
||||||
fname.write(self.plugin_keys[keyname].decode('hex'))
|
fname.write(self.plugin_keys[keyname].decode('hex'))
|
||||||
elif self.json_file:
|
elif self.json_file:
|
||||||
|
|
Loading…
Reference in New Issue