use hashlib PBKDF2 function

This commit is contained in:
The MMGen Project 2025-09-26 10:40:17 +00:00
commit 263824b997
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 12 additions and 15 deletions

View file

@ -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}

View file

@ -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)