diff --git a/mmgen/altcoin/util.py b/mmgen/altcoin/util.py index 59909f6f..a0f71a3e 100755 --- a/mmgen/altcoin/util.py +++ b/mmgen/altcoin/util.py @@ -48,18 +48,16 @@ def decrypt_keystore(data, passwd, *, mac_algo=None, mac_params={}): elif kdf == 'pbkdf2': if (prf := parms.get('prf')) != 'hmac-sha256': die(1, f"unsupported hash function {prf!r} (must be 'hmac-sha256')") - from cryptography.hazmat.primitives import hashes - from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC - hashed_pw = PBKDF2HMAC( - algorithm = hashes.SHA256(), - length = parms['dklen'], + from hashlib import pbkdf2_hmac, blake2b + hashed_pw = pbkdf2_hmac( + hash_name = 'sha256', + password = passwd, salt = bytes.fromhex(parms['salt']), - iterations = parms['c'] - ).derive(passwd) + iterations = parms['c'], + dklen = parms['dklen']) # see: # https://github.com/xchainjs/xchainjs-lib.git # https://github.com/xchainjs/foundry-primitives-js.git - from hashlib import blake2b mac_algo = mac_algo or blake2b mac_params = mac_params or {'digest_size': 32} diff --git a/mmgen/bip39.py b/mmgen/bip39.py index db17fbb8..79432935 100755 --- a/mmgen/bip39.py +++ b/mmgen/bip39.py @@ -132,11 +132,10 @@ class bip39(baseconv): self.tohex(words_arg) # validate - from cryptography.hazmat.primitives import hashes - from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC - return PBKDF2HMAC( - algorithm = hashes.SHA512(), - length = 64, + from hashlib import pbkdf2_hmac + return pbkdf2_hmac( + hash_name = 'sha512', + password = ' '.join(words_arg).encode(), salt = b'mnemonic' + passwd.encode(), - iterations = 2048 - ).derive(' '.join(words_arg).encode()) + iterations = 2048, + dklen = 64)