Browse Source

use hashlib PBKDF2 function

The MMGen Project 2 months ago
parent
commit
263824b997
2 changed files with 12 additions and 15 deletions
  1. 6 8
      mmgen/altcoin/util.py
  2. 6 7
      mmgen/bip39.py

+ 6 - 8
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}
 

+ 6 - 7
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)